All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next] selftests/bpf: Override EXTRA_LDFLAGS for static builds
@ 2026-05-13 11:24 Paul Chaignon
  2026-05-13 15:20 ` Jakub Sitnicki
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Paul Chaignon @ 2026-05-13 11:24 UTC (permalink / raw)
  To: bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Alexis Lothoré,
	Quentin Monnet

When running vmtest.sh with static linking, the bpftool_map_access
selftests fail. These selftests are calling the bpftool binary in
tools/sbin/ directly, which results in the following error:

    error while loading shared libraries: libLLVM.so.21.1:
      cannot open shared object file: No such file or directory

To fix this, we need to also build bpftool statically. That can be done
by setting EXTRA_LDFLAGS=-static.

Fixes: 2d96bbdfd3b5 ("selftests/bpf: convert test_bpftool_map_access.sh into test_progs framework")
Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com>
---
 tools/testing/selftests/bpf/README.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/README.rst b/tools/testing/selftests/bpf/README.rst
index 776fbe3cb8f9..37164322a102 100644
--- a/tools/testing/selftests/bpf/README.rst
+++ b/tools/testing/selftests/bpf/README.rst
@@ -77,7 +77,7 @@ In case of linker errors when running selftests, try using static linking:
 
 .. code-block:: console
 
-  $ LDLIBS=-static PKG_CONFIG='pkg-config --static' vmtest.sh
+  $ LDLIBS=-static EXTRA_LDFLAGS=-static PKG_CONFIG='pkg-config --static' vmtest.sh
 
 .. note:: Some distros may not support static linking.
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next] selftests/bpf: Override EXTRA_LDFLAGS for static builds
  2026-05-13 11:24 [PATCH bpf-next] selftests/bpf: Override EXTRA_LDFLAGS for static builds Paul Chaignon
@ 2026-05-13 15:20 ` Jakub Sitnicki
  2026-05-14  4:23 ` sashiko-bot
  2026-05-19  2:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 5+ messages in thread
From: Jakub Sitnicki @ 2026-05-13 15:20 UTC (permalink / raw)
  To: Paul Chaignon
  Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Alexis Lothoré,
	Quentin Monnet

On Wed, May 13, 2026 at 01:24:37PM +0200, Paul Chaignon wrote:
> When running vmtest.sh with static linking, the bpftool_map_access
> selftests fail. These selftests are calling the bpftool binary in
> tools/sbin/ directly, which results in the following error:
> 
>     error while loading shared libraries: libLLVM.so.21.1:
>       cannot open shared object file: No such file or directory
> 
> To fix this, we need to also build bpftool statically. That can be done
> by setting EXTRA_LDFLAGS=-static.
> 
> Fixes: 2d96bbdfd3b5 ("selftests/bpf: convert test_bpftool_map_access.sh into test_progs framework")
> Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com>
> ---

That seems to do the trick.

Reviewed-by: Jakub Sitnicki <jakub@cloudflare.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next] selftests/bpf: Override EXTRA_LDFLAGS for static builds
  2026-05-13 11:24 [PATCH bpf-next] selftests/bpf: Override EXTRA_LDFLAGS for static builds Paul Chaignon
  2026-05-13 15:20 ` Jakub Sitnicki
@ 2026-05-14  4:23 ` sashiko-bot
  2026-05-18 18:49   ` Paul Chaignon
  2026-05-19  2:10 ` patchwork-bot+netdevbpf
  2 siblings, 1 reply; 5+ messages in thread
From: sashiko-bot @ 2026-05-14  4:23 UTC (permalink / raw)
  To: Paul Chaignon; +Cc: bpf

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The suggested workaround `EXTRA_LDFLAGS=-static` in README.rst breaks the bpftool build or silently disables LLVM support.
--

commit dcbd0d5d7a0eb4a9300ad0890d83b7e4cdfd3aeb
Author: Paul Chaignon <paul.chaignon@gmail.com>

selftests/bpf: Override EXTRA_LDFLAGS for static builds

This commit updates the README.rst for BPF selftests to include
EXTRA_LDFLAGS=-static when recommending how to statically link,
in order to fix shared library loading errors with libLLVM.so
when running vmtest.sh.

> diff --git a/tools/testing/selftests/bpf/README.rst b/tools/testing/selftests/bpf/README.rst
> index 776fbe3cb8f9b..37164322a1023 100644
> --- a/tools/testing/selftests/bpf/README.rst
> +++ b/tools/testing/selftests/bpf/README.rst
> @@ -77,7 +77,7 @@ In case of linker errors when running selftests, try using static linking:
>  
>  .. code-block:: console
>  
> -  $ LDLIBS=-static PKG_CONFIG='pkg-config --static' vmtest.sh
> +  $ LDLIBS=-static EXTRA_LDFLAGS=-static PKG_CONFIG='pkg-config --static' vmtest.sh

Can adding EXTRA_LDFLAGS=-static break the bpftool build or silently disable
LLVM support?

In the bpftool Makefile, LLVM's --system-libs and -lstdc++ are only appended
to LIBS if llvm-config --shared-mode outputs 'static'. However, the
feature-llvm test in tools/build/feature/Makefile unconditionally includes
--system-libs and uses g++, which automatically includes -lstdc++.

If a system has static LLVM libraries but llvm-config --shared-mode is set
to 'shared' (common on many distros), the feature-llvm test statically links
successfully, but bpftool's Makefile will attempt to build with LLVM support
using gcc -static while omitting --system-libs and -lstdc++. This can cause
the build to fail with undefined references.

Additionally, if static LLVM libraries are entirely absent, the feature test
fails, causing bpftool to silently build without LLVM support.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/714556da329c812988010ffe53173d9152570a78.1778669303.git.paul.chaignon@gmail.com?part=1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next] selftests/bpf: Override EXTRA_LDFLAGS for static builds
  2026-05-14  4:23 ` sashiko-bot
