Force the AArch64 linker backend to refuse to link when it encounters unresoleable...
authorNick Clifton <nickc@redhat.com>
Thu, 12 Oct 2017 12:38:20 +0000 (13:38 +0100)
committerNick Clifton <nickc@redhat.com>
Thu, 12 Oct 2017 12:38:20 +0000 (13:38 +0100)
* reloc.c (enum bfd_reloc_status): Start values at 2.
* bfd-in2.h: Regenerate.
* elfnn-aarch64.c (aarch64_relocate): Invert sense of function, so
that a TRUE return indicates success.  Compare the result of
calling _bfd_aarch64_elf_put_addend against bfd_reloc_ok.
(build_one_stub): Change sense of tests against aarch64_relocate
return value.
(elfNN_aarch64_tls_relax): Return bfd_reloc_notsupported, rather
than FALSE, when an error is detected.
(elfNN_aarch64_final_link_relocate): Likewise.

* testsuite/ld-aarch64/pcrel_pic_defined.d: Expect errors not
warnings.  Expect errors about unsupported relocations.
* testsuite/ld-aarch64/pcrel_pic_undefined.d: Likewise.

bfd/ChangeLog
bfd/bfd-in2.h
bfd/elfnn-aarch64.c
bfd/reloc.c
ld/ChangeLog
ld/testsuite/ld-aarch64/pcrel_pic_defined.d
ld/testsuite/ld-aarch64/pcrel_pic_undefined.d

index 5651316d681884f5a4819fc058c9c4d5f7a9011e..a62f7f653facf67175194cbecb572c9d584c961f 100644 (file)
@@ -1,3 +1,16 @@
+2017-10-12  Nick Clifton  <nickc@redhat.com>
+
+       * reloc.c (enum bfd_reloc_status): Start values at 2.
+       * bfd-in2.h: Regenerate.
+       * elfnn-aarch64.c (aarch64_relocate): Invert sense of function, so
+       that a TRUE return indicates success.  Compare the result of
+       calling _bfd_aarch64_elf_put_addend against bfd_reloc_ok.
+       (build_one_stub): Change sense of tests against aarch64_relocate
+       return value.
+       (elfNN_aarch64_tls_relax): Return bfd_reloc_notsupported, rather
+       than FALSE, when an error is detected.
+       (elfNN_aarch64_final_link_relocate): Likewise.
+
 2017-10-12  H.J. Lu  <hongjiu.lu@intel.com>
 
        * elf32-i386.c (elf_backend_hide_symbol): New.
index 4ba05b10b6e82c8e38768273e8c1502a8819a1ec..8265efa32ec4b836f0391a9b2ed699fbc125c2bc 100644 (file)
@@ -2466,8 +2466,9 @@ unsigned int bfd_arch_mach_octets_per_byte
 
 typedef enum bfd_reloc_status
 {
-  /* No errors detected.  */
-  bfd_reloc_ok,
+  /* No errors detected.  Note - the value 2 is used so that it
+     will not be mistaken for the boolean TRUE or FALSE values.  */
+  bfd_reloc_ok = 2,
 
   /* The relocation was performed, but there was an overflow.  */
   bfd_reloc_overflow,
index 92970561eedb5d1abd8a19f1eb2eb411bad132b8..5fd314dee2a0b70721cf0b589bdb7782e0b56462 100644 (file)
@@ -2610,6 +2610,8 @@ elfNN_aarch64_link_hash_table_create (bfd *abfd)
   return &ret->root.root;
 }
 
+/* Perform relocation R_TYPE.  Returns TRUE upon success, FALSE otherwise.  */
+
 static bfd_boolean
 aarch64_relocate (unsigned int r_type, bfd *input_bfd, asection *input_section,
                  bfd_vma offset, bfd_vma value)
@@ -2625,7 +2627,7 @@ aarch64_relocate (unsigned int r_type, bfd *input_bfd, asection *input_section,
   value = _bfd_aarch64_elf_resolve_relocation (r_type, place, value, 0, FALSE);
   return _bfd_aarch64_elf_put_addend (input_bfd,
                                      input_section->contents + offset, r_type,
-                                     howto, value);
+                                     howto, value) == bfd_reloc_ok;
 }
 
 static enum elf_aarch64_stub_type
@@ -2965,22 +2967,22 @@ aarch64_build_one_stub (struct bfd_hash_entry *gen_entry,
   switch (stub_entry->stub_type)
     {
     case aarch64_stub_adrp_branch:
-      if (aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21), stub_bfd, stub_sec,
-                           stub_entry->stub_offset, sym_value))
+      if (!aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21), stub_bfd, stub_sec,
+                            stub_entry->stub_offset, sym_value))
        /* The stub would not have been relaxed if the offset was out
           of range.  */
        BFD_FAIL ();
 
