]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
x86-64: further tighten convert-load-reloc checking
authorJan Beulich <jbeulich@suse.com>
Fri, 21 Feb 2025 09:25:41 +0000 (10:25 +0100)
committerJan Beulich <jbeulich@suse.com>
Fri, 21 Feb 2025 09:25:41 +0000 (10:25 +0100)
REX2.M affects what insn we're actually dealing with, so we better check
this to avoid transforming (future) insns we must not touch.

bfd/elf64-x86-64.c
ld/testsuite/ld-x86-64/load4.d
ld/testsuite/ld-x86-64/load4.s

index 3d68f97ad790e8496f0aba0952e0e676a0d6b3c4..1e08f2e7125424f6409bcfdaabcda8761e4f558a 100644 (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".  */
index 190205e8167d9dbf5526e15c5ad50f37d22bbdb2..fc9c0c6c1405eef4604e65edfe81a7cc2307aad3 100644 (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
index f3fa1b11b730a4ba313f8ca90d8c185792276890..ab6f668e9ed269f0da914e79fc8a05e49b376c7f 100644 (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