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]

PATCH: PR gas/17598: R_X86_64_GOTPLT64 relocation isn't tested


Hi,

R_X86_64_GOTPLT64 isn't necessary and R_X86_64_GOT64 should be used
instead.  I checked in this patch to add assembler support for @gotplt,
but treat R_X86_64_GOTPLT64 the same R_X86_64_GOT64.  There should be
no impact on GCC since GCC never generates R_X86_64_GOTPLT64 and
R_X86_64_GOT64 is optimal anyway.


H.J.
---
bfd/

	PR gas/17598
	* elf64-x86-64.c (elf_x86_64_check_relocs): Treat
	R_X86_64_GOTPLT64 the same as R_X86_64_GOT64.
	(elf_x86_64_relocate_section): Likewise.

gas/

	PR gas/17598
	* config/tc-i386.c (reloc): Support BFD_RELOC_X86_64_GOTPLT64.

gas/testsuite/

	PR gas/17598
	* gas/i386/reloc64.s: Add @gotplt check.

	* gas/i386/reloc64.d: Updated.
	* gas/i386/reloc64.l: Likewise.

ld/testsuite/

	PR gas/17598
	* ld-x86-64/x86-64.exp: Run gotplt1.

	* ld-x86-64/gotplt1.d: New file.
	* ld-x86-64/gotplt1.s: Likewise.
---
 bfd/ChangeLog                     |  7 +++++++
 bfd/elf64-x86-64.c                | 17 +----------------
 gas/ChangeLog                     |  5 +++++
 gas/config/tc-i386.c              |  3 +++
 gas/testsuite/ChangeLog           |  8 ++++++++
 gas/testsuite/gas/i386/reloc64.d  |  2 ++
 gas/testsuite/gas/i386/reloc64.l  | 10 ++++++++++
 gas/testsuite/gas/i386/reloc64.s  | 16 ++++++++++++++++
 ld/testsuite/ChangeLog            |  8 ++++++++
 ld/testsuite/ld-x86-64/gotplt1.d  |  6 ++++++
 ld/testsuite/ld-x86-64/gotplt1.s  |  5 +++++
 ld/testsuite/ld-x86-64/x86-64.exp |  1 +
 12 files changed, 72 insertions(+), 16 deletions(-)
 create mode 100644 ld/testsuite/ld-x86-64/gotplt1.d
 create mode 100644 ld/testsuite/ld-x86-64/gotplt1.s

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 701540e..3cf91d1 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,10 @@
+2014-11-13  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR gas/17598
+	* elf64-x86-64.c (elf_x86_64_check_relocs): Treat
+	R_X86_64_GOTPLT64 the same as R_X86_64_GOT64.
+	(elf_x86_64_relocate_section): Likewise.
+
 2014-11-13  Nick Clifton  <nickc@redhat.com>
 
 	PR binutils/17512
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index d0ed8a7..f2b13e7 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -1752,14 +1752,6 @@ elf_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
 
 	    if (h != NULL)
 	      {
-		if (r_type == R_X86_64_GOTPLT64)
-		  {
-		    /* This relocation indicates that we also need
-		       a PLT entry, as this is a function.  We don't need
-		       a PLT entry for local symbols.  */
-		    h->needs_plt = 1;
-		    h->plt.refcount += 1;
-		  }
 		h->got.refcount += 1;
 		old_tls_type = elf_x86_64_hash_entry (h)->tls_type;
 	      }
