gdb: fix vfork with multiple threads
[deliverable/binutils-gdb.git] / bfd / reloc.c
index e01cb5182ec2a1e4d3d5675662d791b85d0fa5fa..6d920e1df06937bdda90254be115d8af37086da0 100644 (file)
@@ -1,5 +1,5 @@
 /* BFD support for handling relocation entries.
-   Copyright (C) 1990-2019 Free Software Foundation, Inc.
+   Copyright (C) 1990-2021 Free Software Foundation, Inc.
    Written by Cygnus Support.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -51,6 +51,7 @@ SECTION
 #include "bfdlink.h"
 #include "libbfd.h"
 #include "bfdver.h"
+
 /*
 DOCDD
 INODE
@@ -383,8 +384,8 @@ DESCRIPTION
        This is used to fill in an empty howto entry in an array.
 
 .#define EMPTY_HOWTO(C) \
-.  HOWTO ((C), 0, 0, 0, FALSE, 0, complain_overflow_dont, NULL, \
-.        NULL, FALSE, 0, 0, FALSE)
+.  HOWTO ((C), 0, 0, 0, false, 0, complain_overflow_dont, NULL, \
+.        NULL, false, 0, 0, false)
 .
 */
 
@@ -432,8 +433,9 @@ DESCRIPTION
 .
 */
 
-/* N_ONES produces N one bits, without overflowing machine arithmetic.  */
-#define N_ONES(n) (((((bfd_vma) 1 << ((n) - 1)) - 1) << 1) | 1)
+/* N_ONES produces N one bits, without undefined behaviour for N
+   between zero and the number of bits in a bfd_vma.  */
+#define N_ONES(n) ((n) == 0 ? 0 : ((bfd_vma) 1 << ((n) - 1) << 1) - 1)
 
 /*
 FUNCTION
@@ -466,6 +468,9 @@ bfd_check_overflow (enum complain_overflow how,
   bfd_vma fieldmask, addrmask, signmask, ss, a;
   bfd_reloc_status_type flag = bfd_reloc_ok;
 
+  if (bitsize == 0)
+    return flag;
+
   /* Note: BITSIZE should always be <= ADDRSIZE, but in case it's not,
      we'll be permissive: extra bits in the field mask will
      automatically extend the address mask for purposes of the
@@ -515,7 +520,7 @@ FUNCTION
        bfd_reloc_offset_in_range
 
 SYNOPSIS
-       bfd_boolean bfd_reloc_offset_in_range
+       bool bfd_reloc_offset_in_range
          (reloc_howto_type *howto,
           bfd *abfd,
           asection *section,
@@ -530,7 +535,7 @@ DESCRIPTION
 /* HOWTO describes a relocation, at offset OCTET.  Return whether the
    relocation field is within SECTION of ABFD.  */
 
-bfd_boolean
+bool
 bfd_reloc_offset_in_range (reloc_howto_type *howto,
                           bfd *abfd,
                           asection *section,
@@ -744,14 +749,14 @@ bfd_perform_relocation (bfd *abfd,
   else
     output_base = reloc_target_output_section->vma;
 
-  /* For sections where relocations are in octets, output_base and
-     output_offset must also be converted to octets.  */
+  output_base += symbol->section->output_offset;
+
+  /* If symbol addresses are in octets, convert to bytes.  */
   if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
       && (symbol->section->flags & SEC_ELF_OCTETS))
-    relocation += ((output_base + symbol->section->output_offset)
-                  * bfd_octets_per_byte (abfd, NULL));
-  else
-    relocation += output_base + symbol->section->output_offset;
+    output_base *= bfd_octets_per_byte (abfd, input_section);
+
+  relocation += output_base;
 
   /* Add in supplied addend.  */
   relocation += reloc_entry->addend;
@@ -1080,14 +1085,14 @@ bfd_install_relocation (bfd *abfd,
   else
     output_base = reloc_target_output_section->vma;
 
-  /* For sections where relocations are in octets, output_base and
-     output_offset must also be converted to octets.  */
+  output_base += symbol->section->output_offset;
+
+  /* If symbol addresses are in octets, convert to bytes.  */
   if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
       && (symbol->section->flags & SEC_ELF_OCTETS))
-    relocation += ((output_base + symbol->section->output_offset)
-                  * bfd_octets_per_byte (abfd, NULL));
-  else
-    relocation += output_base + symbol->section->output_offset;
+    output_base *= bfd_octets_per_byte (abfd, input_section);
+
+  relocation += output_base;
 
   /* Add in supplied addend.  */
   relocation += reloc_entry->addend;
@@ -1383,10 +1388,7 @@ _bfd_final_link_relocate (reloc_howto_type *howto,
     }
 
   return _bfd_relocate_contents (howto, input_bfd, relocation,
-                                contents
-                                + address
-                                * bfd_octets_per_byte (input_bfd,
-                                                       input_section));
+                                contents + octets);
 }
 
 /* Relocate a given location using a given value and howto.  */
