Skip to content

Commit

Permalink
btf: add Array.Index
Browse files Browse the repository at this point in the history
The kernel refuses to load an array type without an index type, so probably
btf.rst is outdated.
  • Loading branch information
lmb committed May 27, 2022
1 parent ee95a07 commit 0f69484
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions btf/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func TestCOREAreTypesCompatible(t *testing.T) {
{&Int{Name: "a", Size: 2}, &Int{Name: "b", Size: 4}, true},
{&Pointer{Target: &Void{}}, &Pointer{Target: &Void{}}, true},
{&Pointer{Target: &Void{}}, &Void{}, false},
{&Array{Type: &Void{}}, &Array{Type: &Void{}}, true},
{&Array{Type: &Int{}}, &Array{Type: &Void{}}, false},
{&Array{Index: &Void{}, Type: &Void{}}, &Array{Index: &Void{}, Type: &Void{}}, true},
{&Array{Index: &Void{}, Type: &Int{}}, &Array{Index: &Void{}, Type: &Void{}}, false},
{&FuncProto{Return: &Int{}}, &FuncProto{Return: &Void{}}, false},
{
&FuncProto{Return: &Void{}, Params: []FuncParam{{Name: "a", Type: &Void{}}}},
Expand Down
15 changes: 9 additions & 6 deletions btf/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,22 @@ func (p *Pointer) copy() Type {

// Array is an array with a fixed number of elements.
type Array struct {
Index Type
Type Type
Nelems uint32
}

func (arr *Array) Format(fs fmt.State, verb rune) {
formatType(fs, verb, arr, "type=", arr.Type, "n=", arr.Nelems)
formatType(fs, verb, arr, "index=", arr.Index, "type=", arr.Type, "n=", arr.Nelems)
}

func (arr *Array) TypeName() string { return "" }

func (arr *Array) walk(tdq *typeDeque) { tdq.push(&arr.Type) }
func (arr *Array) walk(tdq *typeDeque) {
tdq.push(&arr.Index)
tdq.push(&arr.Type)
}

func (arr *Array) copy() Type {
cpy := *arr
return &cpy
Expand Down Expand Up @@ -904,10 +909,8 @@ func inflateRawTypes(rawTypes []rawType, rawStrings *stringTable) ([]Type, error

case kindArray:
btfArr := raw.data.(*btfArray)

// IndexType is unused according to btf.rst.
// Don't make it available right now.
arr := &Array{nil, btfArr.Nelems}
arr := &Array{nil, nil, btfArr.Nelems}
fixup(btfArr.IndexType, &arr.Index)
fixup(btfArr.Type, &arr.Type)
typ = arr

Expand Down

0 comments on commit 0f69484

Please sign in to comment.