Skip to content

Commit

Permalink
btf: support raw BTF in loadKernelSpec
Browse files Browse the repository at this point in the history
Some distributions with older kernels sometimes don't ship BTF out of the box. By allowing raw BTF in the fallback paths users can use pahole to work around this.

libbpf has similar behaviour: libbpf/libbpf@0420f75

Signed-off-by: Wang Xingxing <[email protected]>
  • Loading branch information
wxx213 authored Nov 1, 2023
1 parent 6b0a090 commit 78e76c9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions btf/btf.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,12 @@ func loadKernelSpec() (_ *Spec, fallback bool, _ error) {
}
defer file.Close()

spec, err := loadSpecFromELF(file)
spec, err := LoadSpecFromReader(file)
return spec, true, err
}

// findVMLinux scans multiple well-known paths for vmlinux kernel images.
func findVMLinux() (*internal.SafeELFFile, error) {
func findVMLinux() (*os.File, error) {
release, err := internal.KernelRelease()
if err != nil {
return nil, err
Expand All @@ -346,7 +346,7 @@ func findVMLinux() (*internal.SafeELFFile, error) {
}

for _, loc := range locations {
file, err := internal.OpenSafeELFFile(fmt.Sprintf(loc, release))
file, err := os.Open(fmt.Sprintf(loc, release))
if errors.Is(err, os.ErrNotExist) {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion btf/btf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func TestFindVMLinux(t *testing.T) {
}
defer file.Close()

spec, err := loadSpecFromELF(file)
spec, err := LoadSpecFromReader(file)
if err != nil {
t.Fatal("Can't load BTF:", err)
}
Expand Down

0 comments on commit 78e76c9

Please sign in to comment.