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.
This commit is contained in:
Jan Beulich
2025-02-21 10:25:41 +01:00
parent 11c2852449
commit 010a8fd409
3 changed files with 14 additions and 5 deletions

View File

@@ -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". */

View File

@@ -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

View File

@@ -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