WIP MachO binutils port assisted by AI I may consider upstreaming this in the future.
0

Configure Feed

Select the types of activity you want to include in your feed.

PR 34036 looping in symbol_equated_p chains

This patch adds a new function for safely traversing a chain of equated
symbols to find the defining symbol.

PR 34036
* symbols.c (symbol_equated_to): New function.
* symbols.h (symbol_equated_to): Declare.
* expr.c (resolve_register): Use symbol_equated_to.
* config/tc-i386.c (parse_register): Likewise.
* config/tc-v850.c (reg_name_search): Likewise.

Alan Modra (Apr 4, 2026, 8:52 AM +1030) ea2b9ecd c9c059cb

+47 -22
+3 -9
gas/config/tc-i386.c
··· 17062 17062 char *save = input_line_pointer; 17063 17063 char *buf = xstrdup (reg_string), *name; 17064 17064 symbolS *symbolP; 17065 + offsetT off; 17065 17066 17066 17067 input_line_pointer = buf; 17067 17068 get_symbol_name (&name); 17068 17069 symbolP = symbol_find (name); 17069 - while (symbolP && symbol_equated_p (symbolP)) 17070 - { 17071 - const expressionS *e = symbol_get_value_expression(symbolP); 17072 - 17073 - if (e->X_add_number) 17074 - break; 17075 - symbolP = e->X_add_symbol; 17076 - } 17077 - if (symbolP && S_GET_SEGMENT (symbolP) == reg_section) 17070 + symbolP = symbol_equated_to (symbolP, &off); 17071 + if (symbolP && off == 0 && S_GET_SEGMENT (symbolP) == reg_section) 17078 17072 { 17079 17073 const expressionS *e = symbol_get_value_expression (symbolP); 17080 17074
+7 -2
gas/config/tc-v850.c
··· 943 943 /* If the symbol is an alias for another name then use that. 944 944 If the symbol is an alias for a number, then return the number. */ 945 945 if (symbol_equated_p (symbolP)) 946 - name 947 - = S_GET_NAME (symbol_get_value_expression (symbolP)->X_add_symbol); 946 + { 947 + offsetT off; 948 + symbolP = symbol_equated_to (symbolP, &off); 949 + if (symbolP == NULL || off != 0) 950 + return -1; 951 + name = S_GET_NAME (symbolP); 952 + } 948 953 else if (accept_numbers) 949 954 { 950 955 int reg = S_GET_VALUE (symbolP);
+8 -11
gas/expr.c
··· 2473 2473 void resolve_register (expressionS *expP) 2474 2474 { 2475 2475 symbolS *sym; 2476 - offsetT acc = 0; 2477 - const expressionS *e = expP; 2476 + offsetT acc; 2477 + const expressionS *e; 2478 2478 2479 2479 if (expP->X_op != O_symbol) 2480 2480 return; 2481 2481 2482 - do 2483 - { 2484 - if (!md_register_arithmetic && e->X_add_number) 2485 - break; 2486 - sym = e->X_add_symbol; 2487 - acc += e->X_add_number; 2488 - e = symbol_get_value_expression (sym); 2489 - } 2490 - while (symbol_equated_p (sym)); 2482 + sym = symbol_equated_to (expP->X_add_symbol, &acc); 2483 + acc += expP->X_add_number; 2484 + if (sym == NULL 2485 + || (!md_register_arithmetic && acc != 0)) 2486 + return; 2491 2487 2488 + e = symbol_get_value_expression (sym); 2492 2489 if (e->X_op == O_register) 2493 2490 { 2494 2491 expr_copy (expP, e);
+28
gas/symbols.c
··· 3020 3020 || S_IS_COMMON (s))); 3021 3021 } 3022 3022 3023 + /* Return the final symbol in a chain of equated symbols, and the offset 3024 + from that symbol. If the chain has a loop, return NULL. 3025 + For a non-equated SYM, return SYM. */ 3026 + 3027 + symbolS * 3028 + symbol_equated_to (symbolS *sym, offsetT *off) 3029 + { 3030 + valueT add = 0; 3031 + symbolS *ret = sym; 3032 + while (ret && symbol_equated_p (ret)) 3033 + { 3034 + const expressionS *e = symbol_get_value_expression (ret); 3035 + add += e->X_add_number; 3036 + ret->flags.resolving = 1; 3037 + ret = e->X_add_symbol; 3038 + if (ret->flags.resolving) 3039 + ret = NULL; 3040 + } 3041 + while (sym && sym->flags.resolving) 3042 + { 3043 + const expressionS *e = symbol_get_value_expression (sym); 3044 + sym->flags.resolving = 0; 3045 + sym = e->X_add_symbol; 3046 + } 3047 + *off = add; 3048 + return ret; 3049 + } 3050 + 3023 3051 /* Return whether a symbol has a constant value. */ 3024 3052 3025 3053 int
+1
gas/symbols.h
··· 221 221 extern int symbol_section_p (const symbolS *); 222 222 extern int symbol_equated_p (const symbolS *); 223 223 extern int symbol_equated_reloc_p (const symbolS *); 224 + extern symbolS *symbol_equated_to (symbolS *, offsetT *); 224 225 extern int symbol_constant_p (const symbolS *); 225 226 extern int symbol_shadow_p (const symbolS *); 226 227 extern symbolS *symbol_symbolS (symbolS *);