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]

[committed, PATCH] x86: Add DT_PLTRELSZ/DT_PLTREL/DT_JMPREL for PLT relocation


x86, PLT relocation may contain R_386_TLS_DESC or R_X86_64_TLSDESC
even though there is no real PLT.  We need to add DT_PLTRELSZ, DT_PLTREL
and DT_JMPREL if there is a .rel.plt/.rela.plt section.

bfd/

	* elf32-i386.c (elf_i386_size_dynamic_sections): Alwasys add
	DT_PLTRELSZ, DT_PLTREL and DT_JMPREL for .rel.plt section.
	* elf64-x86-64.c (elf_x86_64_size_dynamic_sections): Alwasys
	add DT_PLTRELSZ, DT_PLTREL and DT_JMPREL for .rela.plt section.

ld/

	* testsuite/ld-i386/tlsdesc2.d: New test.
	* testsuite/ld-x86-64/tlsdesc2.d: Likewise.
---
 bfd/ChangeLog                     |  7 +++++++
 bfd/elf32-i386.c                  | 14 +++++++-------
 bfd/elf64-x86-64.c                | 22 +++++++++++-----------
 ld/ChangeLog                      |  5 +++++
 ld/testsuite/ld-i386/i386.exp     |  1 +
 ld/testsuite/ld-i386/tlsdesc2.d   | 10 ++++++++++
 ld/testsuite/ld-x86-64/tlsdesc2.d | 10 ++++++++++
 ld/testsuite/ld-x86-64/x86-64.exp |  1 +
 8 files changed, 52 insertions(+), 18 deletions(-)
 create mode 100644 ld/testsuite/ld-i386/tlsdesc2.d
 create mode 100644 ld/testsuite/ld-x86-64/tlsdesc2.d

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 26b3572..3234230 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,10 @@
+2017-04-26  H.J. Lu  <hongjiu.lu@intel.com>
+
+	* elf32-i386.c (elf_i386_size_dynamic_sections): Alwasys add
+	DT_PLTRELSZ, DT_PLTREL and DT_JMPREL for .rel.plt section.
+	* elf64-x86-64.c (elf_x86_64_size_dynamic_sections): Alwasys
+	add DT_PLTRELSZ, DT_PLTREL and DT_JMPREL for .rela.plt section.
+
 2017-04-26  Nick Clifton  <nickc@redhat.com>
 
 	PR binutils/21434
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index 9a568ce..78c5d5b 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -3577,14 +3577,14 @@ elf_i386_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
 	     relocation.  */
 	  if (!add_dynamic_entry (DT_PLTGOT, 0))
 	    return FALSE;
+	}
 
-	  if (htab->elf.srelplt->size != 0)
-	    {
-	      if (!add_dynamic_entry (DT_PLTRELSZ, 0)
-		  || !add_dynamic_entry (DT_PLTREL, DT_REL)
-		  || !add_dynamic_entry (DT_JMPREL, 0))
-		return FALSE;
-	    }
+      if (htab->elf.srelplt->size != 0)
+	{
+	  if (!add_dynamic_entry (DT_PLTRELSZ, 0)
+	      || !add_dynamic_entry (DT_PLTREL, DT_REL)
+	      || !add_dynamic_entry (DT_JMPREL, 0))
+	    return FALSE;
 	}
 
       if (relocs)
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 965ceb2..0e0a020 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -4052,21 +4052,21 @@ elf_x86_64_size_dynamic_sections (bfd *output_bfd,
 	     relocation.  */
 	  if (!add_dynamic_entry (DT_PLTGOT, 0))
 	    return FALSE;
+	}
 
-	  if (htab->elf.srelplt->size != 0)
-	    {
-	      if (!add_dynamic_entry (DT_PLTRELSZ, 0)
-		  || !add_dynamic_entry (DT_PLTREL, DT_RELA)
-		  || !add_dynamic_entry (DT_JMPREL, 0))
-		return FALSE;
-	    }
-
-	  if (htab->tlsdesc_plt
-	      && (!add_dynamic_entry (DT_TLSDESC_PLT, 0)
-		  || !add_dynamic_entry (DT_TLSDESC_GOT, 0)))
+      if (htab->elf.srelplt->size != 0)
+	{
+	  if (!add_dynamic_entry (DT_PLTRELSZ, 0)
+	      || !add_dynamic_entry (DT_PLTREL, DT_RELA)
+	      || !add_dynamic_entry (DT_JMPREL, 0))
 	    return FALSE;
 	}
 
+      if (htab->tlsdesc_plt
+	  && (!add_dynamic_entry (DT_TLSDESC_PLT, 0)
+	      || !add_dynamic_entry (DT_TLSDESC_GOT, 0)))
+	return FALSE;
+
       if (relocs)
 	{
 	  if (!add_dynamic_entry (DT_RELA, 0)
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 93165f2..c93d903 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,8 @@
+2017-04-26  H.J. Lu  <hongjiu.lu@intel.com>
+
+	* testsuite/ld-i386/tlsdesc2.d: New test.
+	* testsuite/ld-x86-64/tlsdesc2.d: Likewise.
+
 2017-04-26  Maciej W. Rozycki  <macro@imgtec.com>
 
 	PR ld/21334
diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
index 844b36f..a709bcf 100644
--- a/ld/testsuite/ld-i386/i386.exp
+++ b/ld/testsuite/ld-i386/i386.exp
@@ -437,6 +437,7 @@ run_dump_test "pr18801"
 run_dump_test "pr18815"
 run_dump_test "pr19939a"
 run_dump_test "pr19939b"
+run_dump_test "tlsdesc2"
 
 proc undefined_weak {cflags ldflags} {
     set testname "Undefined weak symbol"
diff --git a/ld/testsuite/ld-i386/tlsdesc2.d b/ld/testsuite/ld-i386/tlsdesc2.d
new file mode 100644
index 0000000..b8569e8
--- /dev/null
+++ b/ld/testsuite/ld-i386/tlsdesc2.d
@@ -0,0 +1,10 @@
+#source: tlsdesc.s
+#as: --32
+#ld: -melf_i386 -shared -z now
+#readelf: -d --wide
+
+#...
+.*\(PLTRELSZ\).*
+.*\(PLTREL\).*
+.*\(JMPREL\).*
+#pass
diff --git a/ld/testsuite/ld-x86-64/tlsdesc2.d b/ld/testsuite/ld-x86-64/tlsdesc2.d
new file mode 100644
index 0000000..8679757
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsdesc2.d
@@ -0,0 +1,10 @@
+#source: tlsdesc.s
+#as: --64
+#ld: -melf_x86_64 -shared -z now
+#readelf: -d --wide
+
+#...
+.*\(PLTRELSZ\).*
+.*\(PLTREL\).*
+.*\(JMPREL\).*
+#pass
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
index a9394c3..7127eca 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -530,6 +530,7 @@ run_dump_test "pr20253-4e"
 run_dump_test "pr20253-4f"
 run_dump_test "pr20253-5a"
 run_dump_test "pr20253-5b"
+run_dump_test "tlsdesc2"
 
 proc undefined_weak {cflags ldflags} {
     set testname "Undefined weak symbol"
-- 
2.9.3


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