-
Notifications
You must be signed in to change notification settings - Fork 711
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
elf: detect map definitions with static qualifier
The following map definition static struct bpf_map_def foo __section("maps") = {...}; makes clang emit a relocation that points at the maps section, not at the foo symbol (even though foo is still present in the symbol table). The library currently doesn't recognize this and tries to find a map named "maps" at load time, which is pretty confusing. Try to detect the mistake by refusing direct map loads from the "maps" and ".maps" (for BTF-style definitions) sections. They will never succeed anyways.
- Loading branch information
Showing
6 changed files
with
47 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* This file excercises the ELF loader. It is not a valid BPF program. */ | ||
|
||
#include "common.h" | ||
|
||
struct bpf_map_def dummy __section("maps") = { | ||
.type = BPF_MAP_TYPE_HASH, | ||
.key_size = sizeof(uint32_t), | ||
.value_size = sizeof(uint64_t), | ||
.max_entries = 1, | ||
.map_flags = 0, | ||
}; | ||
|
||
/* The static qualifier leads to clang not emitting a symbol. */ | ||
static struct bpf_map_def hash_map __section("maps") = { | ||
.type = BPF_MAP_TYPE_HASH, | ||
.key_size = sizeof(uint32_t), | ||
.value_size = sizeof(uint64_t), | ||
.max_entries = 1, | ||
.map_flags = 0, | ||
}; | ||
|
||
__section("xdp") int xdp_prog() { | ||
uint32_t key = 0; | ||
void *p = map_lookup_elem(&hash_map, &key); | ||
return !!p; | ||
} |