]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[AArch64][Backport]Improve PC-relative relocation check for shared library
authorJiong Wang <jiong.wang@arm.com>
Tue, 5 May 2015 19:55:20 +0000 (20:55 +0100)
committerJiong Wang <jiong.wang@arm.com>
Tue, 5 May 2015 19:55:20 +0000 (20:55 +0100)
Apply from master:

2015-04-24  Jiong. Wang  <jiong.wang@arm.com>

bfd/
* elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Reject
PC-relative relocation for external symbol.

ld/testsuite/
* ld-aarch64/pcrel.s: New testcase.
* ld-aarch64/pcrel_pic_defiend_local.d: New expect file.
* ld-aarch64/pcrel_pic_undefined.d: Ditto.
* ld-aarch64/aarch64-elf.exp: Run them.

bfd/ChangeLog
bfd/elfnn-aarch64.c
ld/testsuite/ChangeLog
ld/testsuite/ld-aarch64/aarch64-elf.exp
ld/testsuite/ld-aarch64/pcrel.s [new file with mode: 0644]
ld/testsuite/ld-aarch64/pcrel_pic_defined_local.d [new file with mode: 0644]
ld/testsuite/ld-aarch64/pcrel_pic_undefined.d [new file with mode: 0644]

index 2060e3c627f9806b2cfad3487144d1b0d69ef3b9..989e4438bdc6d26660908e963d74368cf0418b23 100644 (file)
@@ -1,3 +1,12 @@
+2015-05-05  Jiong Wang  <jiong.wang@arm.com>
+
+       Apply from master:
+
+       2015-04-24  Jiong. Wang  <jiong.wang@arm.com>
+
+       * elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Reject
+       PC-relative relocation for external symbol.
+
 2015-04-10  Alan Modra  <amodra@gmail.com>
 
        PR ld/18222
index f23afb5e60d1f9f1fb32c140b75ac69f704e4b25..a04a5241d7c56bf7b48d15168420baecdaed122e 100644 (file)
@@ -4427,16 +4427,36 @@ elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
                                                   signed_addend, weak_undef_p);
       break;
 
+    case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
+    case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
+    case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
+    case BFD_RELOC_AARCH64_LD_LO19_PCREL:
+    case BFD_RELOC_AARCH64_16_PCREL:
+    case BFD_RELOC_AARCH64_32_PCREL:
+    case BFD_RELOC_AARCH64_64_PCREL:
+      if (info->shared
+         && (input_section->flags & SEC_ALLOC) != 0
+         && (input_section->flags & SEC_READONLY) != 0
+         && h != NULL
+         && !h->def_regular)
+       {
+         int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
+
+         (*_bfd_error_handler)
+           (_("%B: relocation %s against external symbol `%s' can not be used"
+              " when making a shared object; recompile with -fPIC"),
+            input_bfd, elfNN_aarch64_howto_table[howto_index].name,
+            h->root.root.string);
+         bfd_set_error (bfd_error_bad_value);
+         return FALSE;
+       }
+
     case BFD_RELOC_AARCH64_16:
 #if ARCH_SIZE == 64
     case BFD_RELOC_AARCH64_32:
 #endif
     case BFD_RELOC_AARCH64_ADD_LO12:
-    case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
-    case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
-    case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
     case BFD_RELOC_AARCH64_BRANCH19:
-    case BFD_RELOC_AARCH64_LD_LO19_PCREL:
     case BFD_RELOC_AARCH64_LDST8_LO12:
     case BFD_RELOC_AARCH64_LDST16_LO12:
     case BFD_RELOC_AARCH64_LDST32_LO12:
@@ -4452,9 +4472,6 @@ elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
     case BFD_RELOC_AARCH64_MOVW_G2:
     case BFD_RELOC_AARCH64_MOVW_G2_NC:
     case BFD_RELOC_AARCH64_MOVW_G3:
-    case BFD_RELOC_AARCH64_16_PCREL:
-    case BFD_RELOC_AARCH64_32_PCREL:
-    case BFD_RELOC_AARCH64_64_PCREL:
     case BFD_RELOC_AARCH64_TSTBR14:
       value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
                                                   signed_addend, weak_undef_p);
