x86-64: have value properly checked when resolving fixup
authorJan Beulich <jbeulich@suse.com>
Mon, 26 Apr 2021 08:35:51 +0000 (10:35 +0200)
committerJan Beulich <jbeulich@suse.com>
Mon, 26 Apr 2021 08:35:51 +0000 (10:35 +0200)
Constants not known at the time an individual insn gets assembled and
going into a sign-extended field still shouldn't be silently truncated
at the time the respective fixup gets resolved.

gas/ChangeLog
gas/config/tc-i386.c
gas/testsuite/gas/i386/i386.exp
gas/testsuite/gas/i386/x86-64-addr32-bad.l [new file with mode: 0644]
gas/testsuite/gas/i386/x86-64-addr32-bad.s [new file with mode: 0644]

index 696d728d8c7df753e5f3ece688c776259f634aaf..585c98b25210b773a127e8f635fe7dfc1604b65d 100644 (file)
@@ -1,3 +1,11 @@
+2021-04-26  Jan Beulich  <jbeulich@suse.com>
+
+       * config/tc-i386.c (md_apply_fix): Mark BFD_RELOC_X86_64_32S as
+       signed.
+       * testsuite/gas/i386/x86-64-addr32-bad.s,
+       testsuite/gas/i386/x86-64-addr32-bad.l: New.
+       * testsuite/gas/i386/i386.exp: Run new test.
+
 2021-04-23  Eric Botcazou<ebotcazou@adacore.com>
 
        * testsuite/gas/elf/section25.d: Run it everywhere.
index dc1ee881a203075b6283ae88ab248a8bd66de659..1f9844dcb52aeeed2229c91fb0a69d40d3139665 100644 (file)
@@ -12576,7 +12576,18 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
 
   /* Are we finished with this relocation now?  */
   if (fixP->fx_addsy == NULL)
-    fixP->fx_done = 1;
+    {
+      fixP->fx_done = 1;
+      switch (fixP->fx_r_type)
+       {
+       case BFD_RELOC_X86_64_32S:
+         fixP->fx_signed = 1;
+         break;
+
+       default:
+         break;
+       }
+    }
 #if defined (OBJ_COFF) && defined (TE_PE)
   else if (fixP->fx_addsy != NULL && S_IS_WEAK (fixP->fx_addsy))
     {
index e1dab453b42d73661b860180458c6cea2c313b79..a9a2a6403bbc090dae7a3ad03c6869cc862242b6 100644 (file)
@@ -750,6 +750,7 @@ if [gas_64_check] then {
     run_dump_test "x86_64-intel"
     run_dump_test "x86-64-addr32"
     run_dump_test "x86-64-addr32-intel"
+    run_list_test "x86-64-addr32-bad" "-al"
     run_dump_test "x86-64-opcode"
     run_dump_test "x86-64-intel64"
     if { ! [istarget "*-*-*cygwin*"] && ![istarget "*-*-mingw*"] } then {
diff --git a/gas/testsuite/gas/i386/x86-64-addr32-bad.l b/gas/testsuite/gas/i386/x86-64-addr32-bad.l
new file mode 100644 (file)
index 0000000..bddf0d1
--- /dev/null
@@ -0,0 +1,29 @@
+.*: Assembler messages:
+.*:3: Error:.* [0x]*88888888 .*
+.*:7: Error:.* [0x]*99999999 .*
+.*:11: Error:.* [0x]*99999999 .*
+GAS LISTING .*
+
+
+[      ]*[0-9]+[       ]+\.text
+[      ]*[0-9]+[       ]+addr32:
+[      ]*[0-9]+[       ]+lea   0x88888888\(%rax\), %rax
+[      ]*[0-9]+[       ]+\?\?\?\? 8D808888[    ]+lea   0x88888888\(%rax\), %eax
+[      ]*[0-9]+[       ]+8888
+[      ]*[0-9]+[       ]+\?\?\?\? 67488D80[    ]+lea   0x88888888\(%eax\), %rax
+[      ]*[0-9]+[       ]+88888888 *
+[      ]*[0-9]+[       ]*
+[      ]*[0-9]+[       ]+\?\?\?\? 488D8099[    ]+lea   value\(%rax\), %rax
+[      ]*[0-9]+[       ]+999999
+[      ]*[0-9]+[       ]+\?\?\?\? 8D809999[    ]+lea   value\(%rax\), %eax
+[      ]*[0-9]+[       ]+9999
+[      ]*[0-9]+[       ]+\?\?\?\? 67488D80[    ]+lea   value\(%eax\), %rax
+[      ]*[0-9]+[       ]+99999999 *
+[      ]*[0-9]+[       ]*
+[      ]*[0-9]+[       ]+\?\?\?\? 48C7C099[    ]+mov   \$value, %rax
+[      ]*[0-9]+[       ]+999999
+[      ]*[0-9]+[       ]+\?\?\?\? B8999999[    ]+mov   \$value, %eax
+[      ]*[0-9]+[       ]+99
+[      ]*[0-9]+[       ]*
+[      ]*[0-9]+[       ]+\.equ value, 0x99999999
+#pass
diff --git a/gas/testsuite/gas/i386/x86-64-addr32-bad.s b/gas/testsuite/gas/i386/x86-64-addr32-bad.s
new file mode 100644 (file)
index 0000000..460be20
--- /dev/null
@@ -0,0 +1,15 @@
+       .text
+addr32:
+       lea     0x88888888(%rax), %rax
+       lea     0x88888888(%rax), %eax
+       lea     0x88888888(%eax), %rax
+
+       lea     value(%rax), %rax
+       lea     value(%rax), %eax
+       lea     value(%eax), %rax
+
+       mov     $value, %rax
+       mov     $value, %eax
+
+       .equ    value, 0x99999999
+       .end