@@ -2734,6 +2736,10 @@ ENUMX
   BFD_RELOC_PPC_BA26
 ENUMX
   BFD_RELOC_PPC_TOC16
+ENUMX
+  BFD_RELOC_PPC_TOC16_LO
+ENUMX
+  BFD_RELOC_PPC_TOC16_HI
 ENUMX
   BFD_RELOC_PPC_B16
 ENUMX
@@ -2826,6 +2832,8 @@ ENUMX
   BFD_RELOC_PPC_16DX_HA
 ENUMX
   BFD_RELOC_PPC_REL16DX_HA
+ENUMX
+  BFD_RELOC_PPC_NEG
 ENUMX
   BFD_RELOC_PPC64_HIGHER
 ENUMX
@@ -2937,6 +2945,14 @@ ENUMX
   BFD_RELOC_PPC_TLSGD
 ENUMX
   BFD_RELOC_PPC_TLSLD
+ENUMX
+  BFD_RELOC_PPC_TLSLE
+ENUMX
+  BFD_RELOC_PPC_TLSIE
+ENUMX
+  BFD_RELOC_PPC_TLSM
+ENUMX
+  BFD_RELOC_PPC_TLSML
 ENUMX
   BFD_RELOC_PPC_DTPMOD
 ENUMX
@@ -2991,6 +3007,18 @@ ENUMX
   BFD_RELOC_PPC_GOT_DTPREL16_HI
 ENUMX
   BFD_RELOC_PPC_GOT_DTPREL16_HA
+ENUMX
+  BFD_RELOC_PPC64_TLSGD
+ENUMX
+  BFD_RELOC_PPC64_TLSLD
+ENUMX
+  BFD_RELOC_PPC64_TLSLE
+ENUMX
+  BFD_RELOC_PPC64_TLSIE
+ENUMX
+  BFD_RELOC_PPC64_TLSM
+ENUMX
+  BFD_RELOC_PPC64_TLSML
 ENUMX
   BFD_RELOC_PPC64_TPREL16_DS
 ENUMX
@@ -3028,13 +3056,13 @@ ENUMX
 ENUMX
   BFD_RELOC_PPC64_DTPREL34
 ENUMX
-  BFD_RELOC_PPC64_GOT_TLSGD34
+  BFD_RELOC_PPC64_GOT_TLSGD_PCREL34
 ENUMX
-  BFD_RELOC_PPC64_GOT_TLSLD34
+  BFD_RELOC_PPC64_GOT_TLSLD_PCREL34
 ENUMX
-  BFD_RELOC_PPC64_GOT_TPREL34
+  BFD_RELOC_PPC64_GOT_TPREL_PCREL34
 ENUMX
-  BFD_RELOC_PPC64_GOT_DTPREL34
+  BFD_RELOC_PPC64_GOT_DTPREL_PCREL34
 ENUMX
   BFD_RELOC_PPC64_TLS_PCREL
 ENUMDOC
@@ -6178,6 +6206,8 @@ ENUMX
   BFD_RELOC_OR1K_GOTPC_HI16
 ENUMX
   BFD_RELOC_OR1K_GOTPC_LO16
+ENUMX
+  BFD_RELOC_OR1K_GOT_AHI16
 ENUMX
   BFD_RELOC_OR1K_GOT16
 ENUMX
@@ -6366,6 +6396,11 @@ ENUMX
   BFD_RELOC_MSP430_PREL31
 ENUMX
   BFD_RELOC_MSP430_SYM_DIFF
+ENUMX
+  BFD_RELOC_MSP430_SET_ULEB128
+ENUMX
+  BFD_RELOC_MSP430_SUB_ULEB128
+
 ENUMDOC
   msp430 specific relocation codes
 
@@ -6559,6 +6594,8 @@ ENUMX
 ENUMX
   BFD_RELOC_XTENSA_DIFF32
 ENUMDOC
+  Xtensa relocations for backward compatibility.  These have been replaced
+  by BFD_RELOC_XTENSA_PDIFF and BFD_RELOC_XTENSA_NDIFF.
   Xtensa relocations to mark the difference of two local symbols.
   These are only needed to support linker relaxation and can be ignored
   when not relaxing.  The field is set to the value of the difference
@@ -6671,11 +6708,61 @@ ENUMX
   BFD_RELOC_XTENSA_TLS_CALL
 ENUMDOC
   Xtensa TLS relocations.
