Skip to content

Commit

Permalink
libbpf: Use func name when pinning programs with LIBBPF_STRICT_SEC_NAME
Browse files Browse the repository at this point in the history
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: libbpf/libbpf#273

Fixes: 33a2c75 ("libbpf: add internal pin_name")
Signed-off-by: Stanislav Fomichev <[email protected]>
Signed-off-by: Andrii Nakryiko <[email protected]>
Reviewed-by: Quentin Monnet <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
  • Loading branch information
fomichev authored and anakryiko committed Oct 22, 2021
1 parent e89ef63 commit a77f879
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
13 changes: 11 additions & 2 deletions tools/lib/bpf/libbpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ struct bpf_program {
size_t sub_insn_off;

char *name;
/* sec_name with / replaced by _; makes recursive pinning
/* name with / replaced by _; makes recursive pinning
* in bpf_object__pin_programs easier
*/
char *pin_name;
Expand Down Expand Up @@ -618,7 +618,16 @@ static char *__bpf_program__pin_name(struct bpf_program *prog)
{
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, '/')))
*p = '_';

Expand Down
3 changes: 3 additions & 0 deletions tools/lib/bpf/libbpf_legacy.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ enum libbpf_strict_mode {
* allowed, with LIBBPF_STRICT_SEC_PREFIX this will become
* unrecognized by libbpf and would have to be just SEC("xdp") and
* 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,

Expand Down

0 comments on commit a77f879

Please sign in to comment.