Skip to content

Commit 20cccef

Browse files
committed
testdata: loader - read from anonymous (global) constant
https://lore.kernel.org/bpf/CAK3+h2wcDceeGyFVDU3n7kPm=zgp7r1q4WK0=abxBsj9pyFN-g@mail.gmail.com Signed-off-by: Timo Beckers <[email protected]>
1 parent 9850db7 commit 20cccef

File tree

8 files changed

+29
-0
lines changed

8 files changed

+29
-0
lines changed

elf_reader_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ func TestLoadCollectionSpec(t *testing.T) {
131131
SectionName: "static",
132132
License: "MIT",
133133
},
134+
"anon_const": {
135+
Name: "anon_const",
136+
Type: SocketFilter,
137+
SectionName: "socket/4",
138+
License: "MIT",
139+
},
134140
},
135141
}
136142

testdata/loader-clang-14-eb.elf

1.05 KB
Binary file not shown.

testdata/loader-clang-14-el.elf

1.05 KB
Binary file not shown.

testdata/loader-clang-7-eb.elf

600 Bytes
Binary file not shown.

testdata/loader-clang-7-el.elf

600 Bytes
Binary file not shown.

testdata/loader-clang-9-eb.elf

1.09 KB
Binary file not shown.

testdata/loader-clang-9-el.elf

1.09 KB
Binary file not shown.

testdata/loader.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,26 @@ __section("socket/3") int data_sections() {
166166
return 0;
167167
}
168168
#endif
169+
170+
/*
171+
* Up until LLVM 14, this program results in an .rodata.cst32 section
172+
* that is accessed by 'return values[i]'. For this section, no BTF is
173+
* emitted. 'values' cannot be rewritten, since there is no BTF info
174+
* describing the data section.
175+
*/
176+
__section("socket/4") int anon_const() {
177+
volatile int ctx = 0;
178+
179+
// 32 bytes wide results in a .rodata.cst32 section.
180+
#define values \
181+
(uint64_t[]) { 0x0, 0x1, 0x2, 0x3 }
182+
183+
int i;
184+
for (i = 0; i < 3; i++) {
185+
if (ctx == values[i]) {
186+
return values[i];
187+
}
188+
}
189+
190+
return 0;
191+
}

0 commit comments

Comments
 (0)