+ENUM
+  BFD_RELOC_XTENSA_PDIFF8
+ENUMX
+  BFD_RELOC_XTENSA_PDIFF16
+ENUMX
+  BFD_RELOC_XTENSA_PDIFF32
+ENUMX
+  BFD_RELOC_XTENSA_NDIFF8
+ENUMX
+  BFD_RELOC_XTENSA_NDIFF16
+ENUMX
+  BFD_RELOC_XTENSA_NDIFF32
+ENUMDOC
+  Xtensa relocations to mark the difference of two local symbols.
+  These are only needed to support linker relaxation and can be ignored
+  when not relaxing.  The field is set to the value of the difference
+  assuming no relaxation.  The relocation encodes the position of the
+  subtracted symbol so the linker can determine whether to adjust the field
+  value.  PDIFF relocations are used for positive differences, NDIFF
+  relocations are used for negative differences.  The difference value
+  is treated as unsigned with these relocation types, giving full
+  8/16 value ranges.
 
 ENUM
   BFD_RELOC_Z80_DISP8
 ENUMDOC
   8 bit signed offset in (ix+d) or (iy+d).
+ENUM
+  BFD_RELOC_Z80_BYTE0
+ENUMDOC
+  First 8 bits of multibyte (32, 24 or 16 bit) value.
+ENUM
+  BFD_RELOC_Z80_BYTE1
+ENUMDOC
+  Second 8 bits of multibyte (32, 24 or 16 bit) value.
+ENUM
+  BFD_RELOC_Z80_BYTE2
+ENUMDOC
+  Third 8 bits of multibyte (32 or 24 bit) value.
+ENUM
+  BFD_RELOC_Z80_BYTE3
+ENUMDOC
+  Fourth 8 bits of multibyte (32 bit) value.
+ENUM
+  BFD_RELOC_Z80_WORD0
+ENUMDOC
+  Lowest 16 bits of multibyte (32 or 24 bit) value.
+ENUM
+  BFD_RELOC_Z80_WORD1
+ENUMDOC
+  Highest 16 bits of multibyte (32 or 24 bit) value.
+ENUM
+  BFD_RELOC_Z80_16_BE
+ENUMDOC
+  Like BFD_RELOC_16 but big-endian.
 
 ENUM
   BFD_RELOC_Z8K_DISP7
@@ -8122,7 +8209,7 @@ bfd_reloc_name_lookup (bfd *abfd, const char *reloc_name)
 }
 
 static reloc_howto_type bfd_howto_32 =
-HOWTO (0, 00, 2, 32, FALSE, 0, complain_overflow_dont, 0, "VRT32", FALSE, 0xffffffff, 0xffffffff, TRUE);
+HOWTO (0, 00, 2, 32, false, 0, complain_overflow_dont, 0, "VRT32", false, 0xffffffff, 0xffffffff, true);
 
 /*
 INTERNAL_FUNCTION
@@ -8173,29 +8260,29 @@ INTERNAL_FUNCTION
        bfd_generic_relax_section
 
 SYNOPSIS
-       bfd_boolean bfd_generic_relax_section
+       bool bfd_generic_relax_section
          (bfd *abfd,
           asection *section,
           struct bfd_link_info *,
-          bfd_boolean *);
+          bool *);
 
 DESCRIPTION
        Provides default handling for relaxing for back ends which
        don't do relaxing.
 */
 
-bfd_boolean
+bool
 bfd_generic_relax_section (bfd *abfd ATTRIBUTE_UNUSED,
                           asection *section ATTRIBUTE_UNUSED,
                           struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
-                          bfd_boolean *again)
+                          bool *again)
 {
   if (bfd_link_relocatable (link_info))
     (*link_info->callbacks->einfo)
       (_("%P%F: --relax and -r may not be used together\n"));
 
-  *again = FALSE;
-  return TRUE;
+  *again = false;
+  return true;
 }
 
 /*
@@ -8203,7 +8290,7 @@ INTERNAL_FUNCTION
        bfd_generic_gc_sections
 
 SYNOPSIS
-       bfd_boolean bfd_generic_gc_sections
+       bool bfd_generic_gc_sections
          (bfd *, struct bfd_link_info *);
 
 DESCRIPTION
@@ -8211,11 +8298,11 @@ DESCRIPTION
        don't do section gc -- i.e., does nothing.
 */
 
-bfd_boolean
+bool
 bfd_generic_gc_sections (bfd *abfd ATTRIBUTE_UNUSED,
                         struct bfd_link_info *info ATTRIBUTE_UNUSED)
 {
-  return TRUE;
+  return true;
 }
 
 /*
@@ -8223,7 +8310,7 @@ INTERNAL_FUNCTION
        bfd_generic_lookup_section_flags
 
 SYNOPSIS
-       bfd_boolean bfd_generic_lookup_section_flags
+       bool bfd_generic_lookup_section_flags
          (struct bfd_link_info *, struct flag_info *, asection *);
 
 DESCRIPTION
@@ -8232,7 +8319,7 @@ DESCRIPTION
        Returns FALSE if the section should be omitted, otherwise TRUE.
 */
 
