]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
x86-64: avoid bogus warnings with 32-bit addressing
authorJan Beulich <jbeulich@suse.com>
Tue, 8 Jun 2021 12:55:56 +0000 (14:55 +0200)
committerJan Beulich <jbeulich@suse.com>
Tue, 8 Jun 2021 12:55:56 +0000 (14:55 +0200)
With optimize_disp() adjusting i.types[].bitfield.disp after adjusting
the value to be used as displacement, it better also stores the updated
value, to avoid subsequent "... shortened to ..." warnings. Note how
optimize_imm() already does so.

The -0xffffffff tests being added expose a separate issue: The encoding
chosen should be 1 for ModR/M.mod, not 2. This will want to be taken
care of, but not right here.

This at the same time addresses a similar warning and demonstrates a
similar encoding issue with 16-bit addressing. Since it was omitted
when introducing the lea16-optimize test, add a plain lea16 one to also
cover this.

gas/ChangeLog
gas/config/tc-i386.c
gas/testsuite/gas/i386/i386.exp
gas/testsuite/gas/i386/lea16-optimize.d
gas/testsuite/gas/i386/lea16.d [new file with mode: 0644]
gas/testsuite/gas/i386/lea16.s
gas/testsuite/gas/i386/lea64-optimize.d
gas/testsuite/gas/i386/lea64.d
gas/testsuite/gas/i386/lea64.s

index 5926ffffc3c82909be614f172253753858b3bedd..e2084f89cdb168f6b94e397d3915380d4fbd45a9 100644 (file)
@@ -1,3 +1,14 @@
+2021-06-08  Jan Beulich  <jbeulich@suse.com>
+
+       * config/tc-i386.c (optimize_disp): Write back updated value.
+       * testsuite/gas/i386/lea16.s, testsuite/gas/i386/lea64.s: New
+       cases.
+       * testsuite/gas/i386/lea16-optimize.d,
+       testsuite/gas/i386/lea64.d, testsuite/gas/i386/lea64-optimize.d:
+       Adjust expectations.
+       * testsuite/gas/i386/lea16.d: New.
+       * testsuite/gas/i386/i386.exp: Run new test.
+
 2021-06-08  Jan Beulich  <jbeulich@suse.com>
 
        * config/tc-i386.c (optimize_disp): Drop redundant masking.
index 9dbe6dcd954f90d0948092b5da43c50b7074327a..249f1c366781541385bdc63b36584deb3d934a03 100644 (file)
@@ -5932,6 +5932,8 @@ optimize_disp (void)
                 || i.types[op].bitfield.disp16)
                && fits_in_disp8 (op_disp))
              i.types[op].bitfield.disp8 = 1;
+
+           i.op[op].disps->X_add_number = op_disp;
          }
        else if (i.reloc[op] == BFD_RELOC_386_TLS_DESC_CALL
                 || i.reloc[op] == BFD_RELOC_X86_64_TLSDESC_CALL)
index db52df4152f4e4857d547554ffbb83597c8fc9ac..ff88bae92b2d0d01e2eb22f41a34b16ad328d825 100644 (file)
@@ -69,6 +69,7 @@ if [gas_32_check] then {
     run_dump_test "prefix"
     run_list_test "prefix32" "-al"
     run_dump_test "lea"
+    run_dump_test "lea16"
     run_dump_test "amd"
     run_dump_test "katmai"
     run_dump_test "jump"
index e45b73772071e6766a6a1934e45d4d6a52180efa..3c43b6c94386a6e643d7163b054180ecd66d0fad 100644 (file)
@@ -45,4 +45,6 @@ Disassembly of section .text:
 [      ]*[0-9a-f]+:[   ]+67 8d 05 00 00 00 00[         ]+addr32 lea[   ]+0x0,%ax
 [      ]*[0-9a-f]+:[   ]+66 b8 00 00 00 00[    ]+mov[  ]+\$0x0,%eax
 [      ]*[0-9a-f]+:[   ]+b8 00 00[     ]+mov[  ]+\$0x0,%ax
+[      ]*[0-9a-f]+:[   ]+8d 47 ff[     ]+lea[  ]+-0x1\(%bx\),%ax
+[      ]*[0-9a-f]+:[   ]+8d 87 01 00[  ]+lea[  ]+0x1\(%bx\),%ax
 #pass
diff --git a/gas/testsuite/gas/i386/lea16.d b/gas/testsuite/gas/i386/lea16.d
new file mode 100644 (file)
index 0000000..179102a
--- /dev/null
@@ -0,0 +1,50 @@
+#as: -I${srcdir}/$subdir
+#objdump: -dw -Mi8086
+#name: i386 16-bit LEA
+#warning_output: lea.e
+
+.*: +file format .*
+
+Disassembly of section .text:
+
+0+ <start>:
+[      ]*[0-9a-f]+:[   ]+36 67 66 8d 04 08[    ]+lea[  ]+%ss:\(%eax,%ecx(,1)?\),%eax
+[      ]*[0-9a-f]+:[   ]+36 67 66 8d 04 08[    ]+lea[  ]+%ss:\(%eax,%ecx(,1)?\),%eax
+[      ]*[0-9a-f]+:[   ]+67 66 8d 48 01[       ]+lea[  ]+0x1\(%eax\),%ecx
+[      ]*[0-9a-f]+:[   ]+67 66 8d 88 00 00 00 00[      ]+lea[  ]+0x0\(%eax\),%ecx
+[      ]*[0-9a-f]+:[   ]+67 66 8d 0c 25 00 00 00 00[   ]+addr32 lea[   ]+0x0,%ecx
+[      ]*[0-9a-f]+:[   ]+67 66 8d 04 00[       ]+lea[  ]+\(%eax,%eax(,1)?\),%eax
+[      ]*[0-9a-f]+:[   ]+67 66 8d 04 45 00 00 00 00[   ]+lea[  ]+0x0\(,%eax,2\),%eax
+[      ]*[0-9a-f]+:[   ]+67 66 8d 04 25 00 00 00 00[   ]+addr32 lea[   ]+0x0,%eax
+[      ]*[0-9a-f]+:[   ]+66 8d 00[     ]+lea[  ]+\(%bx,%si\),%eax
+[      ]*[0-9a-f]+:[   ]+67 66 8d 00[  ]+lea[  ]+\(%eax\),%eax
+[      ]*[0-9a-f]+:[   ]+67 66 8d 08[  ]+lea[  ]+\(%eax\),%ecx
+[      ]*[0-9a-f]+:[   ]+67 66 8d 08[  ]+lea[  ]+\(%eax\),%ecx
+[      ]*[0-9a-f]+:[   ]+65 67 66 8d 08[       ]+lea[  ]+%gs:\(%eax\),%ecx
+[      ]*[0-9a-f]+:[   ]+66 8d 04[     ]+lea[  ]+\(%si\),%eax
+[      ]*[0-9a-f]+:[   ]+66 8d 34[     ]+lea[  ]+\(%si\),%esi
+[      ]*[0-9a-f]+:[   ]+66 8d 04[     ]+lea[  ]+\(%si\),%eax
+[      ]*[0-9a-f]+:[   ]+67 8d 00[     ]+lea[  ]+\(%eax\),%ax
+[      ]*[0-9a-f]+:[   ]+67 8d 08[     ]+lea[  ]+\(%eax\),%cx
+[      ]*[0-9a-f]+:[   ]+67 8d 08[     ]+lea[  ]+\(%eax\),%cx
+[      ]*[0-9a-f]+:[   ]+8d 04[        ]+lea[  ]+\(%si\),%ax
+[      ]*[0-9a-f]+:[   ]+8d 34[        ]+lea[  ]+\(%si\),%si
+[      ]*[0-9a-f]+:[   ]+67 66 8d 0c 0d 00 00 00 00[   ]+lea[  ]+0x0\(,%ecx(,1)?\),%ecx
+[      ]*[0-9a-f]+:[   ]+67 66 8d 04 0d 00 00 00 00[   ]+lea[  ]+0x0\(,%ecx(,1)?\),%eax
+[      ]*[0-9a-f]+:[   ]+66 8d 06 01 00[       ]+lea[  ]+0x1,%eax
+[      ]*[0-9a-f]+:[   ]+8d 06 02 00[  ]+lea[  ]+0x2,%ax
+[      ]*[0-9a-f]+:[   ]+66 8d 06 ff ff[       ]+lea[  ]+-0x1,%eax
+[      ]*[0-9a-f]+:[   ]+8d 06 fe ff[  ]+lea[  ]+-0x2,%ax
+[      ]*[0-9a-f]+:[   ]+67 66 8d 05 01 00 00 00[      ]+addr32 lea[   ]+0x1,%eax
+[      ]*[0-9a-f]+:[   ]+67 8d 05 02 00 00 00[         ]+addr32 lea[   ]+0x2,%ax
+[      ]*[0-9a-f]+:[   ]+67 66 8d 05 ff ff ff ff[      ]+addr32 lea[   ]+0xffffffff,%eax
+[      ]*[0-9a-f]+:[   ]+67 8d 05 fe ff ff ff[         ]+addr32 lea[   ]+0xfffffffe,%ax
+[      ]*[0-9a-f]+:[   ]+66 8d 06 00 00[       ]+lea[  ]+0x0,%eax
+[      ]*[0-9a-f]+:[   ]+8d 06 00 00[  ]+lea[  ]+0x0,%ax
+[      ]*[0-9a-f]+:[   ]+67 66 8d 05 00 00 00 00[      ]+addr32 lea[   ]+0x0,%eax
+[      ]*[0-9a-f]+:[   ]+67 8d 05 00 00 00 00[         ]+addr32 lea[   ]+0x0,%ax
+[      ]*[0-9a-f]+:[   ]+66 8d 06 00 00[       ]+lea[  ]+0x0,%eax
+[      ]*[0-9a-f]+:[   ]+8d 06 00 00[  ]+lea[  ]+0x0,%ax
+[      ]*[0-9a-f]+:[   ]+8d 47 ff[     ]+lea[  ]+-0x1\(%bx\),%ax
+[      ]*[0-9a-f]+:[   ]+8d 87 01 00[  ]+lea[  ]+0x1\(%bx\),%ax
+#pass
index 024a4e9c457f2e6eb2e547880da32ac6f47c966b..f48b05d714e70b875095a06f6317ea0477d675fd 100644 (file)
@@ -5,3 +5,6 @@
        .endm
 
        .include "lea.s"
+
+       lea     0xffff(%bx), %ax
+       lea     -0xffff(%bx), %ax
index 9d1c27da6089d0e92f0c86b10d60ccd21b836375..75e21ddad1c6a331b7576791446478d33eb3bc95 100644 (file)
@@ -68,4 +68,10 @@ Disassembly of section .text:
 [      ]*[0-9a-f]+:[   ]+48 c7 c0 00 00 00 00[         ]+mov[  ]+\$0x0,%rax
 [      ]*[0-9a-f]+:[   ]+b8 00 00 00 00[       ]+mov[  ]+\$0x0,%eax
 [      ]*[0-9a-f]+:[   ]+66 b8 00 00[  ]+mov[  ]+\$0x0,%ax
+[      ]*[0-9a-f]+:[   ]+8d 41 ff[     ]+lea[  ]+-0x1\(%rcx\),%eax
+[      ]*[0-9a-f]+:[   ]+8d 41 ff[     ]+lea[  ]+-0x1\(%rcx\),%eax
+[      ]*[0-9a-f]+:[   ]+8d 41 ff[     ]+lea[  ]+-0x1\(%rcx\),%eax
+[      ]*[0-9a-f]+:[   ]+8d 81 01 00 00 00[    ]+lea[  ]+0x1\(%rcx\),%eax
+[      ]*[0-9a-f]+:[   ]+8d 81 01 00 00 00[    ]+lea[  ]+0x1\(%rcx\),%eax
+[      ]*[0-9a-f]+:[   ]+8d 81 01 00 00 00[    ]+lea[  ]+0x1\(%rcx\),%eax
 #pass
index e5b3f0647f7b62532944365c7f87b49c189103bc..8bf2becc4b56c05bc0bab67ad89ced0259974ae2 100644 (file)
@@ -67,4 +67,10 @@ Disassembly of section .text:
 [      ]*[0-9a-f]+:[   ]+48 8d 04 25 00 00 00 00[      ]+lea[  ]+0x0,%rax
 [      ]*[0-9a-f]+:[   ]+8d 04 25 00 00 00 00[         ]+lea[  ]+0x0,%eax
 [      ]*[0-9a-f]+:[   ]+66 8d 04 25 00 00 00 00[      ]+lea[  ]+0x0,%ax
+[      ]*[0-9a-f]+:[   ]+67 8d 41 ff[  ]+lea[  ]+-0x1\(%ecx\),%eax
+[      ]*[0-9a-f]+:[   ]+67 48 8d 41 ff[       ]+lea[  ]+-0x1\(%ecx\),%rax
+[      ]*[0-9a-f]+:[   ]+8d 41 ff[     ]+lea[  ]+-0x1\(%rcx\),%eax
+[      ]*[0-9a-f]+:[   ]+67 8d 81 01 00 00 00[         ]+lea[  ]+0x1\(%ecx\),%eax
+[      ]*[0-9a-f]+:[   ]+67 48 8d 81 01 00 00 00[      ]+lea[  ]+0x1\(%ecx\),%rax
+[      ]*[0-9a-f]+:[   ]+8d 81 01 00 00 00[    ]+lea[  ]+0x1\(%rcx\),%eax
 #pass
index 1778adc4851b5acbec8734082e620aeba384cfca..5c20062b9fde7ba28b4fdbb1331f5a11108aebb0 100644 (file)
@@ -82,3 +82,11 @@ start:
        lea     (,1), %rax
        lea     (,1), %eax
        lea     (,1), %ax
+
+       lea     0xffffffff(%ecx), %eax
+       lea     0xffffffff(%ecx), %rax
+       lea     0xffffffff(%rcx), %eax
+
+       lea     -0xffffffff(%ecx), %eax
+       lea     -0xffffffff(%ecx), %rax
+       lea     -0xffffffff(%rcx), %eax