index 9aef68173f131d5b7f7da6cc638957d93118b8ec..49842983e704042387b3efcd24f796e947beff79 100644 (file)
@@ -1,3 +1,14 @@
+2015-05-05  Jiong Wang  <jiong.wang@arm.com>
+
+       Apply from master:
+
+       2015-04-24  Jiong. Wang  <jiong.wang@arm.com>
+
+       * ld-aarch64/pcrel.s: New testcase.
+       * ld-aarch64/pcrel_pic_defiend_local.d: New expect file.
+       * ld-aarch64/pcrel_pic_undefined.d: Ditto.
+       * ld-aarch64/aarch64-elf.exp: Run them.
+
 2015-04-10  Alan Modra  <amodra@gmail.com>
 
        Revert 2015-03-06  H.J. Lu  <hongjiu.lu@intel.com>
index c0bd39ae36a38268602597a3d69e7c84cef26814..7a24e52f2e1a92fd15e70c10570f2fbd9ed54624 100644 (file)
@@ -104,6 +104,10 @@ run_dump_test "emit-relocs-local-addend"
 # test addend correctness when -r specified.
 run_dump_test "local-addend-r"
 
+# test error handling on pcrel relocation for shared libraries.
+run_dump_test "pcrel_pic_undefined"
+run_dump_test "pcrel_pic_defined_local"
+
 run_dump_test "limit-b"
 run_dump_test "limit-bl"
 run_dump_test "farcall-section"
diff --git a/ld/testsuite/ld-aarch64/pcrel.s b/ld/testsuite/ld-aarch64/pcrel.s
new file mode 100644 (file)
index 0000000..df542ef
--- /dev/null
@@ -0,0 +1,20 @@
+       .text
+       .align 2
+main:
+       # R_AARCH64_ADR_PREL_PG_HI21
+       # R_AARCH64_ADR_PREL_PG_HI21_NC
+       # R_AARCH64_ADR_LO_21
+       adrp    x0, :pg_hi21:global_a
+       adrp    x1, :pg_hi21_nc:global_a
+       adr     x2, global_a
+
+       #R_AARCH64_LD_PREL_LO19
+       ldr     x3, global_a
+
+       # R_AARCH64_PREL16
+       # R_AARCH64_PREL32
+       # R_AARCH64_PREL64
+       .hword  global_a - .
+       .word   global_a - .
+       .xword  global_a - .
+
diff --git a/ld/testsuite/ld-aarch64/pcrel_pic_defined_local.d b/ld/testsuite/ld-aarch64/pcrel_pic_defined_local.d
new file mode 100644 (file)
index 0000000..832652f
--- /dev/null
@@ -0,0 +1,5 @@
+#name: PC-Rel relocation against defined
+#source: pcrel.s
+#objdump: -r
+#ld: -shared -e0 -defsym global_a=0x1000
+#...
diff --git a/ld/testsuite/ld-aarch64/pcrel_pic_undefined.d b/ld/testsuite/ld-aarch64/pcrel_pic_undefined.d
new file mode 100644 (file)
index 0000000..de7f020
--- /dev/null
@@ -0,0 +1,10 @@
+#name: PC-Rel relocation against undefined
+#source: pcrel.s
+#ld: -shared -e0
+#warning: .*: relocation R_AARCH64_ADR_PREL_PG_HI21 against external symbol.*fPIC.*
+#warning: .*: relocation R_AARCH64_ADR_PREL_PG_HI21_NC against external symbol.*fPIC.*
+#warning: .*: relocation R_AARCH64_ADR_PREL_LO21 against external symbol.*fPIC.*
+#warning: .*: relocation R_AARCH64_LD_PREL_LO19 against external symbol.*fPIC.*
+#warning: .*: relocation R_AARCH64_PREL16 against external symbol.*fPIC.*
+#warning: .*: relocation R_AARCH64_PREL32 against external symbol.*fPIC.*
+#warning: .*: relocation R_AARCH64_PREL64 against external symbol.*fPIC.*