Commit a77f879b authored by Stanislav Fomichev's avatar Stanislav Fomichev Committed by Andrii Nakryiko

libbpf: Use func name when pinning programs with LIBBPF_STRICT_SEC_NAME

We can't use section name anymore because they are not unique
and pinning objects with multiple programs with the same
progtype/secname will fail.

  [0] Closes: https://github.com/libbpf/libbpf/issues/273

Fixes: 33a2c75c ("libbpf: add internal pin_name")
Signed-off-by: default avatarStanislav Fomichev <sdf@google.com>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Reviewed-by: default avatarQuentin Monnet <quentin@isovalent.com>
Link: https://lore.kernel.org/bpf/20211021214814.1236114-2-sdf@google.com
parent e89ef634
...@@ -285,7 +285,7 @@ struct bpf_program { ...@@ -285,7 +285,7 @@ struct bpf_program {
size_t sub_insn_off; size_t sub_insn_off;
char *name; char *name;
/* sec_name with / replaced by _; makes recursive pinning /* name with / replaced by _; makes recursive pinning
* in bpf_object__pin_programs easier * in bpf_object__pin_programs easier
*/ */
char *pin_name; char *pin_name;
...@@ -618,7 +618,16 @@ static char *__bpf_program__pin_name(struct bpf_program *prog) ...@@ -618,7 +618,16 @@ static char *__bpf_program__pin_name(struct bpf_program *prog)
{ {
char *name, *p; char *name, *p;
name = p = strdup(prog->sec_name); if (libbpf_mode & LIBBPF_STRICT_SEC_NAME)
name = strdup(prog->name);
else
name = strdup(prog->sec_name);
if (!name)
return NULL;
p = name;
while ((p = strchr(p, '/'))) while ((p = strchr(p, '/')))
*p = '_'; *p = '_';
......
...@@ -52,6 +52,9 @@ enum libbpf_strict_mode { ...@@ -52,6 +52,9 @@ enum libbpf_strict_mode {
* allowed, with LIBBPF_STRICT_SEC_PREFIX this will become * allowed, with LIBBPF_STRICT_SEC_PREFIX this will become
* unrecognized by libbpf and would have to be just SEC("xdp") and * unrecognized by libbpf and would have to be just SEC("xdp") and
* SEC("xdp") and SEC("perf_event"). * SEC("xdp") and SEC("perf_event").
*
* Note, in this mode the program pin path will be based on the
* function name instead of section name.
*/ */
LIBBPF_STRICT_SEC_NAME = 0x04, LIBBPF_STRICT_SEC_NAME = 0x04,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment