From 9fda6d070d55b7f6e853abf2cb8980ef123016da Mon Sep 17 00:00:00 2001 From: Timo Beckers Date: Tue, 22 Feb 2022 15:33:30 +0100 Subject: [PATCH] collection: copy CollectionSpec.BTF in Copy() Without this, loading a copied CollectionSpec fails with: loading collection: map test: BTF doesn't match collection Signed-off-by: Timo Beckers --- collection.go | 1 + collection_test.go | 6 ++++++ 2 files changed, 7 insertions(+) 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) {