Skip to content

Commit

Permalink
selftest: fix set-attach test
Browse files Browse the repository at this point in the history
After commit d6e6286a12e7 ("libbpf: disassociate section handler on explicit
bpf_program__set_type() call"), bpf_program__set_type() will force cleanup
the program's SEC() definition.

The program type should only be set if it differs from the desired one:

  if (type != BPF_PROG_TYPE_UNSPEC && bpf_program__type(prog) != type)
    bpf_program__set_type(prog, type);
  • Loading branch information
rafaeldtinoco committed May 3, 2023
1 parent 5bfcdb2 commit 650fef1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion selftest/set-attach/main.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct {
} events SEC(".maps");
long ringbuffer_flags = 0;

SEC("fentry/FUNC")
SEC("fentry")
int BPF_PROG(foobar)
{
int *process;
Expand Down
6 changes: 5 additions & 1 deletion selftest/set-attach/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ func main() {
os.Exit(-1)
}

prog.SetProgramType(bpf.BPFProgTypeTracing)
// eBPF program type should only be set if it differs from the desired one
// commit d6e6286a12e7 ("libbpf: disassociate section handler on explicit bpf_program__set_type() call")
// prog.SetProgramType(bpf.BPFProgTypeTracing)
prog.SetAttachType(bpf.BPFAttachTypeTraceFentry)

err = prog.SetAttachTarget(0, "__x64_sys_mmap")
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(-1)
}

err = bpfModule.BPFLoadObject()
if err != nil {
fmt.Fprintln(os.Stderr, err)
Expand Down

0 comments on commit 650fef1

Please sign in to comment.