[PATCH 2/4] x86-64: avoid bogus warnings with 32-bit addressing
Jan Beulich
jbeulich@suse.com
Mon Jun 7 12:40:22 GMT 2021
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/
2021-06-XX 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.
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -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)
--- a/gas/testsuite/gas/i386/i386.exp
+++ b/gas/testsuite/gas/i386/i386.exp
@@ -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"
--- a/gas/testsuite/gas/i386/lea16-optimize.d
+++ b/gas/testsuite/gas/i386/lea16-optimize.d
@@ -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
--- /dev/null
+++ b/gas/testsuite/gas/i386/lea16.d
@@ -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]+:[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+:[ ]+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
--- a/gas/testsuite/gas/i386/lea16.s
+++ b/gas/testsuite/gas/i386/lea16.s
@@ -5,3 +5,6 @@
.endm
.include "lea.s"
+
+ lea 0xffff(%bx), %ax
+ lea -0xffff(%bx), %ax
--- a/gas/testsuite/gas/i386/lea64-optimize.d
+++ b/gas/testsuite/gas/i386/lea64-optimize.d
@@ -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
--- a/gas/testsuite/gas/i386/lea64.d
+++ b/gas/testsuite/gas/i386/lea64.d
@@ -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
--- a/gas/testsuite/gas/i386/lea64.s
+++ b/gas/testsuite/gas/i386/lea64.s
@@ -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
More information about the Binutils
mailing list