Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
btf: add CO-RE read test that fails unless relocations were correctly…
… applied The linker rework in 9d739bd caused a piece of code that appended CORERelos to the entrypoint instruction stream to be forgotten. The existing CO-RE tests were all written in a way where the BPF programs would return 0 (success) if no CO-RE relocations were applied at all. This caused CO-RE relocations against functions (subprogs) that were only included by a bpf2bpf call to be skipped. This patch adds a broken test program that returns non-zero if left unaltered, and requires CO-RE relocation against another BTF blob to return 0. Additionally, the checks are performed from a non-inlined subprogram to ensure CO-RE relocations against subprogs work. Signed-off-by: Timo Beckers <timo@isovalent.com>
- Loading branch information
Showing
8 changed files
with
116 additions
and
2 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
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,37 @@ | ||
#include "../../../testdata/common.h" | ||
|
||
#define core_access __builtin_preserve_access_index | ||
|
||
// Struct with the members declared in the wrong order. Accesses need | ||
// a successful CO-RE relocation against the type in relocs_read_tgt.c | ||
// for the test below to pass. | ||
struct s { | ||
char b; | ||
char a; | ||
}; | ||
|
||
// Perform a read from a subprog to ensure CO-RE relocations | ||
// occurring there are tracked and executed in the final linked program. | ||
__attribute__((noinline)) int read_subprog() { | ||
struct s foo = { | ||
.a = 0, | ||
.b = 1, | ||
}; | ||
|
||
if (core_access(foo.a) == 0) | ||
return __LINE__; | ||
|
||
if (core_access(foo.b) == 1) | ||
return __LINE__; | ||
|
||
return 0; | ||
} | ||
|
||
__section("socket") int reads() { | ||
int ret = read_subprog(); | ||
if (ret) | ||
return ret; | ||
|
||
return 0; | ||
} | ||
|
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,16 @@ | ||
/* | ||
This file exists to emit ELFs with specific BTF types to use as target BTF | ||
in tests. It can be made redundant when btf.Spec can be handcrafted and | ||
passed as a CO-RE target in the future. | ||
*/ | ||
|
||
#define core_access __builtin_preserve_access_index | ||
|
||
struct s { | ||
char a; | ||
char b; | ||
}; | ||
|
||
int dummy() { | ||
return core_access((struct s){}.a); | ||
} |