diff --git a/collection.go b/collection.go index 0e0dc5322..5febcab0e 100644 --- a/collection.go +++ b/collection.go @@ -45,6 +45,7 @@ func (cs *CollectionSpec) Copy() *CollectionSpec { Maps: make(map[string]*MapSpec, len(cs.Maps)), Programs: make(map[string]*ProgramSpec, len(cs.Programs)), ByteOrder: cs.ByteOrder, + BTF: cs.BTF.Copy(), } for name, spec := range cs.Maps { diff --git a/collection_test.go b/collection_test.go index 13ac84dbf..a7bffb3e8 100644 --- a/collection_test.go +++ b/collection_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/cilium/ebpf/asm" + "github.com/cilium/ebpf/internal/btf" "github.com/cilium/ebpf/internal/testutils" ) @@ -66,6 +67,7 @@ func TestCollectionSpecCopy(t *testing.T) { License: "MIT", }, }, + BTF: &btf.Spec{}, } cpy := cs.Copy() @@ -80,6 +82,10 @@ func TestCollectionSpecCopy(t *testing.T) { if cpy.Programs["test"] == cs.Programs["test"] { t.Error("Copy returned same Programs") } + + if cpy.BTF == cs.BTF { + t.Error("Copy returned same BTF") + } } func TestCollectionSpecRewriteMaps(t *testing.T) {