]> git.feebdaed.xyz Git - 0xmirror/ebpf.git/commitdiff
feat : Add `LoadSplitSpec` function
authorTristan d'Audibert <tristan.daudibert@gmail.com>
Mon, 7 Jul 2025 09:36:48 +0000 (11:36 +0200)
committerTimo Beckers <ti-mo@users.noreply.github.com>
Tue, 8 Jul 2025 09:12:08 +0000 (11:12 +0200)
Similarly to LoadSpec, LoadSplitSpec could make an easier use of
split-BTF files

Signed-off-by: Tristan d'Audibert <tristan.daudibert@gmail.com>
btf/btf.go

index d26931a049741fb436bf620b2028568904799c55..52a7b502c64f29aba73e03fbf52a10d768cb12bd 100644 (file)
@@ -500,6 +500,20 @@ func (s *Spec) TypeByName(name string, typ interface{}) error {
        return nil
 }
 
+// LoadSplitSpec loads split BTF from the given file.
+//
+// Types from base are used to resolve references in the split BTF.
+// The returned Spec only contains types from the split BTF, not from the base.
+func LoadSplitSpec(file string, base *Spec) (*Spec, error) {
+       fh, err := os.Open(file)
+       if err != nil {
+               return nil, err
+       }
+       defer fh.Close()
+
+       return LoadSplitSpecFromReader(fh, base)
+}
+
 // LoadSplitSpecFromReader loads split BTF from a reader.
 //
 // Types from base are used to resolve references in the split BTF.