Skip to content

Commit

Permalink
Fix unresovled kernel symbols when /proc/kallsyms is not sorted
Browse files Browse the repository at this point in the history
  • Loading branch information
zmj64351508 committed Sep 24, 2024
1 parent 7439460 commit 94ff4bc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ebpf/symtab/kallsyms.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"runtime"
"sort"
"strconv"
)

Expand Down Expand Up @@ -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
}
4 changes: 3 additions & 1 deletion ebpf/symtab/kallsyms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ ffffffff81001750 T memblock_find
ffffffff81001780 T __memblock_alloc_base
ffffffff810017d0 T memblock_alloc
ffffffff81001820 T early_memtest
ffffffff810018a0 T early_memtest_report`
ffffffff810018a0 T early_memtest_report
ffffffff81000800 T unordered_symbol_0
ffffffff81000100 T unordered_symbol_1`

func TestKallsyms(t *testing.T) {
kallsyms, err := NewKallsymsFromData([]byte(testdata))
Expand Down

0 comments on commit 94ff4bc

Please sign in to comment.