aboutsummaryrefslogtreecommitdiff
path: root/gas/symbols.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2020-05-15 18:06:05 +0930
committerAlan Modra <amodra@gmail.com>2020-05-15 18:21:07 +0930
commit2a50b401465f74d7f3ee1654915b9070b4dc0fee (patch)
tree40b5b90d909e7fef28d2f4099d03f1a1ec5f84a8 /gas/symbols.c
parenta51951c25813b8d6c763f51d78d3756d9ca85ee1 (diff)
downloadgdb-2a50b401465f74d7f3ee1654915b9070b4dc0fee.zip
gdb-2a50b401465f74d7f3ee1654915b9070b4dc0fee.tar.gz
gdb-2a50b401465f74d7f3ee1654915b9070b4dc0fee.tar.bz2
Fix tight loop on recursively-defined symbols
This patch fixes a bug in GAS where the assembler enters a tight loop when attempting to resolve recursively-defined symbols, e.g. when trying to assemble "a=a". This is a regression introduced between binutils 2.32 and 2.33, by commit 1903f1385bff9 * symbols.c (struct local_symbol): Update comment. (resolve_symbol_value): For resolved symbols equated to other symbols, verify that the referenced symbol is not a local_symbol before accessing sy_value. Don't leave symbol loops during finalize_syms resolution. * testsuite/gas/all/assign-bad-recursive.d: New test. * testsuite/gas/all/assign-bad-recursive.l: Error output for test. * testsuite/gas/all/assign-bad-recursive.s: Assembly for test. * testsuite/gas/all/gas.exp: Run it.
Diffstat (limited to 'gas/symbols.c')
-rw-r--r--gas/symbols.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/gas/symbols.c b/gas/symbols.c
index 160b0f7..711730d 100644
--- a/gas/symbols.c
+++ b/gas/symbols.c
@@ -114,7 +114,7 @@ struct symbol
/* A pointer in the symbol may point to either a complete symbol
(struct symbol above) or to a local symbol (struct local_symbol
defined here). The symbol code can detect the case by examining
- the first field. It is always NULL for a local symbol.
+ the first field which is present in both structs.
We do this because we ordinarily only need a small amount of
information for a local symbol. The symbol table takes up a lot of
@@ -1237,11 +1237,18 @@ resolve_symbol_value (symbolS *symp)
if (symp->sy_flags.sy_resolved)
{
final_val = 0;
- while (symp->sy_value.X_op == O_symbol
- && symp->sy_value.X_add_symbol->sy_flags.sy_resolved)
+ while (symp->sy_value.X_op == O_symbol)
{
final_val += symp->sy_value.X_add_number;
symp = symp->sy_value.X_add_symbol;
+ if (LOCAL_SYMBOL_CHECK (symp))
+ {
+ struct local_symbol *locsym = (struct local_symbol *) symp;
+ final_val += locsym->lsy_value;
+ return final_val;
+ }
+ if (!symp->sy_flags.sy_resolved)
+ return 0;
}
if (symp->sy_value.X_op == O_constant)
final_val += symp->sy_value.X_add_number;
@@ -1380,6 +1387,11 @@ resolve_symbol_value (symbolS *symp)
break;
}
+ /* Don't leave symbol loops. */
+ if (finalize_syms
+ && add_symbol->sy_flags.sy_resolving)
+ break;
+
if (finalize_syms && final_val == 0)
{
if (LOCAL_SYMBOL_CHECK (add_symbol))