libbpf: Put Kconfig externs into .kconfig section
Move Kconfig-provided externs into custom .kconfig section. Add __kconfig into bpf_helpers.h for user convenience. Update selftests accordingly. Suggested-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: Andrii Nakryiko <andriin@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20191219002837.3074619-2-andriin@fb.com
This commit is contained in:
committed by
Alexei Starovoitov
parent
d69587062c
commit
81bfdd087b
@@ -15,20 +15,18 @@ void test_skeleton(void)
|
||||
int duration = 0, err;
|
||||
struct test_skeleton* skel;
|
||||
struct test_skeleton__bss *bss;
|
||||
struct test_skeleton__externs *exts;
|
||||
struct test_skeleton__kconfig *kcfg;
|
||||
|
||||
skel = test_skeleton__open();
|
||||
if (CHECK(!skel, "skel_open", "failed to open skeleton\n"))
|
||||
return;
|
||||
|
||||
printf("EXTERNS BEFORE: %p\n", skel->externs);
|
||||
if (CHECK(skel->externs, "skel_externs", "externs are mmaped()!\n"))
|
||||
if (CHECK(skel->kconfig, "skel_kconfig", "kconfig is mmaped()!\n"))
|
||||
goto cleanup;
|
||||
|
||||
err = test_skeleton__load(skel);
|
||||
if (CHECK(err, "skel_load", "failed to load skeleton: %d\n", err))
|
||||
goto cleanup;
|
||||
printf("EXTERNS AFTER: %p\n", skel->externs);
|
||||
|
||||
bss = skel->bss;
|
||||
bss->in1 = 1;
|
||||
@@ -37,7 +35,7 @@ void test_skeleton(void)
|
||||
bss->in4 = 4;
|
||||
bss->in5.a = 5;
|
||||
bss->in5.b = 6;
|
||||
exts = skel->externs;
|
||||
kcfg = skel->kconfig;
|
||||
|
||||
err = test_skeleton__attach(skel);
|
||||
if (CHECK(err, "skel_attach", "skeleton attach failed: %d\n", err))
|
||||
@@ -55,10 +53,10 @@ void test_skeleton(void)
|
||||
CHECK(bss->handler_out5.b != 6, "res6", "got %lld != exp %d\n",
|
||||
bss->handler_out5.b, 6);
|
||||
|
||||
CHECK(bss->bpf_syscall != exts->CONFIG_BPF_SYSCALL, "ext1",
|
||||
"got %d != exp %d\n", bss->bpf_syscall, exts->CONFIG_BPF_SYSCALL);
|
||||
CHECK(bss->kern_ver != exts->LINUX_KERNEL_VERSION, "ext2",
|
||||
"got %d != exp %d\n", bss->kern_ver, exts->LINUX_KERNEL_VERSION);
|
||||
CHECK(bss->bpf_syscall != kcfg->CONFIG_BPF_SYSCALL, "ext1",
|
||||
"got %d != exp %d\n", bss->bpf_syscall, kcfg->CONFIG_BPF_SYSCALL);
|
||||
CHECK(bss->kern_ver != kcfg->LINUX_KERNEL_VERSION, "ext2",
|
||||
"got %d != exp %d\n", bss->kern_ver, kcfg->LINUX_KERNEL_VERSION);
|
||||
|
||||
cleanup:
|
||||
test_skeleton__destroy(skel);
|
||||
|
||||
@@ -10,16 +10,16 @@
|
||||
/* non-existing BPF helper, to test dead code elimination */
|
||||
static int (*bpf_missing_helper)(const void *arg1, int arg2) = (void *) 999;
|
||||
|
||||
extern int LINUX_KERNEL_VERSION;
|
||||
extern bool CONFIG_BPF_SYSCALL; /* strong */
|
||||
extern enum libbpf_tristate CONFIG_TRISTATE __weak;
|
||||
extern bool CONFIG_BOOL __weak;
|
||||
extern char CONFIG_CHAR __weak;
|
||||
extern uint16_t CONFIG_USHORT __weak;
|
||||
extern int CONFIG_INT __weak;
|
||||
extern uint64_t CONFIG_ULONG __weak;
|
||||
extern const char CONFIG_STR[8] __weak;
|
||||
extern uint64_t CONFIG_MISSING __weak;
|
||||
extern int LINUX_KERNEL_VERSION __kconfig;
|
||||
extern bool CONFIG_BPF_SYSCALL __kconfig; /* strong */
|
||||
extern enum libbpf_tristate CONFIG_TRISTATE __kconfig __weak;
|
||||
extern bool CONFIG_BOOL __kconfig __weak;
|
||||
extern char CONFIG_CHAR __kconfig __weak;
|
||||
extern uint16_t CONFIG_USHORT __kconfig __weak;
|
||||
extern int CONFIG_INT __kconfig __weak;
|
||||
extern uint64_t CONFIG_ULONG __kconfig __weak;
|
||||
extern const char CONFIG_STR[8] __kconfig __weak;
|
||||
extern uint64_t CONFIG_MISSING __kconfig __weak;
|
||||
|
||||
uint64_t kern_ver = -1;
|
||||
uint64_t bpf_syscall = -1;
|
||||
|
||||
@@ -21,8 +21,8 @@ char out3 = 0;
|
||||
long long out4 = 0;
|
||||
int out1 = 0;
|
||||
|
||||
extern bool CONFIG_BPF_SYSCALL;
|
||||
extern int LINUX_KERNEL_VERSION;
|
||||
extern bool CONFIG_BPF_SYSCALL __kconfig;
|
||||
extern int LINUX_KERNEL_VERSION __kconfig;
|
||||
bool bpf_syscall = 0;
|
||||
int kern_ver = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user