x86: prevent undue use of GOT32X and alike relocations
authorJan Beulich <jbeulich@suse.com>
Thu, 30 Jan 2020 16:03:22 +0000 (17:03 +0100)
committerJan Beulich <jbeulich@suse.com>
Thu, 30 Jan 2020 16:03:22 +0000 (17:03 +0100)
Comparison of i.tm.base_opcode against particular but not sufficiently
specific values needs to be accompanied by other qualification. Exclude
VEX and alike encodings here, and also exclude all forms of prefixes
explicitly specified in the opcodes table. While using @GOT with such
insns may not be very useful, it also isn't with e.g. ADC and SBB, yet
these get explicitly listed in comments as supported.

gas/ChangeLog
gas/config/tc-i386.c
gas/testsuite/gas/i386/got-no-relax.d
gas/testsuite/gas/i386/got.d
gas/testsuite/gas/i386/got.s

index ef3a47cd8c950f54dda7d6eef84b205737dd5a8f..8bad416a307dec3bcdcb98db614d730d4869f6b8 100644 (file)
@@ -1,3 +1,10 @@
+2020-01-30  Jan Beulich  <jbeulich@suse.com>
+
+       * config/tc-i386.c (output_disp): Tighten base_opcode check.
+       * testsuite/gas/i386/got.s: Add LSL, MOVLPS, and BNDCN cases.
+       * testsuite/gas/i386/got-no-relax.d, testsuite/gas/i386/got.d:
+       Adjust expectations.
+
 2020-01-30  Jose E. Marchesi  <jose.marchesi@oracle.com>
 
        * testsuite/gas/bpf/alu.d: Update expected opcode for `neg'.
index 4f102a3de3d1f5583a9125277a7d9fecb20b1857..945ceb28d69a9e34aa80a58a4c44bb4194dfc74f 100644 (file)
@@ -9061,13 +9061,14 @@ output_disp (fragS *insn_start_frag, offsetT insn_start_off)
                          && i.rm.regmem == 5))
                  && (i.rm.mode == 2
                      || (i.rm.mode == 0 && i.rm.regmem == 5))
+                 && !is_any_vex_encoding(&i.tm)
                  && ((i.operands == 1
                       && i.tm.base_opcode == 0xff
                       && (i.rm.reg == 2 || i.rm.reg == 4))
                      || (i.operands == 2
                          && (i.tm.base_opcode == 0x8b
                              || i.tm.base_opcode == 0x85
-                             || (i.tm.base_opcode & 0xc7) == 0x03))))
+                             || (i.tm.base_opcode & ~0x38) == 0x03))))
                {
                  if (object_64bit)
                    {
index 6bf138a5cb2aa75e7bb192da49eaf4dd90b8b597..41b4adfc4317f32f45f6bedd967a287f1b50517b 100644 (file)
@@ -14,18 +14,27 @@ Disassembly of section .text:
 [      ]*[a-f0-9]+:    05 00 00 00 00          add    \$0x0,%eax       12: R_386_GOT32 foo
 [      ]*[a-f0-9]+:    03 05 00 00 00 00       add    0x0,%eax 18: R_386_GOT32X        foo
 [      ]*[a-f0-9]+:    03 80 00 00 00 00       add    0x0\(%eax\),%eax 1e: R_386_GOT32 foo
-[      ]*[a-f0-9]+:    ff 15 00 00 00 00       call   \*0x0    24: R_386_GOT32X        foo
-[      ]*[a-f0-9]+:    ff 90 00 00 00 00       call   \*0x0\(%eax\)    2a: R_386_GOT32 foo
-[      ]*[a-f0-9]+:    ff 25 00 00 00 00       jmp    \*0x0    30: R_386_GOT32X        foo
-[      ]*[a-f0-9]+:    ff a0 00 00 00 00       jmp    \*0x0\(%eax\)    36: R_386_GOT32 foo
-[      ]*[a-f0-9]+:    b8 00 00 00 00          mov    \$0x0,%eax       3b: R_386_GOT32 foo
-[      ]*[a-f0-9]+:    8b 05 00 00 00 00       mov    0x0,%eax 41: R_386_GOT32X        foo
-[      ]*[a-f0-9]+:    8b 80 00 00 00 00       mov    0x0\(%eax\),%eax 47: R_386_GOT32 foo
-[      ]*[a-f0-9]+:    05 00 00 00 00          add    \$0x0,%eax       4c: R_386_GOT32 foo
-[      ]*[a-f0-9]+:    03 05 00 00 00 00       add    0x0,%eax 52: R_386_GOT32X        foo
-[      ]*[a-f0-9]+:    03 80 00 00 00 00       add    0x0\(%eax\),%eax 58: R_386_GOT32 foo
-[      ]*[a-f0-9]+:    ff 90 00 00 00 00       call   \*0x0\(%eax\)    5e: R_386_GOT32 foo
-[      ]*[a-f0-9]+:    ff 15 00 00 00 00       call   \*0x0    64: R_386_GOT32X        foo
-[      ]*[a-f0-9]+:    ff a0 00 00 00 00       jmp    \*0x0\(%eax\)    6a: R_386_GOT32 foo
-[      ]*[a-f0-9]+:    ff 25 00 00 00 00       jmp    \*0x0    70: R_386_GOT32X        foo
+[      ]*[a-f0-9]+:    a9 00 00 00 00          test   \$0x0,%eax       23: R_386_GOT32 foo
+[      ]*[a-f0-9]+:    85 05 00 00 00 00       test   %eax,0x0 29: R_386_GOT32X        foo
+[      ]*[a-f0-9]+:    85 80 00 00 00 00       test   %eax,0x0\(%eax\) 2f: R_386_GOT32 foo
+[      ]*[a-f0-9]+:    ff 15 00 00 00 00       call   \*0x0    35: R_386_GOT32X        foo
+[      ]*[a-f0-9]+:    ff 90 00 00 00 00       call   \*0x0\(%eax\)    3b: R_386_GOT32 foo
+[      ]*[a-f0-9]+:    ff 25 00 00 00 00       jmp    \*0x0    41: R_386_GOT32X        foo
+[      ]*[a-f0-9]+:    ff a0 00 00 00 00       jmp    \*0x0\(%eax\)    47: R_386_GOT32 foo
+[      ]*[a-f0-9]+:    0f 03 05 00 00 00 00    lsl    0x0,%eax 4e: R_386_GOT32 foo
+[      ]*[a-f0-9]+:    0f 03 80 00 00 00 00    lsl    0x0\(%eax\),%eax 55: R_386_GOT32 foo
+[      ]*[a-f0-9]+:    f2 0f 1b 05 00 00 00 00         bndcn  0x0,%bnd0        5d: R_386_GOT32 foo
+[      ]*[a-f0-9]+:    f2 0f 1b 80 00 00 00 00         bndcn  0x0\(%eax\),%bnd0        65: R_386_GOT32 foo
+[      ]*[a-f0-9]+:    0f 13 05 00 00 00 00    movlps %xmm0,0x0        6c: R_386_GOT32 foo
+[      ]*[a-f0-9]+:    0f 13 80 00 00 00 00    movlps %xmm0,0x0\(%eax\)        73: R_386_GOT32 foo
+[      ]*[a-f0-9]+:    b8 00 00 00 00          mov    \$0x0,%eax       78: R_386_GOT32 foo
+[      ]*[a-f0-9]+:    8b 05 00 00 00 00       mov    0x0,%eax 7e: R_386_GOT32X        foo
+[      ]*[a-f0-9]+:    8b 80 00 00 00 00       mov    0x0\(%eax\),%eax 84: R_386_GOT32 foo
+[      ]*[a-f0-9]+:    05 00 00 00 00          add    \$0x0,%eax       89: R_386_GOT32 foo
+[      ]*[a-f0-9]+:    03 05 00 00 00 00       add    0x0,%eax 8f: R_386_GOT32X        foo
+[      ]*[a-f0-9]+:    03 80 00 00 00 00       add    0x0\(%eax\),%eax 95: R_386_GOT32 foo
+[      ]*[a-f0-9]+:    ff 90 00 00 00 00       call   \*0x0\(%eax\)    9b: R_386_GOT32 foo
+[      ]*[a-f0-9]+:    ff 15 00 00 00 00       call   \*0x0    a1: R_386_GOT32X        foo
+[      ]*[a-f0-9]+:    ff a0 00 00 00 00       jmp    \*0x0\(%eax\)    a7: R_386_GOT32 foo
+[      ]*[a-f0-9]+:    ff 25 00 00 00 00       jmp    \*0x0    ad: R_386_GOT32X        foo
 #pass
index 7621cdf07008aaa9a69f205b08e81c582bdb34b7..351da27e046825ced95f6cde8470779529638621 100644 (file)
@@ -13,18 +13,27 @@ Disassembly of section .text:
 [      ]*[a-f0-9]+:    05 00 00 00 00          add    \$0x0,%eax       12: R_386_GOT32 foo
 [      ]*[a-f0-9]+:    03 05 00 00 00 00       add    0x0,%eax 18: R_386_GOT32X        foo
 [      ]*[a-f0-9]+:    03 80 00 00 00 00       add    0x0\(%eax\),%eax 1e: R_386_GOT32X        foo
-[      ]*[a-f0-9]+:    ff 15 00 00 00 00       call   \*0x0    24: R_386_GOT32X        foo
-[      ]*[a-f0-9]+:    ff 90 00 00 00 00       call   \*0x0\(%eax\)    2a: R_386_GOT32X        foo
-[      ]*[a-f0-9]+:    ff 25 00 00 00 00       jmp    \*0x0    30: R_386_GOT32X        foo
-[      ]*[a-f0-9]+:    ff a0 00 00 00 00       jmp    \*0x0\(%eax\)    36: R_386_GOT32X        foo
-[      ]*[a-f0-9]+:    b8 00 00 00 00          mov    \$0x0,%eax       3b: R_386_GOT32 foo
-[      ]*[a-f0-9]+:    8b 05 00 00 00 00       mov    0x0,%eax 41: R_386_GOT32X        foo
-[      ]*[a-f0-9]+:    8b 80 00 00 00 00       mov    0x0\(%eax\),%eax 47: R_386_GOT32X        foo
-[      ]*[a-f0-9]+:    05 00 00 00 00          add    \$0x0,%eax       4c: R_386_GOT32 foo
-[      ]*[a-f0-9]+:    03 05 00 00 00 00       add    0x0,%eax 52: R_386_GOT32X        foo
-[      ]*[a-f0-9]+:    03 80 00 00 00 00       add    0x0\(%eax\),%eax 58: R_386_GOT32X        foo
-[      ]*[a-f0-9]+:    ff 90 00 00 00 00       call   \*0x0\(%eax\)    5e: R_386_GOT32X        foo
-[      ]*[a-f0-9]+:    ff 15 00 00 00 00       call   \*0x0    64: R_386_GOT32X        foo
-[      ]*[a-f0-9]+:    ff a0 00 00 00 00       jmp    \*0x0\(%eax\)    6a: R_386_GOT32X        foo
-[      ]*[a-f0-9]+:    ff 25 00 00 00 00       jmp    \*0x0    70: R_386_GOT32X        foo
+[      ]*[a-f0-9]+:    a9 00 00 00 00          test   \$0x0,%eax       23: R_386_GOT32 foo
+[      ]*[a-f0-9]+:    85 05 00 00 00 00       test   %eax,0x0 29: R_386_GOT32X        foo
+[      ]*[a-f0-9]+:    85 80 00 00 00 00       test   %eax,0x0\(%eax\) 2f: R_386_GOT32X        foo
+[      ]*[a-f0-9]+:    ff 15 00 00 00 00       call   \*0x0    35: R_386_GOT32X        foo
+[      ]*[a-f0-9]+:    ff 90 00 00 00 00       call   \*0x0\(%eax\)    3b: R_386_GOT32X        foo
+[      ]*[a-f0-9]+:    ff 25 00 00 00 00       jmp    \*0x0    41: R_386_GOT32X        foo
+[      ]*[a-f0-9]+:    ff a0 00 00 00 00       jmp    \*0x0\(%eax\)    47: R_386_GOT32X        foo
+[      ]*[a-f0-9]+:    0f 03 05 00 00 00 00    lsl    0x0,%eax 4e: R_386_GOT32 foo
+[      ]*[a-f0-9]+:    0f 03 80 00 00 00 00    lsl    0x0\(%eax\),%eax 55: R_386_GOT32 foo
+[      ]*[a-f0-9]+:    f2 0f 1b 05 00 00 00 00         bndcn  0x0,%bnd0        5d: R_386_GOT32 foo
+[      ]*[a-f0-9]+:    f2 0f 1b 80 00 00 00 00         bndcn  0x0\(%eax\),%bnd0        65: R_386_GOT32 foo
+[      ]*[a-f0-9]+:    0f 13 05 00 00 00 00    movlps %xmm0,0x0        6c: R_386_GOT32 foo
+[      ]*[a-f0-9]+:    0f 13 80 00 00 00 00    movlps %xmm0,0x0\(%eax\)        73: R_386_GOT32 foo
+[      ]*[a-f0-9]+:    b8 00 00 00 00          mov    \$0x0,%eax       78: R_386_GOT32 foo
+[      ]*[a-f0-9]+:    8b 05 00 00 00 00       mov    0x0,%eax 7e: R_386_GOT32X        foo
+[      ]*[a-f0-9]+:    8b 80 00 00 00 00       mov    0x0\(%eax\),%eax 84: R_386_GOT32X        foo
+[      ]*[a-f0-9]+:    05 00 00 00 00          add    \$0x0,%eax       89: R_386_GOT32 foo
+[      ]*[a-f0-9]+:    03 05 00 00 00 00       add    0x0,%eax 8f: R_386_GOT32X        foo
+[      ]*[a-f0-9]+:    03 80 00 00 00 00       add    0x0\(%eax\),%eax 95: R_386_GOT32X        foo
+[      ]*[a-f0-9]+:    ff 90 00 00 00 00       call   \*0x0\(%eax\)    9b: R_386_GOT32X        foo
+[      ]*[a-f0-9]+:    ff 15 00 00 00 00       call   \*0x0    a1: R_386_GOT32X        foo
+[      ]*[a-f0-9]+:    ff a0 00 00 00 00       jmp    \*0x0\(%eax\)    a7: R_386_GOT32X        foo
+[      ]*[a-f0-9]+:    ff 25 00 00 00 00       jmp    \*0x0    ad: R_386_GOT32X        foo
 #pass
index 10fa881aa6f12d9dec70d2159007de39f79ca9b4..47194115bc88e084dadc3ed69a244877016d1a3d 100644 (file)
@@ -8,11 +8,24 @@ _start:
        addl    foo@GOT, %eax
        addl    foo@GOT(%eax), %eax
 
+       testl   $foo@GOT, %eax
+       testl   foo@GOT, %eax
+       testl   foo@GOT(%eax), %eax
+
        call    *foo@GOT
        call    *foo@GOT(%eax)
        jmp     *foo@GOT
        jmp     *foo@GOT(%eax)
 
+       lsll    foo@GOT, %eax
+       lsll    foo@GOT(%eax), %eax
+
+       bndcn   foo@GOT, %bnd0
+       bndcn   foo@GOT(%eax), %bnd0
+
+       movlps  %xmm0, foo@GOT
+       movlps  %xmm0, foo@GOT(%eax)
+
        .intel_syntax noprefix
 
        mov     eax, offset foo@got
This page took 0.03903 seconds and 4 git commands to generate.