[PATCH 2/3] x86: improve resolution of register equates
Jan Beulich
jbeulich@suse.com
Tue Mar 22 13:52:57 GMT 2022
More information about the Binutils mailing list
Tue Mar 22 13:52:57 GMT 2022
- Previous message (by thread): [PATCH 1/3] x86: don't attempt to resolve equates and alike from i386_parse_name()
- Next message (by thread): [PATCH 3/3] x86: reject relocations involving registers
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Allow transitive (or recursive) equates to work in addition to direct
ones. The only requirements are that
- the equate being straight of a register, i.e. no expressions involved
(albeit I'm afraid something like "%eax + 0" will be viewed as %eax),
- at the point of use there's no forward ref left which cannot be
resolved, yet.
---
The adjustment to use "fresh" symbols (a, b, c) in the test case is to
account for what I'd call a separate anomaly: y and z "latch" their
values upon first use, i.e. what they resolve to doesn't change anymore
when x changes. This looks to be separate because it can as well be
observed in an architecture independent way, by e.g. using constants
instead of registers and data generation directives instead of insns. I
think this is also related to why the example in PR gas/28977 had to use
two assignments in order to actually observe the misbehavior.
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -12974,6 +12974,14 @@ parse_register (char *reg_string, char *
input_line_pointer = reg_string;
c = get_symbol_name (®_string);
symbolP = symbol_find (reg_string);
+ while (symbolP && S_GET_SEGMENT (symbolP) != reg_section)
+ {
+ const expressionS *e = symbol_get_value_expression(symbolP);
+
+ if (e->X_op != O_symbol || e->X_add_number)
+ break;
+ symbolP = e->X_add_symbol;
+ }
if (symbolP && S_GET_SEGMENT (symbolP) == reg_section)
{
const expressionS *e = symbol_get_value_expression (symbolP);
--- a/gas/config/tc-i386-intel.c
+++ b/gas/config/tc-i386-intel.c
@@ -529,6 +529,9 @@ static int i386_intel_simplify (expressi
if (e->X_add_symbol
&& !i386_intel_simplify_symbol (e->X_add_symbol))
return 0;
+ if (!the_reg && this_operand >= 0
+ && e->X_op == O_symbol && !e->X_add_number)
+ the_reg = i.op[this_operand].regs;
if (e->X_op == O_add || e->X_op == O_subtract)
{
base = intel_state.base;
--- a/gas/testsuite/gas/i386/equ.d
+++ b/gas/testsuite/gas/i386/equ.d
@@ -13,6 +13,8 @@ Disassembly of section .text:
[ 0-9a-f]+:[ 0-9a-f]+test[ ]+%ecx,%ecx
[ 0-9a-f]+:[ 0-9a-f]+mov[ ]+%fs:\(%ecx,%ecx,4\),%ecx
[ 0-9a-f]+:[ 0-9a-f]+fadd[ ]+%st\(1\),%st
+[ 0-9a-f]+:[ 0-9a-f]+fmul[ ]+%st\(1\),%st
+[ 0-9a-f]+:[ 0-9a-f]+fsub[ ]+%st\(1\),%st
[ 0-9a-f]+:[ 0-9a-f]+mov[ ]+\$0xfffffffe,%eax
[ 0-9a-f]+:[ 0-9a-f]+mov[ ]+0xfffffffe,%eax
[ 0-9a-f]+:[ 0-9a-f]+mov[ ]+\$0x0,%eax[ 0-9a-f]+:[ a-zA-Z0-9_]+xtrn
@@ -21,7 +23,11 @@ Disassembly of section .text:
[ 0-9a-f]+:[ 0-9a-f]+mov[ ]+%gs:\(%edx,%edx,8\),%edx
[ 0-9a-f]+:[ 0-9a-f]+mov[ ]+%gs:\(%edx,%edx,8\),%edx
[ 0-9a-f]+:[ 0-9a-f]+fadd[ ]+%st\(1\),%st
+[ 0-9a-f]+:[ 0-9a-f]+fmul[ ]+%st\(1\),%st
+[ 0-9a-f]+:[ 0-9a-f]+fsub[ ]+%st\(1\),%st
[ 0-9a-f]+:[ 0-9a-f]+fadd[ ]+%st\(7\),%st
+[ 0-9a-f]+:[ 0-9a-f]+fmul[ ]+%st\(7\),%st
+[ 0-9a-f]+:[ 0-9a-f]+fsub[ ]+%st\(7\),%st
[ 0-9a-f]+:[ 0-9a-f]+mov[ ]+0x4\(%edx\),%eax
[ 0-9a-f]+:[ 0-9a-f]+mov[ ]+0x4\(%edx\),%eax
#pass
--- a/gas/testsuite/gas/i386/equ.s
+++ b/gas/testsuite/gas/i386/equ.s
@@ -13,8 +13,12 @@ _start:
.equ s, %fs
testl r, r
movl s:(r,r,4), r
+ .equ z, y
+ .equ y, x
.equ x, %st(1)
fadd x
+ fmul y
+ fsub z
.if r <> %ecx
.err
@@ -37,8 +41,14 @@ _start:
mov r, s:[r+r*8]
mov r, s:[8*r+r]
fadd x
- .equ x, st(7)
- fadd x
+ fmul y
+ fsub z
+ .equ c, b
+ .equ b, a
+ .equ a, st(7)
+ fadd a
+ fmul b
+ fsub c
.equ r, edx + 4
mov eax, [r]
mov eax, [r]
- Previous message (by thread): [PATCH 1/3] x86: don't attempt to resolve equates and alike from i386_parse_name()
- Next message (by thread): [PATCH 3/3] x86: reject relocations involving registers
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Binutils mailing list