From 78e76c90b74417746d3f8931b088ae56a549f703 Mon Sep 17 00:00:00 2001 From: wxx213 Date: Wed, 1 Nov 2023 20:19:21 +0800 Subject: [PATCH] btf: support raw BTF in loadKernelSpec 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: https://github.com/libbpf/libbpf/commit/0420f75dbcf732e3230ae212970b33a80026e225 Signed-off-by: Wang Xingxing --- btf/btf.go | 6 +++--- btf/btf_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/btf/btf.go b/btf/btf.go index a2ee2d130..9291b8c14 100644 --- a/btf/btf.go +++ b/btf/btf.go @@ -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 @@ -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 } diff --git a/btf/btf_test.go b/btf/btf_test.go index 4976fe481..843acadfe 100644 --- a/btf/btf_test.go +++ b/btf/btf_test.go @@ -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) }