-      if (aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC), stub_bfd, stub_sec,
-                           stub_entry->stub_offset + 4, sym_value))
+      if (!aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC), stub_bfd, stub_sec,
+                            stub_entry->stub_offset + 4, sym_value))
        BFD_FAIL ();
       break;
 
     case aarch64_stub_long_branch:
       /* We want the value relative to the address 12 bytes back from the
          value itself.  */
-      if (aarch64_relocate (AARCH64_R (PRELNN), stub_bfd, stub_sec,
-                           stub_entry->stub_offset + 16, sym_value + 12))
+      if (!aarch64_relocate (AARCH64_R (PRELNN), stub_bfd, stub_sec,
+                            stub_entry->stub_offset + 16, sym_value + 12))
        BFD_FAIL ();
       break;
 
@@ -3001,8 +3003,8 @@ aarch64_build_one_stub (struct bfd_hash_entry *gen_entry,
       break;
 
     case aarch64_stub_erratum_843419_veneer:
-      if (aarch64_relocate (AARCH64_R (JUMP26), stub_bfd, stub_sec,
-                           stub_entry->stub_offset + 4, sym_value + 4))
+      if (!aarch64_relocate (AARCH64_R (JUMP26), stub_bfd, stub_sec,
+                            stub_entry->stub_offset + 4, sym_value + 4))
        BFD_FAIL ();
       break;
 
@@ -4998,7 +5000,7 @@ elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
            (_("%B(%A+%#Lx): unresolvable %s relocation against symbol `%s'"),
             input_bfd, input_section, rel->r_offset, howto->name, name);
          bfd_set_error (bfd_error_bad_value);
-         return FALSE;
+         return bfd_reloc_notsupported;
        }
       else if (h->plt.offset == (bfd_vma) -1)
        goto bad_ifunc_reloc;
@@ -5022,7 +5024,7 @@ bad_ifunc_reloc:
               "symbol `%s' isn't handled by %s"), input_bfd,
             howto->name, name, __FUNCTION__);
          bfd_set_error (bfd_error_bad_value);
-         return FALSE;
+         return bfd_reloc_notsupported;
 
        case BFD_RELOC_AARCH64_NN:
          if (rel->r_addend != 0)
@@ -5038,7 +5040,7 @@ bad_ifunc_reloc:
                   "symbol `%s' has non-zero addend: %Ld"),
                 input_bfd, howto->name, name, rel->r_addend);
              bfd_set_error (bfd_error_bad_value);
-             return FALSE;
+             return bfd_reloc_notsupported;
            }
 
          /* Generate dynamic relocation only when there is a
@@ -5362,7 +5364,7 @@ bad_ifunc_reloc:
             input_bfd, elfNN_aarch64_howto_table[howto_index].name,
             h->root.root.string);
          bfd_set_error (bfd_error_bad_value);
-         return FALSE;
+         return bfd_reloc_notsupported;
        }
       /* Fall through.  */
 
