https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124679
Bug ID: 124679
Summary: gcc preprocessor spins to infinite memory consumption
on systemtap-generated c code, gcc version 15+
Product: gcc
Version: 15.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: preprocessor
Assignee: unassigned at gcc dot gnu.org
Reporter: fche at redhat dot com
Target Milestone: ---
Systemtap generates C code from instrumentation scripts, which are then
compiled with GCC. A particular script has been producing C code which, while
complex,
looks legitimate. Gcc 15 (and later!) however appear to spin in their
preprocessor just working on macro expansion, consuming all RAM. Since the
problem occurs in the preprocessor stage, I don't have an .i file to
demonstrate the problem.
I'll try to gather more helpful raw info, but for now:
% stap -k -vvvv -p4 --example timeout.stp
quickly shows a cc1 process that is processing a /var/tmp/stap*/stap_*_src.c
file.
Siccing gdb on that process shows something like:
#0 __GI___mremap (addr=addr@entry=0x1506288ec000,
old_len=old_len@entry=637620224, new_len=new_len@entry=637628416,
flags=flags@entry=1) at ../sysdeps/unix/sysv/linux/mremap.c:49
#1 0x0000150ad3498e01 in mremap_chunk (p=0x1506288ec000, new_size=637628416)
at malloc.c:3088
#2 __GI___libc_realloc (oldmem=0x1506288ec010, bytes=637624400) at
malloc.c:3644
#3 0x000000000134a974 in xrealloc (oldmem=<optimized out>, size=637624400) at
../libiberty/../../libiberty/xmalloc.c:181
#4 0x000000000138f248 in collect_args (pfile=0x12d14fd0, node=0x150ac4c58c48,
pragma_buff=<synthetic pointer>,
num_args=<synthetic pointer>) at ../libcpp/../../libcpp/macro.cc:1306
#5 funlike_invocation_p (pfile=0x12d14fd0, node=0x150ac4c58c48,
pragma_buff=<synthetic pointer>, num_args=<synthetic pointer>)
at ../libcpp/../../libcpp/macro.cc:1478
#6 enter_macro_context (pfile=0x12d14fd0, node=0x150ac4c58c48,
result=0x1313bdf0, location=4611686017303326973)
at ../libcpp/../../libcpp/macro.cc:1553
#7 0x0000000001382644 in cpp_get_token_1 (pfile=0x12d14fd0,
location=0x7ffdaccfccc8) at ../libcpp/../../libcpp/macro.cc:3110
#8 0x00000000013988f8 in expand_arg (pfile=0x12d14fd0, arg=0x130d88c0) at
../libcpp/../../libcpp/macro.cc:2801
#9 0x000000000138ed10 in replace_args (pfile=0x12d14fd0, node=0x150ac254cf18,
macro=<optimized out>, args=0x130d8890,
expansion_point_loc=4747058182) at ../libcpp/../../libcpp/macro.cc:2032
#10 enter_macro_context (pfile=0x12d14fd0, node=0x150ac254cf18,
result=0x12d88e00, location=4747058182)
at ../libcpp/../../libcpp/macro.cc:1574
#11 0x0000000001382644 in cpp_get_token_1 (pfile=0x12d14fd0,
location=0x7ffdaccfce98) at ../libcpp/../../libcpp/macro.cc:3110
#12 0x00000000013988f8 in expand_arg (pfile=0x12d14fd0, arg=0x130c9ba0) at
../libcpp/../../libcpp/macro.cc:2801
#13 0x000000000138ed10 in replace_args (pfile=0x12d14fd0, node=0x150ac254cf18,
macro=<optimized out>, args=0x130c9b70,
expansion_point_loc=4746992390) at ../libcpp/../../libcpp/macro.cc:2032
#14 enter_macro_context (pfile=0x12d14fd0, node=0x150ac254cf18,
result=0x12d88d00, location=4746992390)
at ../libcpp/../../libcpp/macro.cc:1574
#15 0x0000000001382644 in cpp_get_token_1 (pfile=0x12d14fd0,
location=0x7ffdaccfd068) at ../libcpp/../../libcpp/macro.cc:3110
#16 0x00000000013988f8 in expand_arg (pfile=0x12d14fd0, arg=0x130bae80) at
../libcpp/../../libcpp/macro.cc:2801
#17 0x000000000138ed10 in replace_args (pfile=0x12d14fd0, node=0x150ac254cf18,
macro=<optimized out>, args=0x130bae50,
expansion_point_loc=4746926598) at ../libcpp/../../libcpp/macro.cc:2032
#18 enter_macro_context (pfile=0x12d14fd0, node=0x150ac254cf18,
result=0x12d88c00, location=4746926598)
at ../libcpp/../../libcpp/macro.cc:1574
#19 0x0000000001382644 in cpp_get_token_1 (pfile=0x12d14fd0,
location=0x7ffdaccfd238) at ../libcpp/../../libcpp/macro.cc:3110
#20 0x00000000013988f8 in expand_arg (pfile=0x12d14fd0, arg=0x130ac160) at
../libcpp/../../libcpp/macro.cc:2801
#21 0x000000000138ed10 in replace_args (pfile=0x12d14fd0, node=0x150ac254cf18,
macro=<optimized out>, args=0x130ac130,
expansion_point_loc=4746860806) at ../libcpp/../../libcpp/macro.cc:2032
#22 enter_macro_context (pfile=0x12d14fd0, node=0x150ac254cf18,
result=0x12d88b00, location=4746860806)
at ../libcpp/../../libcpp/macro.cc:1574
#23 0x0000000001382644 in cpp_get_token_1 (pfile=0x12d14fd0,
location=0x7ffdaccfd408) at ../libcpp/../../libcpp/macro.cc:3110
#24 0x00000000013988f8 in expand_arg (pfile=0x12d14fd0, arg=0x1309d440) at
../libcpp/../../libcpp/macro.cc:2801
#25 0x000000000138ed10 in replace_args (pfile=0x12d14fd0, node=0x150ac254cf18,
macro=<optimized out>, args=0x1309d410,
expansion_point_loc=4746795014) at ../libcpp/../../libcpp/macro.cc:2032
#18 enter_macro_context (pfile=0x12d14fd0, node=0x150ac254cf18,
result=0x12d88c00, location=4746926598)
at ../libcpp/../../libcpp/macro.cc:1574
1574 replace_args (pfile, node, macro,
(gdb) p *node
$12 = {ident = {str = 0x150ac246ca88 "strlcpy", len = 7, hash_value =
302130339}, is_directive = 0, directive_index = 0,
rid_code = 0, flags = 48, type = NT_USER_MACRO, deferred = 0, value =
{answers = 0x150ac254e800, macro = 0x150ac254e800,
builtin = 3260344320, arg_index = 59392}}
(gdb)