On Mon, Apr 24, 2023 at 9:06 AM Jiri Olsa <jolsa@xxxxxxxxxx> wrote: > > Adding support for uprobe.multi/uprobe.multi program sections > to allow auto attach of multi_uprobe programs. > > Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx> > --- > tools/lib/bpf/libbpf.c | 38 ++++++++++++++++++++++++++++++++++++++ > 1 file changed, 38 insertions(+) > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > index c786bc142791..70353aaac86e 100644 > --- a/tools/lib/bpf/libbpf.c > +++ b/tools/lib/bpf/libbpf.c > @@ -8628,6 +8628,7 @@ static int attach_tp(const struct bpf_program *prog, long cookie, struct bpf_lin > static int attach_raw_tp(const struct bpf_program *prog, long cookie, struct bpf_link **link); > static int attach_trace(const struct bpf_program *prog, long cookie, struct bpf_link **link); > static int attach_kprobe_multi(const struct bpf_program *prog, long cookie, struct bpf_link **link); > +static int attach_uprobe_multi(const struct bpf_program *prog, long cookie, struct bpf_link **link); > static int attach_lsm(const struct bpf_program *prog, long cookie, struct bpf_link **link); > static int attach_iter(const struct bpf_program *prog, long cookie, struct bpf_link **link); > > @@ -8643,6 +8644,8 @@ static const struct bpf_sec_def section_defs[] = { > SEC_DEF("uretprobe.s+", KPROBE, 0, SEC_SLEEPABLE, attach_uprobe), > SEC_DEF("kprobe.multi+", KPROBE, BPF_TRACE_KPROBE_MULTI, SEC_NONE, attach_kprobe_multi), > SEC_DEF("kretprobe.multi+", KPROBE, BPF_TRACE_KPROBE_MULTI, SEC_NONE, attach_kprobe_multi), > + SEC_DEF("uprobe.multi+", KPROBE, BPF_TRACE_UPROBE_MULTI, SEC_NONE, attach_uprobe_multi), > + SEC_DEF("uretprobe.multi+", KPROBE, BPF_TRACE_UPROBE_MULTI, SEC_NONE, attach_uprobe_multi), > SEC_DEF("ksyscall+", KPROBE, 0, SEC_NONE, attach_ksyscall), > SEC_DEF("kretsyscall+", KPROBE, 0, SEC_NONE, attach_ksyscall), > SEC_DEF("usdt+", KPROBE, 0, SEC_NONE, attach_usdt), > @@ -10611,6 +10614,41 @@ static int attach_kprobe_multi(const struct bpf_program *prog, long cookie, stru > return libbpf_get_error(*link); > } > > +static int attach_uprobe_multi(const struct bpf_program *prog, long cookie, struct bpf_link **link) > +{ > + LIBBPF_OPTS(bpf_uprobe_multi_opts, opts); > + char *probe_type = NULL, *binary_path = NULL, *func_name = NULL; > + int n, ret = -EINVAL; > + > + *link = NULL; > + > + n = sscanf(prog->sec_name, "%m[^/]/%m[^:]:%m[a-zA-Z0-9_.*?]+", Arnaldo recently brought to my attention that Go doesn't do mangling, so their function names are crazy, e.g.: "go/doc/comment.(*parseDoc).code" So we should think about making no assumptions about pattern inside `%m[a-zA-Z0-9_.*?]` > + &probe_type, &binary_path, &func_name); > + switch (n) { > + case 1: > + /* handle SEC("u[ret]probe") - format is valid, but auto-attach is impossible. */ > + ret = 0; > + break; > + case 2: > + pr_warn("prog '%s': section '%s' missing ':function[+offset]' specification\n", > + prog->name, prog->sec_name); > + break; > + case 3: > + opts.retprobe = strcmp(probe_type, "uretprobe.multi"); > + *link = bpf_program__attach_uprobe_multi_opts(prog, binary_path, func_name, &opts); > + ret = libbpf_get_error(*link); > + break; > + default: > + pr_warn("prog '%s': invalid format of section definition '%s'\n", prog->name, > + prog->sec_name); > + break; > + } > + free(probe_type); > + free(binary_path); > + free(func_name); > + return ret; > +} > + > static void gen_uprobe_legacy_event_name(char *buf, size_t buf_sz, > const char *binary_path, uint64_t offset) > { > -- > 2.40.0 >