linux-stable/tools/testing/selftests/bpf/prog_tests/linked_funcs.c
Andrii Nakryiko f2644fb44d selftests/bpf: Add function linking selftest
Add selftest validating various aspects of statically linking functions:
  - no conflicts and correct resolution for name-conflicting static funcs;
  - correct resolution of extern functions;
  - correct handling of weak functions, both resolution itself and libbpf's
    handling of unused weak function that "lost" (it leaves gaps in code with
    no ELF symbols);
  - correct handling of hidden visibility to turn global function into
    "static" for the purpose of BPF verification.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20210423181348.1801389-16-andrii@kernel.org
2021-04-23 14:05:27 -07:00

42 lines
1 KiB
C

// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2021 Facebook */
#include <test_progs.h>
#include <sys/syscall.h>
#include "linked_funcs.skel.h"
void test_linked_funcs(void)
{
int err;
struct linked_funcs *skel;
skel = linked_funcs__open();
if (!ASSERT_OK_PTR(skel, "skel_open"))
return;
skel->rodata->my_tid = syscall(SYS_gettid);
skel->bss->syscall_id = SYS_getpgid;
err = linked_funcs__load(skel);
if (!ASSERT_OK(err, "skel_load"))
goto cleanup;
err = linked_funcs__attach(skel);
if (!ASSERT_OK(err, "skel_attach"))
goto cleanup;
/* trigger */
syscall(SYS_getpgid);
ASSERT_EQ(skel->bss->output_val1, 2000 + 2000, "output_val1");
ASSERT_EQ(skel->bss->output_ctx1, SYS_getpgid, "output_ctx1");
ASSERT_EQ(skel->bss->output_weak1, 42, "output_weak1");
ASSERT_EQ(skel->bss->output_val2, 2 * 1000 + 2 * (2 * 1000), "output_val2");
ASSERT_EQ(skel->bss->output_ctx2, SYS_getpgid, "output_ctx2");
/* output_weak2 should never be updated */
ASSERT_EQ(skel->bss->output_weak2, 0, "output_weak2");
cleanup:
linked_funcs__destroy(skel);
}