Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

collection: Rename CollectionSpec.BTF to .Types, copy in Copy() #581

Merged
merged 2 commits into from Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/bpf2go/output.go
Expand Up @@ -255,7 +255,7 @@ func output(args outputArgs) error {
}

// Collect any types which we've been asked for explicitly.
cTypes, err := collectCTypes(spec.BTF, args.cTypes)
cTypes, err := collectCTypes(spec.Types, args.cTypes)
if err != nil {
return err
}
Expand Down
9 changes: 5 additions & 4 deletions collection.go
Expand Up @@ -27,8 +27,8 @@ type CollectionSpec struct {
Maps map[string]*MapSpec
Programs map[string]*ProgramSpec

// The BTF used by maps and programs.
BTF *btf.Spec
// Types holds type information about Maps and Programs.
Types *btf.Spec

// ByteOrder specifies whether the ELF was compiled for
// big-endian or little-endian architectures.
Expand All @@ -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,
Types: cs.Types.Copy(),
}

for name, spec := range cs.Maps {
Expand Down Expand Up @@ -412,7 +413,7 @@ func (cl *collectionLoader) loadMap(mapName string) (*Map, error) {
return nil, fmt.Errorf("missing map %s", mapName)
}

if mapSpec.BTF != nil && cl.coll.BTF != mapSpec.BTF.Spec {
if mapSpec.BTF != nil && cl.coll.Types != mapSpec.BTF.Spec {
return nil, fmt.Errorf("map %s: BTF doesn't match collection", mapName)
}

Expand Down Expand Up @@ -441,7 +442,7 @@ func (cl *collectionLoader) loadProgram(progName string) (*Program, error) {
return nil, fmt.Errorf("cannot load program %s: program type is unspecified", progName)
}

if progSpec.BTF != nil && cl.coll.BTF != progSpec.BTF.Spec() {
if progSpec.BTF != nil && cl.coll.Types != progSpec.BTF.Spec() {
return nil, fmt.Errorf("program %s: BTF doesn't match collection", progName)
}

Expand Down
6 changes: 6 additions & 0 deletions collection_test.go
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/cilium/ebpf/asm"
"github.com/cilium/ebpf/internal/btf"
"github.com/cilium/ebpf/internal/testutils"
)

Expand Down Expand Up @@ -66,6 +67,7 @@ func TestCollectionSpecCopy(t *testing.T) {
License: "MIT",
},
},
Types: &btf.Spec{},
}
cpy := cs.Copy()

Expand All @@ -80,6 +82,10 @@ func TestCollectionSpecCopy(t *testing.T) {
if cpy.Programs["test"] == cs.Programs["test"] {
t.Error("Copy returned same Programs")
}

if cpy.Types == cs.Types {
t.Error("Copy returned same Types")
}
}

func TestCollectionSpecRewriteMaps(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion elf_reader_test.go
Expand Up @@ -143,7 +143,7 @@ func TestLoadCollectionSpec(t *testing.T) {
return false
}),
cmpopts.IgnoreTypes(new(btf.Map), new(btf.Program)),
cmpopts.IgnoreFields(CollectionSpec{}, "ByteOrder", "BTF"),
cmpopts.IgnoreFields(CollectionSpec{}, "ByteOrder", "Types"),
cmpopts.IgnoreFields(ProgramSpec{}, "Instructions", "ByteOrder"),
cmpopts.IgnoreUnexported(ProgramSpec{}),
cmpopts.IgnoreMapEntries(func(key string, _ *MapSpec) bool {
Expand Down