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
Make BTF for data sections optional #675
Changes from all commits
5dfc4e5
47418e6
38cabea
7d3d28d
d6b1820
09f3e22
352d2b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,6 +131,12 @@ func TestLoadCollectionSpec(t *testing.T) { | |
SectionName: "static", | ||
License: "MIT", | ||
}, | ||
"anon_const": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like there is no fix for the problem here, this means that the tests will fail on this commit? If yes, that's problematic when trying to bisect problems. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, didn't know we really cared about that, will respin the set to take this into account. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
Name: "anon_const", | ||
Type: SocketFilter, | ||
SectionName: "socket/4", | ||
License: "MIT", | ||
}, | ||
}, | ||
} | ||
|
||
|
@@ -148,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 | ||
}), | ||
} | ||
|
||
|
@@ -171,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) | ||
|
@@ -217,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) | ||
} | ||
}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() { | ||
|
@@ -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. | ||
|
@@ -166,3 +169,26 @@ __section("socket/3") int data_sections() { | |
return 0; | ||
} | ||
#endif | ||
|
||
/* | ||
* Up until LLVM 14, this program results in an .rodata.cst32 section | ||
* that is accessed by 'return values[i]'. For this section, no BTF is | ||
* emitted. 'values' cannot be rewritten, since there is no BTF info | ||
* describing the data section. | ||
*/ | ||
__section("socket/4") int anon_const() { | ||
volatile int ctx = 0; | ||
|
||
// 32 bytes wide results in a .rodata.cst32 section. | ||
#define values \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we just fake a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've tried all possible ways I could think of to force this to be emitted to a particular section, but haven't managed. Since it's not a real symbol, clang doesn't support setting the section attribute on it. |
||
(uint64_t[]) { 0x0, 0x1, 0x2, 0x3 } | ||
|
||
int i; | ||
for (i = 0; i < 3; i++) { | ||
if (ctx == values[i]) { | ||
return values[i]; | ||
} | ||
} | ||
|
||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we allow replacing the same variable in multiple rodata sections? Seems wonky.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reasoning behind not allowing it? Detecting compiler bugs? Technically, the same var being present in multiple rodata sections would also require having 2 equally-named ELF symbols with global vis, which is wonky indeed. So, we error here instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, added a check that makes sure we don't replace the same var twice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this could also happen when the caller copies .rodata from a CollectionSpec and adds it under a different key in
Maps
.