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

elf: Add support for map struct typedef #1125

Merged
merged 2 commits into from
Oct 10, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion elf_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ func (ec *elfCode) loadBTFMaps() error {
}

// Each Var representing a BTF map definition contains a Struct.
mapStruct, ok := v.Type.(*btf.Struct)
mapStruct, ok := btf.UnderlyingType(v.Type).(*btf.Struct)
if !ok {
return fmt.Errorf("expected struct, got %s", v.Type)
}
Expand Down
7 changes: 7 additions & 0 deletions elf_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ func TestLoadCollectionSpec(t *testing.T) {
MaxEntries: 1,
},
},
"btf_typedef_map": {
Name: "btf_typedef_map",
Type: Array,
KeySize: 4,
ValueSize: 8,
MaxEntries: 1,
},
},
Programs: map[string]*ProgramSpec{
"xdp_prog": {
Expand Down
Binary file modified testdata/loader-clang-11-eb.elf
Binary file not shown.
Binary file modified testdata/loader-clang-11-el.elf
Binary file not shown.
Binary file modified testdata/loader-clang-14-eb.elf
Binary file not shown.
Binary file modified testdata/loader-clang-14-el.elf
Binary file not shown.
Binary file modified testdata/loader-clang-17-eb.elf
Binary file not shown.
Binary file modified testdata/loader-clang-17-el.elf
Binary file not shown.
10 changes: 10 additions & 0 deletions testdata/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ struct bpf_map_def array_of_hash_map __section("maps") = {
.max_entries = 2,
};

typedef struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(key_size, sizeof(uint32_t));
__uint(value_size, sizeof(uint64_t));
__uint(max_entries, 1);
} array_map_t;

// Map definition behind a typedef.
array_map_t btf_typedef_map __section(".maps");

static int __attribute__((noinline)) __section("static") static_fn(uint32_t arg) {
return arg - 1;
}
Expand Down
Loading