This is the mail archive of the binutils-cvs@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]

[binutils-gdb] [AArch64] Create .got section if _GLOBAL_OFFSET_TABLE_ referenced


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=18f822a08fd5cb8fed8b0b318e7945545c255081

commit 18f822a08fd5cb8fed8b0b318e7945545c255081
Author: Jiong Wang <jiong.wang@arm.com>
Date:   Mon Mar 7 15:40:50 2016 +0000

    [AArch64] Create .got section if _GLOBAL_OFFSET_TABLE_ referenced
    
    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.

Diff:
---
 bfd/ChangeLog                                    |  5 +++++
 bfd/elfnn-aarch64.c                              | 16 ++++++++++++++++
 ld/ChangeLog                                     |  7 +++++++
 ld/testsuite/ld-aarch64/aarch64-elf.exp          |  1 +
 ld/testsuite/ld-aarch64/implicit_got_section_1.d |  5 +++++
 ld/testsuite/ld-aarch64/implicit_got_section_1.s |  3 +++
 6 files changed, 37 insertions(+)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 5f9f99d..d9d9e77 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -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
diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
index 599b5f8..d14b734 100644
--- a/bfd/elfnn-aarch64.c
+++ b/bfd/elfnn-aarch64.c
@@ -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
diff --git a/ld/ChangeLog b/ld/ChangeLog
index d325c81..c42042c 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -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
diff --git a/ld/testsuite/ld-aarch64/aarch64-elf.exp b/ld/testsuite/ld-aarch64/aarch64-elf.exp
index 37ce48c..b9c4133 100644
--- a/ld/testsuite/ld-aarch64/aarch64-elf.exp
+++ b/ld/testsuite/ld-aarch64/aarch64-elf.exp
@@ -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
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
+test:
+	.word _GLOBAL_OFFSET_TABLE_ - .


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