This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[AArch64] Use SYMBOL_REFERENCES_LOCAL in one symbol check


During fixing copy relocation on AArch64, I noticed for some pc-relative
relocations, we want to allow them under PIC mode.  However the current
check now looks inaccurate to me.  A normal global symbol even defined in
.so can still bind externally in which case pc-relative relocation is not
allowed.

I think SYMBOL_REFERENCES_LOCAL should be used and is more accurate than
the original individual checks..

This patch fixed this.

cross/native binutils/gas/ld/gcc/g++ check OK.

OK for master?

bfd/
2017-06-15  Jiong Wang  <jiong.wang@arm.com>

        * elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Use
        SYMBOL_REFERENCES_LOCAL.

ld/
        * testsuite/ld-aarch64/aarch64-elf.exp: Update test name
        * testsuite/ld-aarch64/pcrel.s: Add new testcases.
        * testsuite/ld-aarch64/pcrel_pic_undefined.d: Update the
        expected warnings.
        * testsuite/ld-aarch64/pcrel_pic_defined_local.d: Rename ...
        * testsuite/ld-aarch64/pcrel_pic_defined.d: ... to this.
        Update expected warnings.

diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
index a566d0f4a710fb3f09ce74273cf170350491cfbd..b5ed3d75d707b24e3a722dc42ae93ee39d13b47c 100644
--- a/bfd/elfnn-aarch64.c
+++ b/bfd/elfnn-aarch64.c
@@ -5329,15 +5329,15 @@ elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
       if (bfd_link_pic (info)
 	  && (input_section->flags & SEC_ALLOC) != 0
 	  && (input_section->flags & SEC_READONLY) != 0
-	  && h != NULL
-	  && !h->def_regular)
+	  && !SYMBOL_REFERENCES_LOCAL (info, h))
 	{
 	  int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
 
 	  _bfd_error_handler
 	    /* xgettext:c-format */
-	    (_("%B: relocation %s against external symbol `%s' can not be used"
-	       " when making a shared object; recompile with -fPIC"),
+	    (_("%B: relocation %s against symbol `%s' which may bind "
+	       "externally 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);
diff --git a/ld/testsuite/ld-aarch64/aarch64-elf.exp b/ld/testsuite/ld-aarch64/aarch64-elf.exp
index f171f6fe3483e2b24e73cdb0fbf26bb5576d1ab2..b9c9885cb42d142a42a2fa55a248adbaca357a24 100644
--- a/ld/testsuite/ld-aarch64/aarch64-elf.exp
+++ b/ld/testsuite/ld-aarch64/aarch64-elf.exp
@@ -195,7 +195,7 @@ run_dump_test_lp64 "local-addend-r"
 
 # test error handling on pcrel relocation for shared libraries.
 run_dump_test_lp64 "pcrel_pic_undefined"
-run_dump_test_lp64 "pcrel_pic_defined_local"
+run_dump_test_lp64 "pcrel_pic_defined"
 
 run_dump_test "limit-b"
 run_dump_test "limit-bl"
diff --git a/ld/testsuite/ld-aarch64/pcrel.s b/ld/testsuite/ld-aarch64/pcrel.s
index df542ef5deea7e065c8efc3836b53bc56dd11e95..c5e18d019e4e802273bcbd88b232699fa2f582d7 100644
--- a/ld/testsuite/ld-aarch64/pcrel.s
+++ b/ld/testsuite/ld-aarch64/pcrel.s
@@ -1,3 +1,4 @@
+	.hidden global_b
 	.text
 	.align 2
 main:
@@ -18,3 +19,8 @@ main:
 	.word	global_a - .
 	.xword	global_a - .
 
+	# Defined global symbol may bind externally because of copy relocation,
+	# while defined hidden symbol binds locally.  LD should be able to
+	# differenciate this.
+	adrp	x0, :pg_hi21:global_b
+	.xword	global_b - .
diff --git a/ld/testsuite/ld-aarch64/pcrel_pic_defined.d b/ld/testsuite/ld-aarch64/pcrel_pic_defined.d
new file mode 100644
index 0000000000000000000000000000000000000000..743e810b96fcf274d778a5562dcf3d14343f4708
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/pcrel_pic_defined.d
@@ -0,0 +1,10 @@
+#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.*
diff --git a/ld/testsuite/ld-aarch64/pcrel_pic_defined_local.d b/ld/testsuite/ld-aarch64/pcrel_pic_defined_local.d
deleted file mode 100644
index 832652fc9f621b3d7570fe179738d62a47b7bbd8..0000000000000000000000000000000000000000
--- a/ld/testsuite/ld-aarch64/pcrel_pic_defined_local.d
+++ /dev/null
@@ -1,5 +0,0 @@
-#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
index de7f020eb4c640f8a23d0359a3b33490d4abc40d..f7f048d9da6cfef37928a003bb8d4b3579f61e17 100644
--- a/ld/testsuite/ld-aarch64/pcrel_pic_undefined.d
+++ b/ld/testsuite/ld-aarch64/pcrel_pic_undefined.d
@@ -1,10 +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.*
+#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.*

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]