[binutils-gdb] x86-64: further tighten convert-load-reloc checking

Jan Beulich jbeulich@sourceware.org
Fri Feb 21 09:27:18 GMT 2025


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

commit 010a8fd40903ffffac30a15a56b9477b395c8817
Author: Jan Beulich <jbeulich@suse.com>
Date:   Fri Feb 21 10:25:41 2025 +0100

    x86-64: further tighten convert-load-reloc checking
    
    REX2.M affects what insn we're actually dealing with, so we better check
    this to avoid transforming (future) insns we must not touch.

Diff:
---
 bfd/elf64-x86-64.c             | 4 ++--
 ld/testsuite/ld-x86-64/load4.d | 9 ++++++---
 ld/testsuite/ld-x86-64/load4.s | 6 ++++++
 3 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 3d68f97ad79..1e08f2e7125 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -2354,14 +2354,14 @@ elf_x86_64_convert_load_reloc (bfd *abfd,
 	  if (to_reloc_pc32)
 	    return true;
 
-	  if (opcode == 0x85)
+	  if (opcode == 0x85 && !(rex2 & (REX2_M << 4)))
 	    {
 	      /* Convert "test %reg, foo@GOTPCREL(%rip)" to
 		 "test $foo, %reg".  */
 	      modrm = 0xc0 | (modrm & 0x38) >> 3;
 	      opcode = 0xf7;
 	    }
-	  else if ((opcode | 0x38) == 0x3b)
+	  else if ((opcode | 0x38) == 0x3b && !(rex2 & (REX2_M << 4)))
 	    {
 	      /* Convert "binop foo@GOTPCREL(%rip), %reg" to
 		 "binop $foo, %reg".  */
diff --git a/ld/testsuite/ld-x86-64/load4.d b/ld/testsuite/ld-x86-64/load4.d
index 190205e8167..fc9c0c6c140 100644
--- a/ld/testsuite/ld-x86-64/load4.d
+++ b/ld/testsuite/ld-x86-64/load4.d
@@ -7,7 +7,10 @@
 Disassembly of section .text:
 
 0+4000b0 <_start>:
-[ 	]*[a-f0-9]+:	12 05 ([0-9a-f]{2} ){4} *	adc    0x[a-f0-9]+\(%rip\),%al        # 6000c8 <.*>
-[ 	]*[a-f0-9]+:	44 84 3d ([0-9a-f]{2} ){4} *	test   %r15b,0x[a-f0-9]+\(%rip\)        # 6000c8 <.*>
-[ 	]*[a-f0-9]+:	48 87 05 ([0-9a-f]{2} ){4} *	xchg   %rax,0x[a-f0-9]+\(%rip\)        # 6000c8 <.*>
+[ 	]*[a-f0-9]+:	12 05 ([0-9a-f]{2} ){4} *	adc    0x[a-f0-9]+\(%rip\),%al        # 6000e0 <.*>
+[ 	]*[a-f0-9]+:	44 84 3d ([0-9a-f]{2} ){4} *	test   %r15b,0x[a-f0-9]+\(%rip\)        # 6000e0 <.*>
+[ 	]*[a-f0-9]+:	48 87 05 ([0-9a-f]{2} ){4} *	xchg   %rax,0x[a-f0-9]+\(%rip\)        # 6000e0 <.*>
+[ 	]*[a-f0-9]+:	d5 c0 03 05 ([0-9a-f]{2} ){4} *	lsl    0x[a-f0-9]+\(%rip\),%r16d        # 6000e0 <.*>
+[ 	]*[a-f0-9]+:	d5 80 13 05 ([0-9a-f]{2} ){4} *	\{rex2 0x80\} movlps %xmm0,0x[a-f0-9]+\(%rip\)        # 6000e0 <.*>
+[ 	]*[a-f0-9]+:	d5 80 2b 05 ([0-9a-f]{2} ){4} *	\{rex2 0x80\} movntps %xmm0,0x[a-f0-9]+\(%rip\)        # 6000e0 <.*>
 #pass
diff --git a/ld/testsuite/ld-x86-64/load4.s b/ld/testsuite/ld-x86-64/load4.s
index f3fa1b11b73..ab6f668e9ed 100644
--- a/ld/testsuite/ld-x86-64/load4.s
+++ b/ld/testsuite/ld-x86-64/load4.s
@@ -19,5 +19,11 @@ _start:
 1:	.reloc .-4, R_X86_64_REX_GOTPCRELX, bar-4
 	xchg	1f(%rip), %rax
 1:	.reloc .-4, R_X86_64_REX_GOTPCRELX, bar-4
+	lsl	1f(%rip), %r16d
+1:	.reloc .-4, R_X86_64_CODE_4_GOTPCRELX, bar-4
+	{rex2} movlps %xmm0, 1f(%rip)
+1:	.reloc .-4, R_X86_64_CODE_4_GOTPCRELX, bar-4
+	{rex2} movntps %xmm0, 1f(%rip)
+1:	.reloc .-4, R_X86_64_CODE_4_GOTPCRELX, bar-4
 
 	.size	_start, .-_start


More information about the Binutils-cvs mailing list