This is the mail archive of the 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] Create .got section if _GLOBAL_OFFSET_TABLE_ referenced

If a relocation refers to _GLOBAL_OFFSET_TABLE_, we should always create
the .got.  Otherwise, _GLOBAL_OFFSET_TABLE_ which implicitly points to
the start of .got section can't be resolved in some rare but do exist
scenarios (ppc32 seems has the same issue and have done the same fix).

ld regression OK on both cross and native environment.

OK for master?

2016-02-25  Jiong Wang  <>

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

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

diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
index 59c51cc..6e4c9f5 100644
--- a/bfd/elfnn-aarch64.c
+++ b/bfd/elfnn-aarch64.c
@@ -7053,6 +7053,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
diff --git a/ld/testsuite/ld-aarch64/aarch64-elf.exp b/ld/testsuite/ld-aarch64/aarch64-elf.exp
index 0e5b31e..9f4074f 100644
--- a/ld/testsuite/ld-aarch64/aarch64-elf.exp
+++ b/ld/testsuite/ld-aarch64/aarch64-elf.exp
@@ -223,6 +223,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
index 0000000..1ad24fe
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/implicit_got_section_1.d
@@ -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
index 0000000..8d80748
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/implicit_got_section_1.s
@@ -0,0 +1,3 @@
+	.text

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