From 099347dc5ed04b645946afe24d6088b64c3c9d5d Mon Sep 17 00:00:00 2001 From: Leon Hwang Date: Wed, 4 Dec 2024 22:12:39 +0800 Subject: [PATCH] bpflbr: Use latest official cilium/ebpf lib Signed-off-by: Leon Hwang --- go.mod | 6 ++---- go.sum | 8 ++++---- internal/bpflbr/bpf_prog_info.go | 15 +++++---------- internal/bpflbr/dump.go | 8 +++----- 4 files changed, 14 insertions(+), 23 deletions(-) diff --git a/go.mod b/go.mod index 4e22755..a677e8c 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/go.sum b/go.sum index dafc26e..f372b2b 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/internal/bpflbr/bpf_prog_info.go b/internal/bpflbr/bpf_prog_info.go index 59e5d8f..ee423e6 100644 --- a/internal/bpflbr/bpf_prog_info.go +++ b/internal/bpflbr/bpf_prog_info.go @@ -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 { @@ -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() @@ -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] } diff --git a/internal/bpflbr/dump.go b/internal/bpflbr/dump.go index 2495863..de09732 100644 --- a/internal/bpflbr/dump.go +++ b/internal/bpflbr/dump.go @@ -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") @@ -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. @@ -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] }