From ed1c6eb93e46b04f2e2ddc82df4bd8f5e8eed6aa Mon Sep 17 00:00:00 2001 From: "mingjun.zhou" Date: Fri, 20 Sep 2024 13:54:19 +0800 Subject: [PATCH] Fix unresovled kernel symbols when /proc/kallsyms is not sorted --- ebpf/symtab/kallsyms.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ebpf/symtab/kallsyms.go b/ebpf/symtab/kallsyms.go index 3601dafa96..722c1acc28 100644 --- a/ebpf/symtab/kallsyms.go +++ b/ebpf/symtab/kallsyms.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "runtime" + "sort" "strconv" ) @@ -94,5 +95,9 @@ func NewKallsymsFromData(kallsyms []byte) (*SymbolTab, error) { if allZeros { return NewSymbolTab(nil), nil } + // kallsyms maybe unsorted when bpf/modules are loaded from userspace after kernel boot. + sort.Slice(syms, func(i, j int) bool { + return syms[i].Start < syms[j].Start + }) return NewSymbolTab(syms), nil }