[PR20402][LD][AARCH64]Don't emit RELATIVE relocation for absolute symbols which are...
authorRenlin Li <renlin.li@arm.com>
Wed, 7 Mar 2018 09:27:45 +0000 (09:27 +0000)
committerRenlin Li <renlin.li@arm.com>
Wed, 7 Mar 2018 14:47:27 +0000 (14:47 +0000)
For absolute symbols which are forced local or not dynamic, the ABS relocation
should be resolved at static linking time.

Originally, an RELATIVE/ABS relocation will be generated even for absolution
symbols for the dynamic linker to resolve.

bfd/

2018-03-07  Renlin Li  <renlin.li@arm.com>

PR ld/20402
* elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Check absolute symbol,
and don't emit relocation in specific case.

ld/

2018-03-07  Renlin Li  <renlin.li@arm.com>

PR ld/20402
* testsuite/ld-aarch64/aarch64-elf.exp: Run new test.
* testsuite/ld-aarch64/pr20402.s: New.
* testsuite/ld-aarch64/pr20402.d: New.

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

index 09fae15d21b053ff6b3a6b20314e99aaac9f948a..c0ad7eba3827898b1ac765698c24ac68ff371061 100644 (file)
@@ -1,3 +1,9 @@
+2018-03-07  Renlin Li  <renlin.li@arm.com>
+
+       PR ld/20402
+       * elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Check absolute
+       symbol, and don't emit relocation in specific case.
+
 2018-03-07  Alan Modra  <amodra@gmail.com>
 
        * elf64-mips.c (mips_elf64_rtype_to_howto): Return NULL on error.
index dc24df801e20d053912d52344f641a7566a17db6..beef91a22d083ac711375ec10ceddb9322e1ced5 100644 (file)
@@ -5074,6 +5074,7 @@ elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
   asection *base_got;
   bfd_vma orig_value = value;
   bfd_boolean resolved_to_zero;
+  bfd_boolean abs_symbol_p;
 
   globals = elf_aarch64_hash_table (info);
 
@@ -5093,6 +5094,9 @@ elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
 
   weak_undef_p = (h ? h->root.type == bfd_link_hash_undefweak
                  : bfd_is_und_section (sym_sec));
+  abs_symbol_p = (h !=NULL && h->root.type == bfd_link_hash_defined
+                 && bfd_is_abs_section (h->root.u.def.section));
+
 
   /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
      it here if it is defined in a non-shared object.  */
@@ -5360,6 +5364,12 @@ bad_ifunc_reloc:
              skip = TRUE;
              relocate = TRUE;
            }
+         else if (abs_symbol_p)
+           {
+             /* Local absolute symbol.  */
+             skip = (h->forced_local || (h->dynindx == -1));
+             relocate = skip;
+           }
 
          outrel.r_offset += (input_section->output_section->vma
                              + input_section->output_offset);
@@ -5369,8 +5379,7 @@ bad_ifunc_reloc:
          else if (h != NULL
                   && h->dynindx != -1
                   && (!bfd_link_pic (info)
-                      || !(bfd_link_pie (info)
-                           || SYMBOLIC_BIND (info, h))
+                      || !(bfd_link_pie (info) || SYMBOLIC_BIND (info, h))
                       || !h->def_regular))
            outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type);
          else
index 218df5cfa35bb2fc67125d10a6955e5eb2e2a222..dd441fa20a2cc98665ec5619ae459d21399cd0cb 100644 (file)
@@ -1,3 +1,10 @@
+2018-03-07  Renlin Li  <renlin.li@arm.com>
+
+       PR ld/20402
+       * testsuite/ld-aarch64/aarch64-elf.exp: Run new test.
+       * testsuite/ld-aarch64/pr20402.s: New.
+       * testsuite/ld-aarch64/pr20402.d: New.
+
 2018-03-06  Jim Wilson  <jimw@sifive.com>
 
        PR 22920
index c67ffb19ebfa074bdd4d203a5ef11bd0a61cb25e..de99a8b233bbb7f06fe70f5771f23a682d8f9fcb 100644 (file)
@@ -286,6 +286,7 @@ run_dump_test_lp64 "tprel_g2_overflow"
 run_dump_test "tprel_add_lo12_overflow"
 run_dump_test "protected-data"
 run_dump_test_lp64 "pr22764"
+run_dump_test_lp64 "pr20402"
 
 # ifunc tests
 run_dump_test "ifunc-1"
diff --git a/ld/testsuite/ld-aarch64/pr20402.d b/ld/testsuite/ld-aarch64/pr20402.d
new file mode 100644 (file)
index 0000000..9cfeeb7
--- /dev/null
@@ -0,0 +1,7 @@
+#ld: -pie -defsym foo=0x1 -defsym bar=0x2
+#readelf: -r
+
+Relocation section '\.rela\.dyn' at offset .* contains 2 entries:
+  Offset          Info           Type           Sym\. Value    Sym\. Name \+ Addend
+000000000000  000000000000 R_AARCH64_NONE                       0
+000000000000  000000000000 R_AARCH64_NONE                       0
diff --git a/ld/testsuite/ld-aarch64/pr20402.s b/ld/testsuite/ld-aarch64/pr20402.s
new file mode 100644 (file)
index 0000000..b18c5e7
--- /dev/null
@@ -0,0 +1,6 @@
+  .text
+  .global _start
+  .hidden foo
+_start:
+  .xword foo
+  .xword bar