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] Fix PLT first entry GOT operand calculation.


Embedding the .plt section in another revealed a bug in the way the
larl operand of the first magic plt entry is being calculated.  Fixed
with the attached patch.

bfd/ChangeLog:

	* elf64-s390.c (elf_s390_finish_dynamic_sections): Subtract plt
	section offset when calculation the larl operand in the first PLT
	entry.

ld/ChangeLog:

	* testsuite/ld-s390/pltoffset-1.dd: New test.
	* testsuite/ld-s390/pltoffset-1.ld: New test.
	* testsuite/ld-s390/pltoffset-1.s: New test.
	* testsuite/ld-s390/s390.exp: Run new test.
---
 bfd/ChangeLog                       |  6 ++++++
 bfd/elf64-s390.c                    |  7 ++++---
 ld/ChangeLog                        |  7 +++++++
 ld/testsuite/ld-s390/pltoffset-1.dd |  8 ++++++++
 ld/testsuite/ld-s390/pltoffset-1.ld | 34 ++++++++++++++++++++++++++++++++++
 ld/testsuite/ld-s390/pltoffset-1.s  | 12 ++++++++++++
 ld/testsuite/ld-s390/s390.exp       |  5 +++++
 7 files changed, 76 insertions(+), 3 deletions(-)
 create mode 100644 ld/testsuite/ld-s390/pltoffset-1.dd
 create mode 100644 ld/testsuite/ld-s390/pltoffset-1.ld
 create mode 100644 ld/testsuite/ld-s390/pltoffset-1.s

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index fb66662..7e4eb92 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2016-06-07  Ulrich Weigand  <ulrich.weigand@de.ibm.com>
+
+	* elf64-s390.c (elf_s390_finish_dynamic_sections): Subtract plt
+	section offset when calculation the larl operand in the first PLT
+	entry.
+
 2016-06-07  Alan Modra  <amodra@gmail.com>
 
 	* cpu-powerpc.c (powerpc_compatible): Allow bfd_mach_ppc_vle entry
diff --git a/bfd/elf64-s390.c b/bfd/elf64-s390.c
index b14b479..9160068 100644
--- a/bfd/elf64-s390.c
+++ b/bfd/elf64-s390.c
@@ -3782,9 +3782,10 @@ elf_s390_finish_dynamic_sections (bfd *output_bfd,
 		  PLT_FIRST_ENTRY_SIZE);
 	  /* Fixup relative address to start of GOT */
 	  bfd_put_32 (output_bfd,
-		      (htab->elf.sgotplt->output_section->vma +
-		       htab->elf.sgotplt->output_offset
-		       - htab->elf.splt->output_section->vma - 6)/2,
+		      (htab->elf.sgotplt->output_section->vma
+		       + htab->elf.sgotplt->output_offset
+		       - htab->elf.splt->output_section->vma
+		       - htab->elf.splt->output_offset - 6)/2,
 		      htab->elf.splt->contents + 8);
 	}
       if (elf_section_data (htab->elf.splt->output_section) != NULL)
diff --git a/ld/ChangeLog b/ld/ChangeLog
index ac08ee6..623194c 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,10 @@
+2016-06-07  Andreas Krebbel  <krebbel@linux.vnet.ibm.com>
+
+	* testsuite/ld-s390/pltoffset-1.dd: New test.
+	* testsuite/ld-s390/pltoffset-1.ld: New test.
+	* testsuite/ld-s390/pltoffset-1.s: New test.
+	* testsuite/ld-s390/s390.exp: Run new test.
+
 2016-06-07  Alan Modra  <amodra@gmail.com>
 
 	* testsuite/ld-powerpc/apuinfo1.s: Delete nop.
diff --git a/ld/testsuite/ld-s390/pltoffset-1.dd b/ld/testsuite/ld-s390/pltoffset-1.dd
new file mode 100644
index 0000000..dcc339b
--- /dev/null
+++ b/ld/testsuite/ld-s390/pltoffset-1.dd
@@ -0,0 +1,8 @@
+tmpdir/pltoffset-1:     file format elf64-s390
+
+Disassembly of section .text:
+
+.* <.text>:
+.*:	00 00 00 00 [	 ]*.long	0x00000000
+.*:	e3 10 f0 38 00 24 [	 ]*stg	%r1,56\(%r15\)
+.*:	c0 10 00 00 00 27 [	 ]*larl	%r1,58 <_GLOBAL_OFFSET_TABLE_>
diff --git a/ld/testsuite/ld-s390/pltoffset-1.ld b/ld/testsuite/ld-s390/pltoffset-1.ld
new file mode 100644
index 0000000..742c8fd
--- /dev/null
+++ b/ld/testsuite/ld-s390/pltoffset-1.ld
@@ -0,0 +1,34 @@
+SECTIONS
+{
+	.text : {
+		. = . + 4;
+		*(.plt)
+	}
+	.test : {
+		*(.text)
+		*(.got)
+		*(.got.plt)
+		*(.rodata)
+		*(.eh_frame)
+		*(.interp)
+		*(.data)
+		*(.bss)
+	}
+
+	/* For old binutils which otherwise complain about nonrepresentable
+	   sections.  */
+	.dynsym : { *(.dynsym) }
+	.gnu.version : { *(.gnu.version) }
+
+	/DISCARD/ : {
+		*(.rela.text)
+		*(.rela.plt)
+		*(.rela.got.plt)
+		*(.rela.data)
+		*(.rela.rodata)
+		*(.rela.bss)
+		*(.rela.text)
+		*(.comment*)
+		*(.note*)
+	}
+}
diff --git a/ld/testsuite/ld-s390/pltoffset-1.s b/ld/testsuite/ld-s390/pltoffset-1.s
new file mode 100644
index 0000000..4c81523
--- /dev/null
+++ b/ld/testsuite/ld-s390/pltoffset-1.s
@@ -0,0 +1,12 @@
+	.file	"hello.c"
+.text
+	.align	8
+.globl main
+	.type	main, @function
+main:
+	brasl	%r5,foo@PLT
+	br	%r4
+	.size	main, .-main
+
+.globl foo
+foo:	.long	123
diff --git a/ld/testsuite/ld-s390/s390.exp b/ld/testsuite/ld-s390/s390.exp
index 4ca7b3c..2ef885a 100644
--- a/ld/testsuite/ld-s390/s390.exp
+++ b/ld/testsuite/ld-s390/s390.exp
@@ -74,6 +74,11 @@ set s390xtests {
      "-m64" {gotreloc-1.s}
      {{objdump -dzrj.text gotreloc_64-1.dd}}
      "gotreloc_64-1"}
+    {"PLT: offset test"
+     "-shared -m elf64_s390 -dT pltoffset-1.ld" ""
+     "-m64" {pltoffset-1.s}
+     {{objdump "-dzrj.text --stop-address=16" pltoffset-1.dd}}
+     "pltoffset-1"}
 }
 
 if [istarget "s390-*-*"] {
-- 
1.9.1


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