-bfd_boolean
+bool
 bfd_generic_lookup_section_flags (struct bfd_link_info *info ATTRIBUTE_UNUSED,
                                  struct flag_info *flaginfo,
                                  asection *section ATTRIBUTE_UNUSED)
@@ -8240,9 +8327,9 @@ bfd_generic_lookup_section_flags (struct bfd_link_info *info ATTRIBUTE_UNUSED,
   if (flaginfo != NULL)
     {
       _bfd_error_handler (_("INPUT_SECTION_FLAGS are not supported"));
-      return FALSE;
+      return false;
     }
-  return TRUE;
+  return true;
 }
 
 /*
@@ -8250,7 +8337,7 @@ INTERNAL_FUNCTION
        bfd_generic_merge_sections
 
 SYNOPSIS
-       bfd_boolean bfd_generic_merge_sections
+       bool bfd_generic_merge_sections
          (bfd *, struct bfd_link_info *);
 
 DESCRIPTION
@@ -8258,11 +8345,11 @@ DESCRIPTION
        which don't have SEC_MERGE support -- i.e., does nothing.
 */
 
-bfd_boolean
+bool
 bfd_generic_merge_sections (bfd *abfd ATTRIBUTE_UNUSED,
                            struct bfd_link_info *link_info ATTRIBUTE_UNUSED)
 {
-  return TRUE;
+  return true;
 }
 
 /*
@@ -8275,7 +8362,7 @@ SYNOPSIS
           struct bfd_link_info *link_info,
           struct bfd_link_order *link_order,
           bfd_byte *data,
-          bfd_boolean relocatable,
+          bool relocatable,
           asymbol **symbols);
 
 DESCRIPTION
@@ -8289,7 +8376,7 @@ bfd_generic_get_relocated_section_contents (bfd *abfd,
                                            struct bfd_link_info *link_info,
                                            struct bfd_link_order *link_order,
                                            bfd_byte *data,
-                                           bfd_boolean relocatable,
+                                           bool relocatable,
                                            asymbol **symbols)
 {
   bfd *input_bfd = link_order->u.indirect.section->owner;
@@ -8360,8 +8447,8 @@ bfd_generic_get_relocated_section_contents (bfd *abfd,
            {
              bfd_vma off;
              static reloc_howto_type none_howto
-               = HOWTO (0, 0, 0, 0, FALSE, 0, complain_overflow_dont, NULL,
-                        "unused", FALSE, 0, 0, FALSE);
+               = HOWTO (0, 0, 0, 0, false, 0, complain_overflow_dont, NULL,
+                        "unused", false, 0, 0, false);
 
              off = ((*parent)->address
                     * bfd_octets_per_byte (input_bfd, input_section));
@@ -8396,7 +8483,7 @@ bfd_generic_get_relocated_section_contents (bfd *abfd,
                case bfd_reloc_undefined:
                  (*link_info->callbacks->undefined_symbol)
                    (link_info, bfd_asymbol_name (*(*parent)->sym_ptr_ptr),
-                    input_bfd, input_section, (*parent)->address, TRUE);
+                    input_bfd, input_section, (*parent)->address, true);
                  break;
                case bfd_reloc_dangerous:
                  BFD_ASSERT (error_message != NULL);
@@ -8449,7 +8536,7 @@ bfd_generic_get_relocated_section_contents (bfd *abfd,
   free (reloc_vector);
   return data;
 
-error_return:
+ error_return:
   free (reloc_vector);
   return NULL;
 }
@@ -8484,7 +8571,7 @@ INTERNAL_FUNCTION
        _bfd_unrecognized_reloc
 
 SYNOPSIS
-       bfd_boolean _bfd_unrecognized_reloc
+       bool _bfd_unrecognized_reloc
          (bfd * abfd,
           sec_ptr section,
           unsigned int r_type);
@@ -8495,7 +8582,7 @@ DESCRIPTION
        Returns FALSE so that it can be called from a return statement.
 */
 
-bfd_boolean
+bool
 _bfd_unrecognized_reloc (bfd * abfd, sec_ptr section, unsigned int r_type)
 {
    /* xgettext:c-format */
@@ -8507,7 +8594,7 @@ _bfd_unrecognized_reloc (bfd * abfd, sec_ptr section, unsigned int r_type)
                      BFD_VERSION_STRING);
 
   bfd_set_error (bfd_error_bad_value);
-  return FALSE;
+  return false;
 }
 
 reloc_howto_type *
This page took 0.029732 seconds and 4 git commands to generate.