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-64: Clear the R_X86_64_converted_reloc_bit bit


We need to clear the R_X86_64_converted_reloc_bit bit after setting it
to avoid leaking it out by --emit-relocs.

I will backport it to 2.30 branch.


H.J.
---
bfd/

	PR ld/23324
	* elf64-x86-64.c (elf_x86_64_relocate_section): Clear the
	R_X86_64_converted_reloc_bit bit.

ld/

	PR ld/23324
	* testsuite/ld-x86-64/pr23324.s: New file.
	* testsuite/ld-x86-64/pr23324a.d: Likewise.
	* testsuite/ld-x86-64/pr23324b.d: Likewise.
---
 bfd/ChangeLog                     | 6 ++++++
 bfd/elf64-x86-64.c                | 8 ++++++--
 ld/ChangeLog                      | 7 +++++++
 ld/testsuite/ld-x86-64/pr23324.s  | 6 ++++++
 ld/testsuite/ld-x86-64/pr23324a.d | 8 ++++++++
 ld/testsuite/ld-x86-64/pr23324b.d | 8 ++++++++
 ld/testsuite/ld-x86-64/x86-64.exp | 2 ++
 7 files changed, 43 insertions(+), 2 deletions(-)
 create mode 100644 ld/testsuite/ld-x86-64/pr23324.s
 create mode 100644 ld/testsuite/ld-x86-64/pr23324a.d
 create mode 100644 ld/testsuite/ld-x86-64/pr23324b.d

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index a7d8ce7e30..5fc2feccfa 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2018-07-02  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR ld/23324
+	* elf64-x86-64.c (elf_x86_64_relocate_section): Clear the
+	R_X86_64_converted_reloc_bit bit.
+
 2018-07-02  Jeff Muizelaar  <jrmuizel@gmail.com>
 	    Tom Tromey  <tom@tromey.com>
 
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 4349561f3c..c3a6c31ed2 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -2431,8 +2431,13 @@ elf_x86_64_relocate_section (bfd *output_bfd,
 	  continue;
 	}
 
+      r_symndx = htab->r_sym (rel->r_info);
       converted_reloc = (r_type & R_X86_64_converted_reloc_bit) != 0;
-      r_type &= ~R_X86_64_converted_reloc_bit;
+      if (converted_reloc)
+	{
+	  r_type &= ~R_X86_64_converted_reloc_bit;
+	  rel->r_info = htab->r_info (r_symndx, r_type);
+	}
 
       if (r_type >= (int) R_X86_64_standard)
 	return _bfd_unrecognized_reloc (input_bfd, input_section, r_type);
@@ -2443,7 +2448,6 @@ elf_x86_64_relocate_section (bfd *output_bfd,
       else
 	howto = (x86_64_elf_howto_table
 		 + ARRAY_SIZE (x86_64_elf_howto_table) - 1);
-      r_symndx = htab->r_sym (rel->r_info);
       h = NULL;
       sym = NULL;
       sec = NULL;
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 31959a73d8..afa9ae83b2 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,10 @@
+2018-07-02  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR ld/23324
+	* testsuite/ld-x86-64/pr23324.s: New file.
+	* testsuite/ld-x86-64/pr23324a.d: Likewise.
+	* testsuite/ld-x86-64/pr23324b.d: Likewise.
+
 2018-07-02  Thomas Preud'homme  <thomas.preudhomme@arm.com>
 
 	* arm-dis.c (select_arm_features): Fix typo in heading comment.  Allow
diff --git a/ld/testsuite/ld-x86-64/pr23324.s b/ld/testsuite/ld-x86-64/pr23324.s
new file mode 100644
index 0000000000..3bad019245
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr23324.s
@@ -0,0 +1,6 @@
+	.text
+	.globl	_start
+	.type	_start,@function
+_start:
+	movq	_start@GOTPCREL(%rip), %rsi
+	ret
diff --git a/ld/testsuite/ld-x86-64/pr23324a.d b/ld/testsuite/ld-x86-64/pr23324a.d
new file mode 100644
index 0000000000..72a474289c
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr23324a.d
@@ -0,0 +1,8 @@
+#source: pr23324.s
+#as: --64 -mrelax-relocations=yes
+#ld: -q -melf_x86_64 -pie
+#readelf: -r --wide
+
+Relocation section '.rela.text' at offset 0x[0-9a-f]+ contains 1 entry:
+ +Offset +Info +Type +Sym.* Value +Symbol's Name \+ Addend
+[0-9a-f]+ +[0-9a-f]+ +R_X86_64_PC32 +[0-9a-f]+ +_start - 4
diff --git a/ld/testsuite/ld-x86-64/pr23324b.d b/ld/testsuite/ld-x86-64/pr23324b.d
new file mode 100644
index 0000000000..ad58d8678d
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr23324b.d
@@ -0,0 +1,8 @@
+#source: pr23324.s
+#as: --x32 -mrelax-relocations=yes
+#ld: -q -melf32_x86_64 -pie
+#readelf: -r --wide
+
+Relocation section '.rela.text' at offset 0x[0-9a-f]+ contains 1 entry:
+ +Offset +Info +Type +Sym.* Value +Symbol's Name \+ Addend
+[0-9a-f]+ +[0-9a-f]+ +R_X86_64_PC32 +[0-9a-f]+ +_start - 4
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
index d07054ca4c..e6ec049994 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -397,6 +397,8 @@ run_dump_test "pr22782a"
 run_dump_test "pr22782b"
 run_dump_test "pr23189"
 run_dump_test "pr23194"
+run_dump_test "pr23324a"
+run_dump_test "pr23324b"
 
 if { ![istarget "x86_64-*-linux*"] && ![istarget "x86_64-*-nacl*"]} {
     return
-- 
2.17.1


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