@@ -8766,7 +8768,8 @@ elf_aarch64_update_plt_entry (bfd *output_bfd,
 {
   reloc_howto_type *howto = elfNN_aarch64_howto_from_bfd_reloc (r_type);
 
-  _bfd_aarch64_elf_put_addend (output_bfd, plt_entry, r_type, howto, value);
+  /* FIXME: We should check the return value from this function call.  */
+  (void) _bfd_aarch64_elf_put_addend (output_bfd, plt_entry, r_type, howto, value);
 }
 
 static void
index 97a17f51477ceb549d77c48c7a55d75224359289..b4d858403764b3ae81ef2bdd9a702e8fdb666aa2 100644 (file)
@@ -65,8 +65,9 @@ CODE_FRAGMENT
 .
 .typedef enum bfd_reloc_status
 .{
-.  {* No errors detected.  *}
-.  bfd_reloc_ok,
+.  {* No errors detected.  Note - the value 2 is used so that it
+.     will not be mistaken for the boolean TRUE or FALSE values.  *}
+.  bfd_reloc_ok = 2,
 .
 .  {* The relocation was performed, but there was an overflow.  *}
 .  bfd_reloc_overflow,
index 80049e0583eef8a615c95dee4a38e7b9601e8bec..85353b667172800865e7c43cfa4a7fd25608bd02 100644 (file)
@@ -1,3 +1,9 @@
+2017-10-12  Nick Clifton  <nickc@redhat.com>
+
+       * testsuite/ld-aarch64/pcrel_pic_defined.d: Expect errors not
+       warnings.  Expect errors about unsupported relocations.
+       * testsuite/ld-aarch64/pcrel_pic_undefined.d: Likewise.
+
 2017-10-12  H.J. Lu  <hongjiu.lu@intel.com>
 
        * testsuite/ld-elf/pr22269b.d: Expect warning of
index 743e810b96fcf274d778a5562dcf3d14343f4708..a611e313ff77e1001c9a1cef19915e5d6a543846 100644 (file)
@@ -1,10 +1,17 @@
 #name: PC-Rel relocation against defined
 #source: pcrel.s
 #ld: -shared -e0 -defsym global_a=0x1000 -defsym global_b=0x2000
-#warning: .*: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `global_a.*bind externally.*fPIC.*
-#warning: .*: relocation R_AARCH64_ADR_PREL_PG_HI21_NC against symbol `global_a.*bind externally.*fPIC.*
-#warning: .*: relocation R_AARCH64_ADR_PREL_LO21 against symbol `global_a.*bind externally.*fPIC.*
-#warning: .*: relocation R_AARCH64_LD_PREL_LO19 against symbol `global_a.*bind externally.*fPIC.*
-#warning: .*: relocation R_AARCH64_PREL16 against symbol `global_a.*bind externally.*fPIC.*
-#warning: .*: relocation R_AARCH64_PREL32 against symbol `global_a.*bind externally.*fPIC.*
-#warning: .*: relocation R_AARCH64_PREL64 against symbol `global_a.*bind externally.*fPIC.*
+#error: .*: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `global_a.*bind externally.*fPIC.*
+#error: .*: dangerous relocation: unsupported relocation
+#error: .*: relocation R_AARCH64_ADR_PREL_PG_HI21_NC against symbol `global_a.*bind externally.*fPIC.*
+#error: .*: dangerous relocation: unsupported relocation
+#error: .*: relocation R_AARCH64_ADR_PREL_LO21 against symbol `global_a.*bind externally.*fPIC.*
+#error: .*: dangerous relocation: unsupported relocation
+#error: .*: relocation R_AARCH64_LD_PREL_LO19 against symbol `global_a.*bind externally.*fPIC.*
+#error: .*: dangerous relocation: unsupported relocation
+#error: .*: relocation R_AARCH64_PREL16 against symbol `global_a.*bind externally.*fPIC.*
+#error: .*: dangerous relocation: unsupported relocation
+#error: .*: relocation R_AARCH64_PREL32 against symbol `global_a.*bind externally.*fPIC.*
+#error: .*: dangerous relocation: unsupported relocation
+#error: .*: relocation R_AARCH64_PREL64 against symbol `global_a.*bind externally.*fPIC.*
+#error: .*: dangerous relocation: unsupported relocation
index f7f048d9da6cfef37928a003bb8d4b3579f61e17..b5d63722352c18cec92201620d850fd8a7ed7d13 100644 (file)
@@ -1,10 +1,17 @@
 #name: PC-Rel relocation against undefined
 #source: pcrel.s
 #ld: -shared -e0 -defsym global_b=0x2000
-#warning: .*: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `global_a.*bind externally.*fPIC.*
-#warning: .*: relocation R_AARCH64_ADR_PREL_PG_HI21_NC against symbol `global_a.*bind externally.*fPIC.*
-#warning: .*: relocation R_AARCH64_ADR_PREL_LO21 against symbol `global_a.*bind externally.*fPIC.*
-#warning: .*: relocation R_AARCH64_LD_PREL_LO19 against symbol `global_a.*bind externally.*fPIC.*
-#warning: .*: relocation R_AARCH64_PREL16 against symbol `global_a.*bind externally.*fPIC.*
-#warning: .*: relocation R_AARCH64_PREL32 against symbol `global_a.*bind externally.*fPIC.*
-#warning: .*: relocation R_AARCH64_PREL64 against symbol `global_a.*bind externally.*fPIC.*
+#error: .*: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `global_a.*bind externally.*fPIC.*
+#error: .*: dangerous relocation: unsupported relocation
+#error: .*: relocation R_AARCH64_ADR_PREL_PG_HI21_NC against symbol `global_a.*bind externally.*fPIC.*
+#error: .*: dangerous relocation: unsupported relocation
+#error: .*: relocation R_AARCH64_ADR_PREL_LO21 against symbol `global_a.*bind externally.*fPIC.*
+#error: .*: dangerous relocation: unsupported relocation
+#error: .*: relocation R_AARCH64_LD_PREL_LO19 against symbol `global_a.*bind externally.*fPIC.*
+#error: .*: dangerous relocation: unsupported relocation
+#error: .*: relocation R_AARCH64_PREL16 against symbol `global_a.*bind externally.*fPIC.*
+#error: .*: dangerous relocation: unsupported relocation
+#error: .*: relocation R_AARCH64_PREL32 against symbol `global_a.*bind externally.*fPIC.*
+#error: .*: dangerous relocation: unsupported relocation
+#error: .*: relocation R_AARCH64_PREL64 against symbol `global_a.*bind externally.*fPIC.*
+#error: .*: dangerous relocation: unsupported relocation