@ 2026-05-18 18:49   ` Paul Chaignon
  0 siblings, 0 replies; 5+ messages in thread
From: Paul Chaignon @ 2026-05-18 18:49 UTC (permalink / raw)
  To: sashiko-reviews; +Cc: bpf

On Thu, May 14, 2026 at 04:23:04AM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] The suggested workaround `EXTRA_LDFLAGS=-static` in README.rst breaks the bpftool build or silently disables LLVM support.
> --
> 
> commit dcbd0d5d7a0eb4a9300ad0890d83b7e4cdfd3aeb
> Author: Paul Chaignon <paul.chaignon@gmail.com>
> 
> selftests/bpf: Override EXTRA_LDFLAGS for static builds
> 
> This commit updates the README.rst for BPF selftests to include
> EXTRA_LDFLAGS=-static when recommending how to statically link,
> in order to fix shared library loading errors with libLLVM.so
> when running vmtest.sh.
> 
> > diff --git a/tools/testing/selftests/bpf/README.rst b/tools/testing/selftests/bpf/README.rst
> > index 776fbe3cb8f9b..37164322a1023 100644
> > --- a/tools/testing/selftests/bpf/README.rst
> > +++ b/tools/testing/selftests/bpf/README.rst
> > @@ -77,7 +77,7 @@ In case of linker errors when running selftests, try using static linking:
> >  
> >  .. code-block:: console
> >  
> > -  $ LDLIBS=-static PKG_CONFIG='pkg-config --static' vmtest.sh
> > +  $ LDLIBS=-static EXTRA_LDFLAGS=-static PKG_CONFIG='pkg-config --static' vmtest.sh
> 
> Can adding EXTRA_LDFLAGS=-static break the bpftool build or silently disable
> LLVM support?
> 
> In the bpftool Makefile, LLVM's --system-libs and -lstdc++ are only appended
> to LIBS if llvm-config --shared-mode outputs 'static'. However, the
> feature-llvm test in tools/build/feature/Makefile unconditionally includes
> --system-libs and uses g++, which automatically includes -lstdc++.
> 
> If a system has static LLVM libraries but llvm-config --shared-mode is set
> to 'shared' (common on many distros), the feature-llvm test statically links
> successfully, but bpftool's Makefile will attempt to build with LLVM support
> using gcc -static while omitting --system-libs and -lstdc++. This can cause
> the build to fail with undefined references.

I'm not sure I'm following this, but I have static LLVM libraries with
llvm-config --shared-mode set to "shared" and everything seems to build
fine.

> 
> Additionally, if static LLVM libraries are entirely absent, the feature test
> fails, causing bpftool to silently build without LLVM support.
> 
> -- 
> Sashiko AI review · https://sashiko.dev/#/patchset/714556da329c812988010ffe53173d9152570a78.1778669303.git.paul.chaignon@gmail.com?part=1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next] selftests/bpf: Override EXTRA_LDFLAGS for static builds
  2026-05-13 11:24 [PATCH bpf-next] selftests/bpf: Override EXTRA_LDFLAGS for static builds Paul Chaignon
  2026-05-13 15:20 ` Jakub Sitnicki
  2026-05-14  4:23 ` sashiko-bot
@ 2026-05-19  2:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-05-19  2:10 UTC (permalink / raw)
  To: Paul Chaignon
  Cc: bpf, ast, daniel, andrii, eddyz87, memxor, alexis.lothore, qmo

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:

On Wed, 13 May 2026 13:24:37 +0200 you wrote:
> When running vmtest.sh with static linking, the bpftool_map_access
> selftests fail. These selftests are calling the bpftool binary in
> tools/sbin/ directly, which results in the following error:
> 
>     error while loading shared libraries: libLLVM.so.21.1:
>       cannot open shared object file: No such file or directory
> 
> [...]

Here is the summary with links:
  - [bpf-next] selftests/bpf: Override EXTRA_LDFLAGS for static builds
    https://git.kernel.org/bpf/bpf-next/c/879daba303f7

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-05-19  2:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-13 11:24 [PATCH bpf-next] selftests/bpf: Override EXTRA_LDFLAGS for static builds Paul Chaignon
2026-05-13 15:20 ` Jakub Sitnicki
2026-05-14  4:23 ` sashiko-bot
2026-05-18 18:49   ` Paul Chaignon
2026-05-19  2:10 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.