Skip to content

Commit 0ab0dc1

Browse files
Asphalttbrb
authored andcommitted
fix: Get bpf prog entry func name from insns
It is possible to get wrong entry func name of bpf prog when there is info of multiple bpf progs in the BTF. Instead, get the very first symbol from bpf prog's instructions as its entry func name. Signed-off-by: Leon Hwang <[email protected]>
1 parent c857506 commit 0ab0dc1

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

internal/pwru/bpf_prog.go

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"fmt"
99

1010
"github.com/cilium/ebpf"
11-
"github.com/cilium/ebpf/btf"
1211
"golang.org/x/sys/unix"
1312
)
1413

@@ -47,26 +46,15 @@ func getEntryFuncName(prog *ebpf.Program) (string, string, error) {
4746
return "", "", fmt.Errorf("failed to get program info: %w", err)
4847
}
4948

50-
id, ok := info.BTFID()
51-
if !ok {
52-
return "", "", fmt.Errorf("bpf program %s does not have BTF", info.Name)
53-
}
54-
55-
handle, err := btf.NewHandleFromID(id)
56-
if err != nil {
57-
return "", "", fmt.Errorf("failed to get BTF handle: %w", err)
58-
}
59-
defer handle.Close()
60-
61-
spec, err := handle.Spec(nil)
49+
insns, err := info.Instructions()
6250
if err != nil {
63-
return "", "", fmt.Errorf("failed to get BTF spec: %w", err)
51+
return "", "", fmt.Errorf("failed to get program instructions: %w", err)
6452
}
6553

66-
iter := spec.Iterate()
67-
for iter.Next() {
68-
if fn, ok := iter.Type.(*btf.Func); ok {
69-
return fn.Name, info.Name, nil
54+
for _, insn := range insns {
55+
sym := insn.Symbol()
56+
if sym != "" {
57+
return sym, info.Name, nil
7058
}
7159
}
7260

0 commit comments

Comments
 (0)