From: Vitaly Chikunov <vt@altlinux.org>
To: Ihor Solodrai <ihor.solodrai@linux.dev>
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
bpf@vger.kernel.org, kernel-team@meta.com
Subject: Re: [PATCH bpf v2] resolve_btfids: Fix linker flags detection
Date: Tue, 3 Mar 2026 23:06:20 +0300 [thread overview]
Message-ID: <aac-hefhJ8znydSb@altlinux.org> (raw)
In-Reply-To: <20260303193954.1879948-1-ihor.solodrai@linux.dev>
Ihor,
On Tue, Mar 03, 2026 at 11:39:54AM -0800, Ihor Solodrai wrote:
> The "|| echo -lzstd" default makes zstd an unconditional link
> dependency of resolve_btfids. On systems where libzstd-dev is not
> installed and pkg-config fails, the linker fails:
>
> ld: cannot find -lzstd: No such file or directory
>
> libzstd is a transitive dependency of libelf, so the -lzstd flag is
> strictly necessary only for static builds [1].
>
> Remove ZSTD_LIBS variable, and instead set LIBELF_LIBS depending on
> whether the build is static or not. Use $(HOSTPKG_CONFIG) as primary
> source of the flags list.
>
> Also add a default value for HOSTPKG_CONFIG in case it's not built via
> the toplevel Makefile.
>
> [1] https://lore.kernel.org/bpf/4ff82800-2daa-4b9f-95a9-6f512859ee70@linux.dev/
>
> Reported-by: BPF CI Bot (Claude Opus 4.6) <bot+bpf-ci@kernel.org>
> Reported-by: Vitaly Chikunov <vt@altlinux.org>
> Closes: https://lore.kernel.org/bpf/aaWqMcK-2AQw5dx8@altlinux.org/
> Fixes: 4021848a903e ("selftests/bpf: Pass through build flags to bpftool and resolve_btfids")
> Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
>
> ---
>
> v1: https://lore.kernel.org/bpf/20260302231058.916946-1-ihor.solodrai@linux.dev/
>
> ---
> tools/bpf/resolve_btfids/Makefile | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/tools/bpf/resolve_btfids/Makefile b/tools/bpf/resolve_btfids/Makefile
> index ef083602b73a..7672208f65e4 100644
> --- a/tools/bpf/resolve_btfids/Makefile
> +++ b/tools/bpf/resolve_btfids/Makefile
> @@ -23,6 +23,7 @@ RM ?= rm
> HOSTCC ?= gcc
> HOSTLD ?= ld
> HOSTAR ?= ar
> +HOSTPKG_CONFIG ?= pkg-config
> CROSS_COMPILE =
>
> OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/
> @@ -63,10 +64,14 @@ $(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(LIBBPF_OU
> $(abspath $@) install_headers
>
> LIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libelf --cflags 2>/dev/null)
> +
> +ifneq ($(filter -static,$(EXTRA_LDFLAGS)),)
> +LIBELF_LIBS := $(shell $(HOSTPKG_CONFIG) libelf --libs --static 2>/dev/null || echo -lelf -lzstd)
> +else
> LIBELF_LIBS := $(shell $(HOSTPKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf)
> +endif
>
> ZLIB_LIBS := $(shell $(HOSTPKG_CONFIG) zlib --libs 2>/dev/null || echo -lz)
Perhaps, this line is not needed either, as `pkg-config libelf --libs
--static` will add -lz.
Thanks,
> -ZSTD_LIBS := $(shell $(HOSTPKG_CONFIG) libzstd --libs 2>/dev/null || echo -lzstd)
>
> HOSTCFLAGS_resolve_btfids += -g \
> -I$(srctree)/tools/include \
> @@ -76,7 +81,7 @@ HOSTCFLAGS_resolve_btfids += -g \
> $(LIBELF_FLAGS) \
> -Wall -Werror
>
> -LIBS = $(LIBELF_LIBS) $(ZLIB_LIBS) $(ZSTD_LIBS)
> +LIBS = $(LIBELF_LIBS) $(ZLIB_LIBS)
>
> export srctree OUTPUT HOSTCFLAGS_resolve_btfids Q HOSTCC HOSTLD HOSTAR
> include $(srctree)/tools/build/Makefile.include
> --
> 2.53.0
next prev parent reply other threads:[~2026-03-03 20:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-03 19:39 [PATCH bpf v2] resolve_btfids: Fix linker flags detection Ihor Solodrai
2026-03-03 20:06 ` Vitaly Chikunov [this message]
2026-03-03 20:17 ` Ihor Solodrai
2026-03-04 19:47 ` Vitaly Chikunov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aac-hefhJ8znydSb@altlinux.org \
--to=vt@altlinux.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=ihor.solodrai@linux.dev \
--cc=kernel-team@meta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox