libbpf: Support attaching tracing programs to Rust functions
Rust BTF FUNC names are DWARF names rather than symbol names. For
generic functions these include type parameters but not the path, e.g.
"blob_read<kernel::sync::lock::Lock<[u8; 4], ...>>". For trait methods
they are just the method name: rust_debugfs's implementation of
kernel::platform::Driver::probe for RustDebugFs has the FUNC name
"probe", so every Rust driver implementing that trait has a FUNC of the
same name. A single FUNC can also describe multiple monomorphized
symbols. pahole records each symbol in a
"rust:linkage:<mangled name>" decl tag on the FUNC, and the kernel
accepts such a tag id as the attach target, resolving it to the FUNC
and symbol.
For fentry/fexit/fmod_ret targets, look for a linkage tag on a FUNC
with the target name and use the tag id as the attach BTF id, so that
programs can use the Rust name, e.g.
SEC("fentry/rust_debugfs:from_str")
If the name matches multiple symbols, fail with -ENOTUNIQ and list
candidates; the mangled name can also be used as the target to
disambiguate. Functions without linkage tags are looked up by FUNC
name as before. Only the BTF's own types are searched for tags, since
module tags may point at deduplicated base FUNCs and the symbol lives
in the module.
Since Rust paths contain "::", only treat a single ':' as the
module/function separator in the target name.
Also avoid the BTF_MAX_NAME_SIZE (128) buffer used for prefixed
lookups when there is no prefix, since Rust names are often longer
than that and would fail with -ENAMETOOLONG.
Assisted-by: LLM
Signed-off-by: Alan Maguire <almagui@kernel.org>
1 file changed