Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions btf/btf.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ func loadSpecFromELF(file *internal.SafeELFFile) (*Spec, error) {
return nil, err
}

if spec.decoder.byteOrder != file.ByteOrder {
return nil, fmt.Errorf("BTF byte order %s does not match ELF byte order %s", spec.decoder.byteOrder, file.ByteOrder)
if spec.byteOrder != file.ByteOrder {
return nil, fmt.Errorf("BTF byte order %s does not match ELF byte order %s", spec.byteOrder, file.ByteOrder)
}

spec.elf = &elfData{
Expand Down Expand Up @@ -350,7 +350,7 @@ func (s *Spec) Copy() *Spec {
}

cpy := &Spec{
s.decoder.Copy(),
s.decoder.copy(nil),
nil,
}

Expand All @@ -370,7 +370,7 @@ func (s *Spec) Copy() *Spec {
// Returns an error wrapping ErrNotFound if a Type with the given ID
// does not exist in the Spec.
func (s *Spec) TypeByID(id TypeID) (Type, error) {
typ, err := s.decoder.TypeByID(id)
typ, err := s.decoder.typeByID(id)
if err != nil {
return nil, fmt.Errorf("inflate type: %w", err)
}
Expand All @@ -386,7 +386,7 @@ func (s *Spec) TypeByID(id TypeID) (Type, error) {
//
// Returns an error wrapping [ErrNotFound] if the type isn't part of the Spec.
func (s *Spec) TypeID(typ Type) (TypeID, error) {
return s.decoder.TypeID(typ)
return s.decoder.typeID(typ)
}

// AnyTypesByName returns a list of BTF Types with the given name.
Expand All @@ -397,7 +397,7 @@ func (s *Spec) TypeID(typ Type) (TypeID, error) {
//
// Returns an error wrapping ErrNotFound if no matching Type exists in the Spec.
func (s *Spec) AnyTypesByName(name string) ([]Type, error) {
types, err := s.TypesByName(newEssentialName(name))
types, err := s.decoder.typesByName(newEssentialName(name))
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion btf/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func CORERelocate(relos []*CORERelocation, targets []*Spec, bo binary.ByteOrder,

var targetTypes []Type
for _, target := range targets {
namedTypes, err := target.TypesByName(essentialName)
namedTypes, err := target.typesByName(essentialName)
if errors.Is(err, ErrNotFound) {
continue
} else if err != nil {
Expand Down
24 changes: 8 additions & 16 deletions btf/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,7 @@ func allBtfTypeOffsets(buf []byte, bo binary.ByteOrder, header *btfType) iter.Se
}
}

// Copy performs a deep copy of a decoder and its base.
func (d *decoder) Copy() *decoder {
if d == nil {
return nil
}

return d.copy(nil)
}

// copy performs a deep copy of a decoder and its base.
func (d *decoder) copy(copiedTypes map[Type]Type) *decoder {
if d == nil {
return nil
Expand Down Expand Up @@ -217,8 +209,8 @@ func (d *decoder) copy(copiedTypes map[Type]Type) *decoder {
}
}

// TypeID returns the ID for a Type previously obtained via [TypeByID].
func (d *decoder) TypeID(typ Type) (TypeID, error) {
// typeID returns the ID for a Type previously obtained via [TypeByID].
func (d *decoder) typeID(typ Type) (TypeID, error) {
if _, ok := typ.(*Void); ok {
// Equality is weird for void, since it is a zero sized type.
return 0, nil
Expand All @@ -235,13 +227,13 @@ func (d *decoder) TypeID(typ Type) (TypeID, error) {
return id, nil
}

// TypesByName returns all types which have the given essential name.
// typesByName returns all types which have the given essential name.
//
// Returns ErrNotFound if no matching Type exists.
func (d *decoder) TypesByName(name essentialName) ([]Type, error) {
func (d *decoder) typesByName(name essentialName) ([]Type, error) {
var types []Type
for id := range d.namedTypes.Find(string(name)) {
typ, err := d.TypeByID(id)
typ, err := d.typeByID(id)
if err != nil {
return nil, err
}
Expand All @@ -261,8 +253,8 @@ func (d *decoder) TypesByName(name essentialName) ([]Type, error) {
return types, nil
}

// TypeByID decodes a type and any of its descendants.
func (d *decoder) TypeByID(id TypeID) (Type, error) {
// typeByID decodes a type and any of its descendants.
func (d *decoder) typeByID(id TypeID) (Type, error) {
d.mu.Lock()
defer d.mu.Unlock()

Expand Down
Loading