[AArch64] Create .got section if _GLOBAL_OFFSET_TABLE_ referenced
authorJiong Wang <jiong.wang@arm.com>
Mon, 7 Mar 2016 15:40:50 +0000 (15:40 +0000)
committerJiong Wang <jiong.wang@arm.com>
Mon, 7 Mar 2016 15:40:50 +0000 (15:40 +0000)
2016-03-07  Jiong Wang  <jiong.wang@arm.com>

bfd/
  * elfnn-aarch64.c (elfNN_aarch64_check_relocs): Always create .got section
  if the symbol "_GLOBAL_OFFSET_TABLE_" referenced.

ld/
  * testsuite/ld-aarch64/implicit_got_section_1.s: New test source file.
  * testsuite/ld-aarch64/implicit_got_section_1.d: New test expected result.
  * testsuite/ld-aarch64/aarch64-elf.exp: Run new test.

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

index 5f9f99d62f87da4e41487debf37182617a8d1944..d9d9e77df2e553db5077c66ca4ec7264755ff609 100644 (file)
@@ -1,3 +1,8 @@
+2016-03-07  Jiong Wang  <jiong.wang@arm.com>
+
+       * elfnn-aarch64.c (elfNN_aarch64_check_relocs): Always create .got
+       section if the symbol "_GLOBAL_OFFSET_TABLE_" is referenced.
+
 2016-03-04  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/19579
index 599b5f8516acbd51cc5123af4550f9d689b5d13d..d14b734e065c0bfcf8d39ec7ff8d4ee25e7afa11 100644 (file)
@@ -7080,6 +7080,22 @@ elfNN_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info,
 
       if (h != NULL)
        {
+         /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
+            This shows up in particular in an R_AARCH64_PREL64 in large model
+            when calculating the pc-relative address to .got section which is
+            used to initialize the gp register.  */
+         if (h->root.root.string
+             && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
+           {
+             if (htab->root.dynobj == NULL)
+               htab->root.dynobj = abfd;
+
+             if (! aarch64_elf_create_got_section (htab->root.dynobj, info))
+               return FALSE;
+
+             BFD_ASSERT (h == htab->root.hgot);
+           }
+
          /* Create the ifunc sections for static executables.  If we
             never see an indirect function symbol nor we are building
             a static executable, those sections will be empty and
index d325c816a4681d13b090d12f2cb69348f47df97a..c42042c26e4f161b9f5b8be69c4ed8ad05fc65a5 100644 (file)
@@ -1,3 +1,10 @@
+2016-03-07  Jiong Wang  <jiong.wang@arm.com>
+
+       * testsuite/ld-aarch64/implicit_got_section_1.s: New test source file.
+       * testsuite/ld-aarch64/implicit_got_section_1.d: New test expected
+       result.
+       * testsuite/ld-aarch64/aarch64-elf.exp: Run new test.
+
 2016-03-06  H.J. Lu  <hongjiu.lu@intel.com>
 
        * testsuite/ld-i386/i386.exp: Link tmpdir/copyreloc-main.o
index 37ce48c3c745af6836661b2efa470fa46d899526..b9c413307580f86dfb750316b4faf834a88d6eb8 100644 (file)
@@ -229,6 +229,7 @@ run_dump_test "gc-tls-relocs"
 run_dump_test "gc-plt-relocs"
 run_dump_test "gc-relocs-257-dyn"
 run_dump_test "gc-relocs-257"
+run_dump_test "implicit_got_section_1"
 run_dump_test "pr17415"
 run_dump_test "tprel_g2_overflow"
 run_dump_test "tprel_add_lo12_overflow"
diff --git a/ld/testsuite/ld-aarch64/implicit_got_section_1.d b/ld/testsuite/ld-aarch64/implicit_got_section_1.d
new file mode 100644 (file)
index 0000000..1ad24fe
--- /dev/null
@@ -0,0 +1,5 @@
+#source: implicit_got_section_1.s
+#ld: -e0
+#readelf: -r
+
+There are no relocations in this file.
diff --git a/ld/testsuite/ld-aarch64/implicit_got_section_1.s b/ld/testsuite/ld-aarch64/implicit_got_section_1.s
new file mode 100644 (file)
index 0000000..8d80748
--- /dev/null
@@ -0,0 +1,3 @@
+       .text
+test:
+       .word _GLOBAL_OFFSET_TABLE_ - .