summaryrefslogtreecommitdiff
path: root/gas
diff options
context:
space:
mode:
authorJan Beulich <jbeulich@suse.com>2021-06-08 14:55:56 +0200
committerJan Beulich <jbeulich@suse.com>2021-06-08 14:55:56 +0200
commit77c59789070949a1cfbd19578c6935ccd57869c2 (patch)
tree283571b167bf04fce848bd7e472f0ceea993f3ed /gas
parentf185acddfa246009e72e5bea95cd457ccc0cc763 (diff)
downloadbinutils-gdb-77c59789070949a1cfbd19578c6935ccd57869c2.tar.gz
x86-64: avoid bogus warnings with 32-bit addressing
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.
Diffstat (limited to 'gas')
-rw-r--r--gas/ChangeLog11
-rw-r--r--gas/config/tc-i386.c2
-rw-r--r--gas/testsuite/gas/i386/i386.exp1
-rw-r--r--gas/testsuite/gas/i386/lea16-optimize.d2
-rw-r--r--gas/testsuite/gas/i386/lea16.d50
-rw-r--r--gas/testsuite/gas/i386/lea16.s3
-rw-r--r--gas/testsuite/gas/i386/lea64-optimize.d6
-rw-r--r--gas/testsuite/gas/i386/lea64.d6
-rw-r--r--gas/testsuite/gas/i386/lea64.s8
9 files changed, 89 insertions, 0 deletions
diff --git a/gas/ChangeLog b/gas/ChangeLog
index 5926ffffc3c..e2084f89cdb 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,5 +1,16 @@
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.
Re-order.
diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c
index 9dbe6dcd954..249f1c36678 100644
--- 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)
diff --git a/gas/testsuite/gas/i386/i386.exp b/gas/testsuite/gas/i386/i386.exp
index db52df4152f..ff88bae92b2 100644
--- 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"
diff --git a/gas/testsuite/gas/i386/lea16-optimize.d b/gas/testsuite/gas/i386/lea16-optimize.d
index e45b7377207..3c43b6c9438 100644
--- 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
diff --git a/gas/testsuite/gas/i386/lea16.d b/gas/testsuite/gas/i386/lea16.d
new file mode 100644
index 00000000000..179102adb09
--- /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]+:[ ]+67 66 8d 08[ ]+lea[ ]+\(%eax\),%ecx
+[ ]*[0-9a-f]+:[ ]+67 66 8d 08[ ]+lea[ ]+\(%eax\),%ecx
+[ ]*[0-9a-f]+:[ ]+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,%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
diff --git a/gas/testsuite/gas/i386/lea16.s b/gas/testsuite/gas/i386/lea16.s
index 024a4e9c457..f48b05d714e 100644
--- 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
diff --git a/gas/testsuite/gas/i386/lea64-optimize.d b/gas/testsuite/gas/i386/lea64-optimize.d
index 9d1c27da608..75e21ddad1c 100644
--- 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
diff --git a/gas/testsuite/gas/i386/lea64.d b/gas/testsuite/gas/i386/lea64.d
index e5b3f0647f7..8bf2becc4b5 100644
--- 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
diff --git a/gas/testsuite/gas/i386/lea64.s b/gas/testsuite/gas/i386/lea64.s
index 1778adc4851..5c20062b9fd 100644
--- 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