]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - bfd/reloc.c
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / bfd / reloc.c
index f5df8e2ab3eb4ff618fe5a92a3af60820d249869..46c996ffbea70e2048bb7c99a38070636cd3af70 100644 (file)
@@ -1,5 +1,5 @@
 /* BFD support for handling relocation entries.
-   Copyright (C) 1990-2020 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"
+#include "coff/internal.h"
 /*
 DOCDD
 INODE
@@ -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
@@ -900,6 +905,23 @@ space consuming.  For each target:
            }
        }
     }
+  else if (abfd->xvec->flavour == bfd_target_coff_flavour
+          && (input_section->output_section->owner->xvec->flavour
+              == bfd_target_elf_flavour)
+          && strcmp (abfd->xvec->name, "pe-x86-64") == 0
+          && strcmp (input_section->output_section->owner->xvec->name,
+                     "elf64-x86-64") == 0)
+    {
+      /* NB: bfd_perform_relocation isn't called to generate PE binary.
+        _bfd_relocate_contents is called instead.  When linking PE
+        object files to generate ELF output, _bfd_relocate_contents
+        isn't called and bfd_perform_relocation is used.  We need to
+        adjust relocation here.  */
+      relocation -= reloc_entry->addend;
+      if (howto->type >= R_AMD64_PCRLONG_1
+         && howto->type <= R_AMD64_PCRLONG_5)
+       relocation -= (bfd_vma)(howto->type - R_AMD64_PCRLONG);
+    }
 
   /* FIXME: This overflow checking is incomplete, because the value
      might have overflowed before we get here.  For a correct check we
@@ -3025,13 +3047,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
@@ -6363,6 +6385,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