libbpf: Add auto-attach for uprobes based on section name
authorAlan Maguire <alan.maguire@oracle.com>
Wed, 30 Mar 2022 15:26:38 +0000 (16:26 +0100)
committerAndrii Nakryiko <andrii@kernel.org>
Mon, 4 Apr 2022 02:55:57 +0000 (19:55 -0700)
commit39f8dc43b7a05ab0e352655a14a9d613c2308b92
tree32ebf3438890623070e52d37c9cff2944ef2cb1b
parent433966e3ae04165811b116af492a684bad7a158c
libbpf: Add auto-attach for uprobes based on section name

Now that u[ret]probes can use name-based specification, it makes
sense to add support for auto-attach based on SEC() definition.
The format proposed is

        SEC("u[ret]probe/binary:[raw_offset|[function_name[+offset]]")

For example, to trace malloc() in libc:

        SEC("uprobe/libc.so.6:malloc")

...or to trace function foo2 in /usr/bin/foo:

        SEC("uprobe//usr/bin/foo:foo2")

Auto-attach is done for all tasks (pid -1).  prog can be an absolute
path or simply a program/library name; in the latter case, we use
PATH/LD_LIBRARY_PATH to resolve the full path, falling back to
standard locations (/usr/bin:/usr/sbin or /usr/lib64:/usr/lib) if
the file is not found via environment-variable specified locations.

Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/1648654000-21758-4-git-send-email-alan.maguire@oracle.com
tools/lib/bpf/libbpf.c
tools/testing/selftests/bpf/progs/test_bpf_cookie.c
tools/testing/selftests/bpf/progs/test_task_pt_regs.c
tools/testing/selftests/bpf/progs/trigger_bench.c