Declassify context struct within _stp_filename_lookup_5
The _stp_filename_lookup_5 is using local arrays to store data parsed
from dwarf. Needed data storage is big and this leads to problems with
stack size. The specific compile time problem is as follows:
error: the frame size of 10272 bytes is larger than 2048 bytes [-Werror=frame-larger-than=]
As Will Cohen points out, this compiler warning is configured in the
kernel source here:
https://elixir.bootlin.com/linux/v6.6-rc6/source/lib/Kconfig.debug#L434
The point of the warning is to prevent a stack overflow. A possible
solution would be to mark the variables as static, moving them to the
data segment. This however only works in case there is no parallelism.
We can't guarantee that (e.g. two different probes may trigger
and use that underlying function at the same time).
So Frank advised to move the data to the context struct. That is
emitted to the stap_XXXXXX_src.i file within translate.cxx by
s.up->emit_common_header (). Sadly, this happens way after sym.c
is emitted, so in sym.c the context struct is not known.
I was wrapping my head around reordering the emission of the context
struct and runtime.h which is a pretty big beast called "main header
file for Linux" ;) There are nontrivial ties between these two.
I gave up going this way.
Instead, I've separated the function body of _stp_filename_lookup_5()
out to a separate file sym2.c, which gets emitted only after the context
struct is known.
To test this, the _stp_filename_lookup_5() has a debug print at its very
beginning of its function body, showing how the c->probe_type can be
accessed (and shown via _stp_printf() to the user). This approach
appears to be workable:
---------------------------8<--------------------------------------------------
Pass 1: parsed user script and 484 library scripts using 138316virt/107988res/15872shr/91576data kb, in 170usr/40sys/215real ms.
Pass 2: analyzed script: 1 probe, 1 function, 0 embeds, 0 globals using 139768virt/110804res/17024shr/93028data kb, in 10usr/10sys/8real ms.
Pass 3: translated to C into "/tmp/stapku0cxM/stap_342553_src.c" using 140912virt/114568res/19596shr/94172data kb, in 180usr/220sys/409real ms.
Pass 4: compiled C into "stap_342553.ko" in 5320usr/1200sys/5906real ms.
Pass 5: starting run.
XXX CONTEXT: uprobe-yes
0x40110a : main+0x4/0xe at /root/test/test.c:2 [/root/test/test5]
0x7fcf6a94e14a : __libc_start_call_main+0x7a/0xb0 [/usr/lib64/libc.so.6]
0x7fcf6a94e20b : __libc_start_main@GLIBC_2.2.5+0x8b/0x160 [/usr/lib64/libc.so.6]
0x401045 : _start+0x25/0x30 [/root/test/test5]
Pass 5: run completed in 20usr/50sys/1343real ms.
Keeping temporary directory "/tmp/stapku0cxM"
---------------------------8<--------------------------------------------------