@@ -2181,8 +2173,6 @@ elf_x86_64_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info,
 	case R_X86_64_GOTPLT64:
 	  if (h != NULL)
 	    {
-	      if (r_type == R_X86_64_GOTPLT64 && h->plt.refcount > 0)
-		h->plt.refcount -= 1;
 	      if (h->got.refcount > 0)
 		h->got.refcount -= 1;
 	      if (h->type == STT_GNU_IFUNC)
@@ -3720,12 +3710,7 @@ elf_x86_64_relocate_section (bfd *output_bfd,
 	case R_X86_64_GOTPCREL64:
 	  /* Use global offset table entry as symbol value.  */
 	case R_X86_64_GOTPLT64:
-	  /* This is the same as GOT64 for relocation purposes, but
-	     indicates the existence of a PLT entry.  The difficulty is,
-	     that we must calculate the GOT slot offset from the PLT
-	     offset, if this symbol got a PLT entry (it was global).
-	     Additionally if it's computed from the PLT entry, then that
-	     GOT offset is relative to .got.plt, not to .got.  */
+	  /* This is obsolete and treated the the same as GOT64.  */
 	  base_got = htab->elf.sgot;
 
 	  if (htab->elf.sgot == NULL)
diff --git a/gas/ChangeLog b/gas/ChangeLog
index e7248c4..e674476 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,8 @@
+2014-11-13  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR gas/17598
+	* config/tc-i386.c (reloc): Support BFD_RELOC_X86_64_GOTPLT64.
+
 2014-11-13  Nick Clifton  <nickc@redhat.com>
 
 	PR binutils/17512
diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c
index 51d58c1..f54f077 100644
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -2835,6 +2835,9 @@ reloc (unsigned int size,
 	  case BFD_RELOC_X86_64_GOT32:
 	    return BFD_RELOC_X86_64_GOT64;
 	    break;
+	  case BFD_RELOC_X86_64_GOTPLT64:
+	    return BFD_RELOC_X86_64_GOTPLT64;
+	    break;
 	  case BFD_RELOC_X86_64_PLTOFF64:
 	    return BFD_RELOC_X86_64_PLTOFF64;
 	    break;
diff --git a/gas/testsuite/ChangeLog b/gas/testsuite/ChangeLog
index 972b2e6..7908363 100644
--- a/gas/testsuite/ChangeLog
+++ b/gas/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2014-11-13  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR gas/17598
+	* gas/i386/reloc64.s: Add @gotplt check.
+
+	* gas/i386/reloc64.d: Updated.
+	* gas/i386/reloc64.l: Likewise.
+
 2014-11-07  H.J. Lu  <hongjiu.lu@intel.com>
 
 	PR ld/17482
diff --git a/gas/testsuite/gas/i386/reloc64.d b/gas/testsuite/gas/i386/reloc64.d
index 4491982..ea7f696 100644
--- a/gas/testsuite/gas/i386/reloc64.d
+++ b/gas/testsuite/gas/i386/reloc64.d
@@ -50,6 +50,7 @@ Disassembly of section \.text:
 .*[ 	]+R_X86_64_TPOFF32[ 	]+xtrn
 .*[ 	]+R_X86_64_TPOFF32[ 	]+xtrn
 .*[ 	]+R_X86_64_TPOFF32[ 	]+xtrn
+.*[ 	]+R_X86_64_GOTPLT64[ 	]+xtrn
 Disassembly of section \.data:
 #...
 .*[ 	]+R_X86_64_64[ 	]+xtrn
@@ -89,3 +90,4 @@ Disassembly of section \.data:
 .*[ 	]+R_X86_64_PC8[ 	]+xtrn
 .*[ 	]+R_X86_64_GOT32[ 	]+xtrn-0x4
 .*[ 	]+R_X86_64_GOT32[ 	]+xtrn\+0x4
+.*[ 	]+R_X86_64_GOTPLT64[ 	]+xtrn
diff --git a/gas/testsuite/gas/i386/reloc64.l b/gas/testsuite/gas/i386/reloc64.l
index ded5cab..5e970cb 100644
--- a/gas/testsuite/gas/i386/reloc64.l
+++ b/gas/testsuite/gas/i386/reloc64.l
@@ -71,3 +71,13 @@
 .*:195: Error: .*
 .*:196: Error: .*
 .*:197: Error: .*
+.*:208: Error: .*
+.*:209: Error: .*
+.*:210: Error: .*
+.*:211: Error: .*
+.*:212: Error: .*
+.*:213: Error: .*
+.*:214: Error: .*
+.*:218: Error: .*
+.*:219: Error: .*
+.*:220: Error: .*
diff --git a/gas/testsuite/gas/i386/reloc64.s b/gas/testsuite/gas/i386/reloc64.s
index 7b35a02..ecaaef5 100644
--- a/gas/testsuite/gas/i386/reloc64.s
+++ b/gas/testsuite/gas/i386/reloc64.s
@@ -202,3 +202,19 @@ bad	.byte	xtrn@tpoff
 	.data
 	.long	xtrn@got - 4
 	.long	xtrn@got + 4
+
+	.text
+	movabs	$xtrn@gotplt, %rax
+bad	add	$xtrn@gotplt, %rax
+bad	mov	$xtrn@gotplt, %eax
+bad	mov	$xtrn@gotplt, %ax
+bad	mov	$xtrn@gotplt, %al
+bad	mov	xtrn@gotplt(%rbx), %eax
+bad	mov	xtrn@gotplt(%ebx), %eax
+bad	call	xtrn@gotplt
+
+	.data
+	.quad	xtrn@gotplt
+bad	.long	xtrn@gotplt
+bad	.word	xtrn@gotplt
+bad	.byte	xtrn@gotplt
diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index dddada5..4d78aab 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2014-11-13  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR gas/17598
+	* ld-x86-64/x86-64.exp: Run gotplt1.
+
+	* ld-x86-64/gotplt1.d: New file.
+	* ld-x86-64/gotplt1.s: Likewise.
+
 2014-11-11  Jiong Wang <jiong.wang@arm.com>
 
 	* lib/ld-lib.exp (run_ld_link_exec_tests): Append board_cflags if gcc
diff --git a/ld/testsuite/ld-x86-64/gotplt1.d b/ld/testsuite/ld-x86-64/gotplt1.d
new file mode 100644
index 0000000..f2ee245
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/gotplt1.d
@@ -0,0 +1,6 @@
+#as: --64
+#ld: -shared -melf_x86_64
+#readelf: -r --wide
+
+#...
+[0-9a-f]+ +[0-9a-f]+ +R_X86_64_GLOB_DAT +[0-9a-f]+ +foo \+ 0
diff --git a/ld/testsuite/ld-x86-64/gotplt1.s b/ld/testsuite/ld-x86-64/gotplt1.s
new file mode 100644
index 0000000..0675843
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/gotplt1.s
@@ -0,0 +1,5 @@
+	.globl _start
+	.type	_start, @function
+_start:
+	movabsq	$foo@GOTPLT, %rax
+	.size	_start, .-_start
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
index 54786a7..a9b68ff 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -227,6 +227,7 @@ run_dump_test "pr12570a"
 run_dump_test "pr12570b"
 run_dump_test "pr14215"
 run_dump_test "pr14207"
+run_dump_test "gotplt1"
 
 if { ![istarget "x86_64-*-linux*"] && ![istarget "x86_64-*-nacl*"]} {
     return
-- 
1.9.3


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