Commit b82bb1ff authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Alexei Starovoitov

selftests/bpf: Add CO-RE relos and SEC("?...") to linked_funcs selftests

Enhance linked_funcs selftest with two tricky features that might not
obviously work correctly together. We add CO-RE relocations to entry BPF
programs and mark those programs as non-autoloadable with SEC("?...")
annotation. This makes sure that libbpf itself handles .BTF.ext CO-RE
relocation data matching correctly for SEC("?...") programs, as well as
ensures that BPF static linker handles this correctly (this was the case
before, no changes are necessary, but it wasn't explicitly tested).
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20220426004511.2691730-6-andrii@kernel.org
parent 11d5daa8
...@@ -14,6 +14,12 @@ void test_linked_funcs(void) ...@@ -14,6 +14,12 @@ void test_linked_funcs(void)
if (!ASSERT_OK_PTR(skel, "skel_open")) if (!ASSERT_OK_PTR(skel, "skel_open"))
return; return;
/* handler1 and handler2 are marked as SEC("?raw_tp/sys_enter") and
* are set to not autoload by default
*/
bpf_program__set_autoload(skel->progs.handler1, true);
bpf_program__set_autoload(skel->progs.handler2, true);
skel->rodata->my_tid = syscall(SYS_gettid); skel->rodata->my_tid = syscall(SYS_gettid);
skel->bss->syscall_id = SYS_getpgid; skel->bss->syscall_id = SYS_getpgid;
......
...@@ -61,12 +61,17 @@ extern int set_output_val2(int x); ...@@ -61,12 +61,17 @@ extern int set_output_val2(int x);
/* here we'll force set_output_ctx2() to be __hidden in the final obj file */ /* here we'll force set_output_ctx2() to be __hidden in the final obj file */
__hidden extern void set_output_ctx2(__u64 *ctx); __hidden extern void set_output_ctx2(__u64 *ctx);
SEC("raw_tp/sys_enter") SEC("?raw_tp/sys_enter")
int BPF_PROG(handler1, struct pt_regs *regs, long id) int BPF_PROG(handler1, struct pt_regs *regs, long id)
{ {
static volatile int whatever;
if (my_tid != (u32)bpf_get_current_pid_tgid() || id != syscall_id) if (my_tid != (u32)bpf_get_current_pid_tgid() || id != syscall_id)
return 0; return 0;
/* make sure we have CO-RE relocations in main program */
whatever = bpf_core_type_size(struct task_struct);
set_output_val2(1000); set_output_val2(1000);
set_output_ctx2(ctx); /* ctx definition is hidden in BPF_PROG macro */ set_output_ctx2(ctx); /* ctx definition is hidden in BPF_PROG macro */
......
...@@ -61,12 +61,17 @@ extern int set_output_val1(int x); ...@@ -61,12 +61,17 @@ extern int set_output_val1(int x);
/* here we'll force set_output_ctx1() to be __hidden in the final obj file */ /* here we'll force set_output_ctx1() to be __hidden in the final obj file */
__hidden extern void set_output_ctx1(__u64 *ctx); __hidden extern void set_output_ctx1(__u64 *ctx);
SEC("raw_tp/sys_enter") SEC("?raw_tp/sys_enter")
int BPF_PROG(handler2, struct pt_regs *regs, long id) int BPF_PROG(handler2, struct pt_regs *regs, long id)
{ {
static volatile int whatever;
if (my_tid != (u32)bpf_get_current_pid_tgid() || id != syscall_id) if (my_tid != (u32)bpf_get_current_pid_tgid() || id != syscall_id)
return 0; return 0;
/* make sure we have CO-RE relocations in main program */
whatever = bpf_core_type_size(struct task_struct);
set_output_val1(2000); set_output_val1(2000);
set_output_ctx1(ctx); /* ctx definition is hidden in BPF_PROG macro */ set_output_ctx1(ctx); /* ctx definition is hidden in BPF_PROG macro */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment