Re: [PATCH bpf-next v3 2/2] selftests/bpf: test linking with duplicate extern functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Sep 30, 2024 at 8:55 PM Eric Long via B4 Relay
<devnull+i.hack3r.moe@xxxxxxxxxx> wrote:
>
> From: Eric Long <i@xxxxxxxxxx>
>
> Previously when multiple BPF object files referencing the same extern
> function (usually kfunc) are statically linked using `bpftool gen
> object`, libbpf tries to get the nonexistent size of BTF_KIND_FUNC_PROTO
> and fails. This test ensures it is fixed.
>
> Signed-off-by: Eric Long <i@xxxxxxxxxx>
> ---
>  tools/testing/selftests/bpf/Makefile                  |  3 ++-
>  .../selftests/bpf/prog_tests/dup_extern_funcs.c       |  9 +++++++++
>  tools/testing/selftests/bpf/progs/dup_extern_funcs1.c | 19 +++++++++++++++++++
>  tools/testing/selftests/bpf/progs/dup_extern_funcs2.c | 17 +++++++++++++++++
>  4 files changed, 47 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> index e295e3df5ec6c3c21abe368038514cfb34b42f69..644c4dd6002c691a9cd94ef26ddf51f6dc84e2cc 100644
> --- a/tools/testing/selftests/bpf/Makefile
> +++ b/tools/testing/selftests/bpf/Makefile
> @@ -496,7 +496,7 @@ SKEL_BLACKLIST := btf__% test_pinning_invalid.c test_sk_assign.c
>  LINKED_SKELS := test_static_linked.skel.h linked_funcs.skel.h          \

we already have linked_funcs.skel.h, let's add all this there, it sort
of matches (it's all functions, no?)

>                 linked_vars.skel.h linked_maps.skel.h                   \
>                 test_subskeleton.skel.h test_subskeleton_lib.skel.h     \
> -               test_usdt.skel.h
> +               test_usdt.skel.h dup_extern_funcs.skel.h
>
>  LSKELS := fentry_test.c fexit_test.c fexit_sleep.c atomics.c           \
>         trace_printk.c trace_vprintk.c map_ptr_kern.c                   \
> @@ -520,6 +520,7 @@ test_usdt.skel.h-deps := test_usdt.bpf.o test_usdt_multispec.bpf.o
>  xsk_xdp_progs.skel.h-deps := xsk_xdp_progs.bpf.o
>  xdp_hw_metadata.skel.h-deps := xdp_hw_metadata.bpf.o
>  xdp_features.skel.h-deps := xdp_features.bpf.o
> +dup_extern_funcs.skel.h-deps := dup_extern_funcs1.bpf.o dup_extern_funcs2.bpf.o
>
>  LINKED_BPF_OBJS := $(foreach skel,$(LINKED_SKELS),$($(skel)-deps))
>  LINKED_BPF_SRCS := $(patsubst %.bpf.o,%.c,$(LINKED_BPF_OBJS))
> diff --git a/tools/testing/selftests/bpf/prog_tests/dup_extern_funcs.c b/tools/testing/selftests/bpf/prog_tests/dup_extern_funcs.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..b26f855745b451f7f53e44b27d47a2f659ad1378
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/dup_extern_funcs.c
> @@ -0,0 +1,9 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#include <test_progs.h>
> +#include "dup_extern_funcs.skel.h"
> +
> +void test_dup_extern_funcs(void)
> +{
> +       RUN_TESTS(dup_extern_funcs);
> +}
> diff --git a/tools/testing/selftests/bpf/progs/dup_extern_funcs1.c b/tools/testing/selftests/bpf/progs/dup_extern_funcs1.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..a5b6ea361c3d457d48bc562040f1ef946fadfc81
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/dup_extern_funcs1.c
> @@ -0,0 +1,19 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#include "vmlinux.h"
> +#include <bpf/bpf_helpers.h>
> +
> +char _license[] SEC("license") = "GPL";
> +
> +void *bpf_cast_to_kern_ctx(void *obj) __ksym;
> +
> +SEC("tc")
> +int handler1(struct __sk_buff *skb)
> +{
> +       struct sk_buff *skb_kern = bpf_cast_to_kern_ctx(skb);
> +
> +       if (!skb_kern)
> +               return -1;
> +
> +       return 0;
> +}
> diff --git a/tools/testing/selftests/bpf/progs/dup_extern_funcs2.c b/tools/testing/selftests/bpf/progs/dup_extern_funcs2.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..2f9f63dcc6ed2a35e82b55da54356502cfc95c9d
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/dup_extern_funcs2.c
> @@ -0,0 +1,17 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#include "vmlinux.h"
> +#include <bpf/bpf_helpers.h>
> +
> +void *bpf_cast_to_kern_ctx(void *obj) __ksym;
> +
> +SEC("xdp")
> +int handler2(struct xdp_md *xdp)
> +{
> +       struct xdp_buff *xdp_kern = bpf_cast_to_kern_ctx(xdp);
> +
> +       if (!xdp_kern)
> +               return -1;
> +
> +       return 0;
> +}
>
> --
> 2.46.2
>
>





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux