PR26074: pass kallsyms_lookup_name as a relocation to the stap runtime
Kernel commit
0bd476e6c671 unexports kallsyms_lookup_name
and kallsyms_on_each_symbol.
As kallsyms_lookup_name is used to look up unexported symbols, we need to
use the relocation mechanism (the same one used to pass _stext) to pass
these symbols to the runtime where necessary.
The patch preserves the old behaviour (link the exported symbol directly)
where kallsyms_lookup_name is available.
* buildrun.cxx (compile_pass): Change output_autoconf
STAPCONF_KALLSYMS_ON_EACH_SYMBOL to exportconf
STAPCONF_KALLSYMS_ON_EACH_SYMBOL_EXPORTED. Since the symbol may be
accessed even when unexported, the autoconf-kallsyms-on-each-symbol.c
is no longer accurate. Control the powerpc issue (PR11514) with
appropriate #ifdefs instead.
Change STAPCONF_KALLSYMS to STAPCONF_KALLSYMS_LOOKUP_NAME_EXPORTED.
* runtime/linux/autoconf-kallsyms-on-each-symbol.c: Deleted.
* runtime/linux/runtime.h (_stp_kallsyms_lookup_name): New field.
(_stp_kallsyms_on_each_symbol): New field.
* runtime/sym.c (kallsyms_lookup_name_fn): New typedef.
(kallsyms_lookup_name): New function, linked in place
of kallsyms_lookup_name, calls _stp_kallsyms_lookup_name if available.
(kallsyms_on_each_symbol_fn): New typedef.
(kallsyms_on_each_symbol): New function, linked in place of
kallsyms_on_each_symbol, calls _stp_kallsyms_on_each_symbol if available.
* runtime/sym.h (_stp_need_kallsyms_stext): New field.
(_stp_set_stext): New function, called to adjust _stp_kretprobe_trampoline
if kallsyms_lookup_name("_stext") call is delayed until after the relocation
is received.
* runtime/transport/symbols.c (_stp_set_stext): New function.
(_stp_do_relocation): Set _stp_kretprobe_trampoline if kallsyms_lookup_name
is not yet available,
Accept and set _stp_kallsyms_lookup_name and _stp_kallsyms_lookup_symbol
from relocations.
* runtime/transport/transport.h (_stp_handle_kallsyms_lookups): New function,
does delayed kallsyms_lookup_name() lookups previously done
in _stp_transport_init(), does delayed _stext lookup.
* runtime/transport/transport.c: Include sym.h for _stp_set_stext().
(_stp_handle_kallsyms_lookups): New function.
(_stp_transport_init): Don't do kallsyms_lookup_name() lookups yet
as kallsyms_lookup_name may be passed later on via relocation.
Init the addresses and _stp_need_kallsyms_stext to NULL instead.
* translate.cxx (c_unparser::emit_module_init): Emit a call to
_stp_handle_kallsyms_lookups() into systemtap_module_init(),
where the relocations for kallsyms_lookup_name() will be available.
* staprun/staprun.c (send_relocation_kernel): Look up
kallsyms_lookup_name and kallsyms_on_each_symbol in /proc/kallsyms
and send their addresses as STP_RELOCATION messages.
* runtime/linux/kprobes.c: define USE_KALLSYMS_ON_EACH_SYMBOL.
May be determined statically or dynamically depending on whether
a relocation is necessary to call kallsyms_on_each_symbol.
(stapkp_prepare_kprobe): change #ifdef to if(USE_KALLSYMS_ON_EACH_SYMBOL).
(stapkp_prepare_kretprobe): Ditto.
(stapkp_symbol_data): make available in all circumstances.
(stapkp_init): change #ifdef to if(USE_KALLSYMS_ON_EACH_SYMBOL).
(stapkp_refresh): Ditto.
* runtime/transport/transport_msgs.h (enum): clarifying comment
for STP_RELOCATION message.