aarch64: Return an error on conditional branch to an undefined symbol
authorSiddhesh Poyarekar <siddesh.poyarekar@arm.com>
Tue, 1 Sep 2020 08:55:52 +0000 (14:25 +0530)
committerSiddhesh Poyarekar <siddhesh@gotplt.org>
Thu, 10 Sep 2020 16:12:37 +0000 (21:42 +0530)
The fix in 7e05773767820b441b23a16628b55c98cb1aef46 introduced a PLT
for conditional jumps when the target symbol is undefined.  This is
incorrect because conditional branch relocations are not allowed to
clobber IP0/IP1 and hence, should not result in a dynamic relocation.

Revert that change and in its place, issue an error when the target
symbol is undefined.

bfd/

2020-09-10  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Revert
changes in 7e05773767820b441b23a16628b55c98cb1aef46.  Set
error for undefined symbol in BFD_RELOC_AARCH64_BRANCH19 and
BFD_RELOC_AARCH64_TSTBR14 relocations.

ld/

2020-09-10  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* testsuite/ld-aarch64/emit-relocs-560.d: Expect error instead
of valid output.

bfd/ChangeLog
bfd/elfnn-aarch64.c
ld/ChangeLog
ld/testsuite/ld-aarch64/emit-relocs-560.d

index f26690145e32129f6632a3a1113f0c121a0854cf..19415d6b9f13cce86f7e89db1a16ea00f9f35180 100644 (file)
@@ -1,3 +1,10 @@
+2020-09-10  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>
+
+       * elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Revert
+       changes in 7e05773767820b441b23a16628b55c98cb1aef46.  Set
+       error for undefined symbol in BFD_RELOC_AARCH64_BRANCH19 and
+       BFD_RELOC_AARCH64_TSTBR14 relocations.
+
 2020-09-09  Nick Clifton  <nickc@redhat.com>
 
        * cofflink.c (coff_link_check_archive_element): Move the check for
index 5b4c189b593c6fe96053571ad8f95bd78b293dae..a9924e7ec5664c8f791bc317e40932f09f507ba8 100644 (file)
@@ -5447,7 +5447,6 @@ elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
   bfd_vma orig_value = value;
   bfd_boolean resolved_to_zero;
   bfd_boolean abs_symbol_p;
-  bfd_boolean via_plt_p;
 
   globals = elf_aarch64_hash_table (info);
 
@@ -5469,8 +5468,6 @@ elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
                  : bfd_is_und_section (sym_sec));
   abs_symbol_p = h != NULL && bfd_is_abs_symbol (&h->root);
 
-  via_plt_p = (globals->root.splt != NULL && h != NULL
-              && h->plt.offset != (bfd_vma) - 1);
 
   /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
      it here if it is defined in a non-shared object.  */
@@ -5806,23 +5803,12 @@ elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
        value += signed_addend;
       break;
 
-    case BFD_RELOC_AARCH64_BRANCH19:
-    case BFD_RELOC_AARCH64_TSTBR14:
-      /* A conditional branch to an undefined weak symbol is converted to a
-        branch to itself.  */
-      if (weak_undef_p && !via_plt_p)
-       {
-         value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type,
-                                                      place, value,
-                                                      signed_addend,
-                                                      weak_undef_p);
-         break;
-       }
-      /* Fall through.  */
     case BFD_RELOC_AARCH64_CALL26:
     case BFD_RELOC_AARCH64_JUMP26:
       {
        asection *splt = globals->root.splt;
+       bfd_boolean via_plt_p =
+         splt != NULL && h != NULL && h->plt.offset != (bfd_vma) - 1;
 
        /* A call to an undefined weak symbol is converted to a jump to
           the next instruction unless a PLT entry will be created.
@@ -5903,6 +5889,23 @@ elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
          bfd_set_error (bfd_error_bad_value);
          return bfd_reloc_notsupported;
        }
+      value = _bfd_aarch64_elf_resolve_relocation (input_bfd, bfd_r_type,
+                                                  place, value,
+                                                  signed_addend,
+                                                  weak_undef_p);
+      break;
+
+    case BFD_RELOC_AARCH64_BRANCH19:
+    case BFD_RELOC_AARCH64_TSTBR14:
+      if (h && h->root.type == bfd_link_hash_undefined)
+       {
+         _bfd_error_handler
+           /* xgettext:c-format */
+           (_("%pB: conditional branch to undefined symbol `%s' "
+              "not allowed"), input_bfd, h->root.root.string);
+         bfd_set_error (bfd_error_bad_value);
+         return bfd_reloc_notsupported;
+       }
       /* Fall through.  */
 
     case BFD_RELOC_AARCH64_16:
@@ -7968,8 +7971,6 @@ elfNN_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info,
            break;
          }
 
-       case BFD_RELOC_AARCH64_BRANCH19:
-       case BFD_RELOC_AARCH64_TSTBR14:
        case BFD_RELOC_AARCH64_CALL26:
        case BFD_RELOC_AARCH64_JUMP26:
          /* If this is a local symbol then we resolve it
index 3e8662868aea288ac21f444aa9e66b313000e0d6..3b9a42669722b5d469bab3dc639e7c9c1baab05f 100644 (file)
@@ -1,3 +1,8 @@
+2020-09-10  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>
+
+       * testsuite/ld-aarch64/emit-relocs-560.d: Expect error instead
+       of valid output.
+
 2020-09-10  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/26590
index 153532457b4ea955fb09b6c97508fe8ce78adcaf..8751b743bd470179be54c9fc7c9330fada3ca2c6 100644 (file)
@@ -1,8 +1,3 @@
 #source: emit-relocs-560.s
 #ld: -shared
-#readelf: -r
-
-Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 2 entries:
-  Offset          Info           Type           Sym. Value    Sym. Name \+ Addend
-[0-9a-f]+  000100000402 R_AARCH64_JUMP_SL 0000000000000000 baz \+ 0
-[0-9a-f]+  000200000402 R_AARCH64_JUMP_SL 0000000000000000 bar \+ 0
+#error: .*: conditional branch to undefined symbol `bar' not allowed