From: Jan Beulich Date: Wed, 23 Mar 2022 11:31:04 +0000 (+0100) Subject: x86: improve resolution of register equates X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=64d23078e30e54e1bb095962540e4c6138edaf5a;p=binutils-gdb.git x86: improve resolution of register equates 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. --- diff --git a/gas/config/tc-i386-intel.c b/gas/config/tc-i386-intel.c index d0c30ddbd5d..83d22407429 100644 --- a/gas/config/tc-i386-intel.c +++ b/gas/config/tc-i386-intel.c @@ -536,6 +536,9 @@ static int i386_intel_simplify (expressionS *e) 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; diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c index ec82144ed1b..93eec1c9ed4 100644 --- a/gas/config/tc-i386.c +++ b/gas/config/tc-i386.c @@ -12974,6 +12974,14 @@ parse_register (char *reg_string, char **end_op) 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); diff --git a/gas/testsuite/gas/i386/equ.d b/gas/testsuite/gas/i386/equ.d index 0f270a6ccdf..d7c863f4560 100644 --- 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 diff --git a/gas/testsuite/gas/i386/equ.s b/gas/testsuite/gas/i386/equ.s index e15148a741d..c7c4e604f03 100644 --- 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]