Skip to content

Commit

Permalink
bpflbr: Use latest official cilium/ebpf lib
Browse files Browse the repository at this point in the history
Signed-off-by: Leon Hwang <[email protected]>
  • Loading branch information
Asphaltt committed Dec 5, 2024
1 parent f382535 commit 099347d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 23 deletions.
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22.4

require (
github.com/Asphaltt/addr2line v0.1.0
github.com/cilium/ebpf v0.16.0
github.com/cilium/ebpf v0.16.1-0.20241204125435-9895aae6467e
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/knightsc/gapstone v4.0.1+incompatible
github.com/spf13/pflag v1.0.5
Expand All @@ -14,9 +14,7 @@ require (

require (
github.com/ianlancetaylor/demangle v0.0.0-20240912202439-0a2b6291aafd // indirect
golang.org/x/sys v0.20.0
golang.org/x/sys v0.26.0
)

replace github.com/knightsc/gapstone v4.0.1+incompatible => github.com/Asphaltt/gapstone v0.0.0-20241029140935-c5412a26abf7

replace github.com/cilium/ebpf v0.16.0 => github.com/Asphaltt/ebpf v0.0.0-20241102052356-d5a4c9e8b9c2
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
github.com/Asphaltt/addr2line v0.1.0 h1:DvcYoB7C7PDg6fZTGxqeIeZ6ydxQ+NpzIR2o+qaVKk4=
github.com/Asphaltt/addr2line v0.1.0/go.mod h1:02z/FcEJ9rsH1i7It81L6xHtjSoBOrKbDtTGlptzfP0=
github.com/Asphaltt/ebpf v0.0.0-20241102052356-d5a4c9e8b9c2 h1:XUIgMZYZAQfAZ72Q2dXcKjA7smub7lu1h6/GNsn+alc=
github.com/Asphaltt/ebpf v0.0.0-20241102052356-d5a4c9e8b9c2/go.mod h1:g+Zxp5bVKYJy9/njLFYE+mNTcw1P8TnE59/2Qq2Pr3I=
github.com/Asphaltt/gapstone v0.0.0-20241029140935-c5412a26abf7 h1:z1Ohf61MSfgVMxAs2Z4nWZ4p+a12K/u41JJurdIxdBU=
github.com/Asphaltt/gapstone v0.0.0-20241029140935-c5412a26abf7/go.mod h1:1K5hEzsMBLTPdRJKEHqBFJ8Zt2VRqDhomcQ11KH0WW4=
github.com/cilium/ebpf v0.16.1-0.20241204125435-9895aae6467e h1:5XfglRYfkpOngOCO8WB/unRPtfpUofslhkM4w+G5MNw=
github.com/cilium/ebpf v0.16.1-0.20241204125435-9895aae6467e/go.mod h1:vay2FaYSmIlv3r8dNACd4mW/OCaZLJKJOo+IHBvCIO8=
github.com/go-quicktest/qt v1.101.0 h1:O1K29Txy5P2OK0dGo59b7b0LR6wKfIhttaAhHUyn7eI=
github.com/go-quicktest/qt v1.101.0/go.mod h1:14Bz/f7NwaXPtdYEgzsx46kqSxVwTbzVZsDC26tQJow=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
Expand Down Expand Up @@ -34,5 +34,5 @@ golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
15 changes: 5 additions & 10 deletions internal/bpflbr/bpf_prog_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ type bpfProgAddrLineInfo struct {
kaddrRange bpfProgKaddrRange
funcName string

jitedLineInfo []uintptr // ordered
lineInfos []btf.LineInfo // mapping 1:1 with jitedLineInfo
jitedLineInfo []uintptr // ordered
lineInfos []btf.LineOffset // mapping 1:1 with jitedLineInfo
}

type bpfProgLineInfo struct {
Expand Down Expand Up @@ -73,14 +73,9 @@ func newBPFProgInfo(prog *ebpf.Program, engine gapstone.Engine) (*bpfProgInfo, e
return nil, fmt.Errorf("failed to get func infos: %w", err)
}

lineInfos, err := pinfo.LineInfos()
if err != nil {
return nil, fmt.Errorf("failed to get line infos: %w", err)
}

lines := lineInfos.Lines()
lines, _ := pinfo.LineInfos()
jitedInsns, _ := pinfo.JitedInsns()
jitedKsyms, _ := pinfo.KsymAddrs()
jitedKsyms, _ := pinfo.JitedKsymAddrs()
jitedFuncLens, _ := pinfo.JitedFuncLens()
jitedLineInfos, _ := pinfo.JitedLineInfos()

Expand All @@ -96,7 +91,7 @@ func newBPFProgInfo(prog *ebpf.Program, engine gapstone.Engine) (*bpfProgInfo, e
return nil, fmt.Errorf("line info number %d != jited line info number %d", len(lines), len(jitedLineInfos))
}

jited2li := make(map[uint64]btf.LineInfo, len(jitedLineInfos))
jited2li := make(map[uint64]btf.LineOffset, len(jitedLineInfos))
for i, kaddr := range jitedLineInfos {
jited2li[kaddr] = lines[i]
}
Expand Down
8 changes: 3 additions & 5 deletions internal/bpflbr/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func DumpProg(pf []ProgFlag) {
assert.NoErr(err, "Failed to get prog info: %v")

jitedInsns, _ := info.JitedInsns()
jitedKsyms, _ := info.KsymAddrs()
jitedKsyms, _ := info.JitedKsymAddrs()
jitedFuncLens, _ := info.JitedFuncLens()
jitedLineInfos, _ := info.JitedLineInfos()
assert.SliceNotEmpty(jitedInsns, "No jited insns")
Expand All @@ -82,10 +82,8 @@ func DumpProg(pf []ProgFlag) {
// jitedFuncLens are the insns length of each function.
// Then, jitedInsns can be split into len(jitedFuncLens) functions with each function having jitedFuncLens[i] insns.

li, err := info.LineInfos()
lines, err := info.LineInfos()
assert.NoErr(err, "Failed to get line infos: %v")

lines := li.Lines()
assert.Equal(len(lines), len(jitedLineInfos), "Line info mismatch: %d != %d (jited)", len(lines), len(jitedLineInfos))

// Each jitedLineInfo is corresponding to a lineInfo.
Expand All @@ -96,7 +94,7 @@ func DumpProg(pf []ProgFlag) {
// ksym addr + insn offset = jited line info addr.
// jited line info addr => line info.

jited2LineInfos := make(map[uint64]btf.LineInfo, len(jitedLineInfos))
jited2LineInfos := make(map[uint64]btf.LineOffset, len(jitedLineInfos))
for i, kaddr := range jitedLineInfos {
jited2LineInfos[kaddr] = lines[i]
}
Expand Down

0 comments on commit 099347d

Please sign in to comment.