Skip to content

Commit

Permalink
testdata: loader - declare constant in custom .rodata.test section
Browse files Browse the repository at this point in the history
This exercises support for constants in custom .rodata* sections.

Signed-off-by: Timo Beckers <timo@isovalent.com>
  • Loading branch information
ti-mo committed May 23, 2022
1 parent 1ff15d2 commit 00ae3f2
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 10 deletions.
14 changes: 6 additions & 8 deletions elf_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,10 @@ func TestLoadCollectionSpec(t *testing.T) {
cmpopts.IgnoreFields(MapSpec{}, "Key", "Value"),
cmpopts.IgnoreUnexported(ProgramSpec{}),
cmpopts.IgnoreMapEntries(func(key string, _ *MapSpec) bool {
switch key {
case ".bss", ".data", ".rodata":
if key == ".bss" || key == ".data" || strings.HasPrefix(key, ".rodata") {
return true

default:
return false
}
return false
}),
}

Expand All @@ -177,9 +174,10 @@ func TestLoadCollectionSpec(t *testing.T) {
}

opts := defaultOpts
if have.Maps[".rodata"] != nil {
if have.Types != nil {
err := have.RewriteConstants(map[string]interface{}{
"arg": uint32(1),
"arg": uint32(1),
"arg2": uint32(2),
})
if err != nil {
t.Fatal("Can't rewrite constant:", err)
Expand Down Expand Up @@ -223,7 +221,7 @@ func TestLoadCollectionSpec(t *testing.T) {
t.Fatal("Can't run program:", err)
}

if ret != 5 {
if ret != 7 {
t.Error("Expected return value to be 5, got", ret)
}
})
Expand Down
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-7-eb.elf
Binary file not shown.
Binary file modified testdata/loader-clang-7-el.elf
Binary file not shown.
Binary file modified testdata/loader-clang-9-eb.elf
Binary file not shown.
Binary file modified testdata/loader-clang-9-el.elf
Binary file not shown.
7 changes: 5 additions & 2 deletions testdata/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ int __attribute__((noinline)) global_fn(uint32_t arg) {
static volatile unsigned int key1 = 0; // .bss
static volatile unsigned int key2 = 1; // .data
volatile const unsigned int key3 = 2; // .rodata
static volatile const uint32_t arg; // .rodata, rewritten by loader
static volatile const uint32_t arg; // .rodata, populated by loader
// custom .rodata section, populated by loader
static volatile const uint32_t arg2 __section(".rodata.test");
#endif

__section("xdp") int xdp_prog() {
Expand All @@ -121,11 +123,12 @@ __section("xdp") int xdp_prog() {
unsigned int key2 = 1;
unsigned int key3 = 2;
uint32_t arg = 1;
uint32_t arg2 = 2;
#endif
map_lookup_elem(&hash_map, (void *)&key1);
map_lookup_elem(&hash_map2, (void *)&key2);
map_lookup_elem(&hash_map2, (void *)&key3);
return static_fn(arg) + global_fn(arg);
return static_fn(arg) + global_fn(arg) + arg2;
}

// This function has no relocations, and is thus parsed differently.
Expand Down

0 comments on commit 00ae3f2

Please sign in to comment.