[PATCH] [GAS] Fix tight loop on recursively-defined symbols
Thomas Backlund
tmb@mageia.org
Sun May 17 22:22:51 GMT 2020
Den 15-05-2020 kl. 11:50, skrev Alan Modra via Binutils:
>
> Revised patch I'm about to commit is as follows. You'll note that the
> test now doesn't use single char symbols reducing the likelihood of
> there being a predefined symbol of that name, and the lines don't
> start in the first column due to some targets treating anything
> starting there as a label.
>
> * 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.
>
> diff --git a/gas/symbols.c b/gas/symbols.c
> index 160b0f7402..711730daf1 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))
> diff --git a/gas/testsuite/gas/all/assign-bad-recursive.d b/gas/testsuite/gas/all/assign-bad-recursive.d
> new file mode 100644
> index 0000000000..aeec5d55f8
> --- /dev/null
> +++ b/gas/testsuite/gas/all/assign-bad-recursive.d
> @@ -0,0 +1,4 @@
> +#name: bad recursive assignments
> +#source: assign-bad-recursive.s
> +#xfail: bfin-*-*
> +#error_output: assign-bad-recursive.l
> diff --git a/gas/testsuite/gas/all/assign-bad-recursive.l b/gas/testsuite/gas/all/assign-bad-recursive.l
> new file mode 100644
> index 0000000000..70eaf0fe2e
> --- /dev/null
> +++ b/gas/testsuite/gas/all/assign-bad-recursive.l
> @@ -0,0 +1,7 @@
> +[^:]*: Assembler messages:
> +.*: Error: symbol definition loop encountered at `aaa'
> +#...
> +.*: Error: symbol definition loop encountered at `iii'
> +#...
> +.*: Error: symbol definition loop encountered at `xxx'
> +#pass
> diff --git a/gas/testsuite/gas/all/assign-bad-recursive.s b/gas/testsuite/gas/all/assign-bad-recursive.s
> new file mode 100644
> index 0000000000..21917d91ff
> --- /dev/null
> +++ b/gas/testsuite/gas/all/assign-bad-recursive.s
> @@ -0,0 +1,8 @@
> + aaa = aaa
> +
> + iii = jjj
> + jjj = iii
> +
> + xxx = yyy
> + yyy = zzz
> + zzz = xxx
> diff --git a/gas/testsuite/gas/all/gas.exp b/gas/testsuite/gas/all/gas.exp
> index d414053782..1664018c0f 100644
> --- a/gas/testsuite/gas/all/gas.exp
> +++ b/gas/testsuite/gas/all/gas.exp
> @@ -97,6 +97,7 @@ if { ![istarget "bfin-*-*"] } then {
> gas_test "assign-ok.s" "" "" "== assignment support"
> }
> gas_test_error "assign-bad.s" "" "== assignment for symbol already set"
> +run_dump_test assign-bad-recursive
>
> run_dump_test simple-forward
> run_dump_test forward
>
This patch broke binutils on aarch64 for us...
For example building binutils-2.34 with all fixes in the 2.34 branch
makes it fail with:
make[2]: Leaving directory
'/home/iurt/rpmbuild/BUILD/binutils-2.34/objs/intl'
make[2]: Entering directory
'/home/iurt/rpmbuild/BUILD/binutils-2.34/objs/zlib'
aarch64-mageia-linux-gnu-gcc -DPACKAGE_NAME=\"zlib\"
-DPACKAGE_TARNAME=\"zlib\" -DPACKAGE_VERSION=\"1.1.4\"
-DPACKAGE_STRING=\"zlib\ 1.1.4\" -DPACKAGE_BUGREPORT=\"\"
-DPACKAGE_URL=\"\" -DPACKAGE=\"zlib\" -DVERSION=\"1.1.4\"
-DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1
-DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1
-DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1
-DLT_OBJDIR=\".libs/\" -DHAVE_STDLIB_H=1 -DHAVE_UNISTD_H=1
-DHAVE_SYS_PARAM_H=1 -DHAVE_GETPAGESIZE=1 -DHAVE_MMAP=1 -DHAVE_MEMCPY=1
-DHAVE_STRERROR=1 -DHAVE_UNISTD_H=1 -I. -I../../zlib -fPIC -O2 -g
-pipe -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
-fstack-protector --param=ssp-buffer-size=4 -fasynchronous-unwind-tables
-c -o libz_a-adler32.o `test -f 'adler32.c' || echo '../../zlib/'`adler32.c
{standard input}: Assembler messages:
{standard input}: Error: invalid operands (*ABS* and *GAS `expr'
section* sections) for `*' when setting `.LVU25'
{standard input}: Error: can't resolve value for symbol `.LVU25'
make[2]: *** [Makefile:603: libz_a-adler32.o] Error 1
or kernel perf build:
CC tests/openat-syscall-tp-fields.o
/tmp/ccgMDEso.s: Assembler messages:
/tmp/ccgMDEso.s: Error: invalid operands (*ABS* and *GAS `expr' section*
sections) for `*' when setting `.LVU552'
/tmp/ccgMDEso.s: Error: can't resolve value for symbol `.LVU552'
CC tests/mmap-basic.o
mv: cannot stat 'util/.config.o.tmp': No such file or directory
make[4]: ***
[/home/iurt/rpmbuild/BUILD/kernel-aarch64/linux-5.6/tools/build/Makefile.build:97:
util/config.o] Error 1
make[4]: *** Waiting for unfinished jobs....
CC tests/perf-record.o
CC ui/tui/setup.o
CC tests/evsel-roundtrip-name.o
CC tests/evsel-tp-sched.o
CC ui/browsers/map.o
CC ui/tui/util.o
/tmp/cc7Otk14.s: Assembler messages:
/tmp/cc7Otk14.s: Error: invalid operands (*ABS* and *GAS `expr' section*
sections) for `*' when setting `.LVU84'
/tmp/cc7Otk14.s: Error: can't resolve value for symbol `.LVU84'
mv: cannot stat 'ui/browsers/.annotate.o.tmp': No such file or directory
make[5]: ***
[/home/iurt/rpmbuild/BUILD/kernel-aarch64/linux-5.6/tools/build/Makefile.build:97:
ui/browsers/annotate.o] Error 1
make[5]: *** Waiting for unfinished jobs....
CC tests/fdarray.o
This is with gcc-10 branch with all fixes up to:
From f2b77b928a54784d40faf1d86bd5b63f14756dc5 Mon Sep 17 00:00:00 2001
From: Mark Eggleston <markeggleston@gcc.gnu.org>
Date: Thu, 7 May 2020 08:29:14 +0100
Subject: [PATCH] Fortran : ICE in gfc_conv_array_constructor_expr PR93497
--
Thomas
More information about the Binutils
mailing list