Re: [PATCH bpf-next v1 01/14] selftests/bpf: Pass through build flags to bpftool and resolve_btfids

From: Ihor Solodrai

Date: Thu Feb 12 2026 - 19:09:15 EST


On 2/11/26 7:08 PM, Ihor Solodrai wrote:
>
>
> On 2/11/26 6:39 PM, Alexei Starovoitov wrote:
>> On Wed, Feb 11, 2026 at 5:14 PM Ihor Solodrai <ihor.solodrai@xxxxxxxxx> wrote:
>>>
>>> EXTRA_* and SAN_* build flags were not correctly propagated to bpftool
>>> and resolve_btids when building selftests/bpf. This led to various
>>> build errors on attempt to build with SAN_CFLAGS="-fsanitize=address",
>>> for example.
>>>
>>> Fix the makefiles to address this:
>>> - Pass SAN_CFLAGS/SAN_LDFLAGS to bpftool and resolve_btfids build
>>> - Propagate EXTRA_LDFLAGS to resolve_btfids link command
>>> - Use pkg-config to detect zlib and zstd for resolve_btfids, similar
>>> libelf handling
>>>
>>> Signed-off-by: Ihor Solodrai <ihor.solodrai@xxxxxxxxx>
>>> ---
>>> tools/bpf/resolve_btfids/Makefile | 7 +++++--
>>> tools/testing/selftests/bpf/Makefile | 9 +++++----
>>> 2 files changed, 10 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/tools/bpf/resolve_btfids/Makefile b/tools/bpf/resolve_btfids/Makefile
>>> index 1733a6e93a07..ef083602b73a 100644
>>> --- a/tools/bpf/resolve_btfids/Makefile
>>> +++ b/tools/bpf/resolve_btfids/Makefile
>>> @@ -65,6 +65,9 @@ $(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(LIBBPF_OU
>>> LIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libelf --cflags 2>/dev/null)
>>> LIBELF_LIBS := $(shell $(HOSTPKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf)
>>>
>>> +ZLIB_LIBS := $(shell $(HOSTPKG_CONFIG) zlib --libs 2>/dev/null || echo -lz)
>>> +ZSTD_LIBS := $(shell $(HOSTPKG_CONFIG) libzstd --libs 2>/dev/null || echo -lzstd)
>>
>> The first two patches look serious enough and justify going to bpf tree.
>> The rest can probably go via bpf as well, since we're early
>> in the merge window.
>> Would be great to have some Acks first though.
>>
>> Why add zstd here? It's not used by resolve_btfid. Why add it?
>
> IIRC zstd is a transitive dependency of libelf.
>
> I stumbled on a combination of build flags that caused link errors
> because of this missing. I can find or produce an example log later
> if that'd be helpful.

Reproduced the splat. See below.

Basically, the bug here was that building selftests/bpf with
EXTRA_LDFLAGS="-static" didn't propagate -static to resolve_btfids so
zstd and co were actually linked dynamically.

After I fixed the propagation of EXTRA_LDFLAGS, the static build of
selftests would fail on linking of resolve_btfids, because of -zstd
missing:

LINK resolve_btfids
/usr/bin/x86_64-linux-gnu-ld.bfd: /lib/x86_64-linux-gnu/libelf.a(elf_compress.o): in function `__libelf_compress':
(.text+0xe4): undefined reference to `ZSTD_createCCtx'
/usr/bin/x86_64-linux-gnu-ld.bfd: (.text+0x243): undefined reference to `ZSTD_compressStream2'
/usr/bin/x86_64-linux-gnu-ld.bfd: (.text+0x24e): undefined reference to `ZSTD_isError'
/usr/bin/x86_64-linux-gnu-ld.bfd: (.text+0x272): undefined reference to `ZSTD_freeCCtx'
/usr/bin/x86_64-linux-gnu-ld.bfd: (.text+0x4ff): undefined reference to `ZSTD_compressStream2'
/usr/bin/x86_64-linux-gnu-ld.bfd: (.text+0x50a): undefined reference to `ZSTD_isError'
/usr/bin/x86_64-linux-gnu-ld.bfd: (.text+0x6e1): undefined reference to `ZSTD_freeCCtx'
/usr/bin/x86_64-linux-gnu-ld.bfd: (.text+0x708): undefined reference to `ZSTD_freeCCtx'
/usr/bin/x86_64-linux-gnu-ld.bfd: (.text+0x78e): undefined reference to `ZSTD_freeCCtx'
/usr/bin/x86_64-linux-gnu-ld.bfd: (.text+0x828): undefined reference to `ZSTD_freeCCtx'
/usr/bin/x86_64-linux-gnu-ld.bfd: (.text+0x8f7): undefined reference to `ZSTD_freeCCtx'
/usr/bin/x86_64-linux-gnu-ld.bfd: /lib/x86_64-linux-gnu/libelf.a(elf_compress.o): in function `__libelf_decompress':
(.text+0xaf7): undefined reference to `ZSTD_decompress'
/usr/bin/x86_64-linux-gnu-ld.bfd: (.text+0xb02): undefined reference to `ZSTD_isError'
/usr/bin/x86_64-linux-gnu-ld.bfd: /lib/x86_64-linux-gnu/libelf.a(elf_compress.o): in function `__libelf_decompress_elf':
(.text+0xc37): undefined reference to `ZSTD_decompress'
/usr/bin/x86_64-linux-gnu-ld.bfd: (.text+0xc42): undefined reference to `ZSTD_isError'
clang-21: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [Makefile:89: /ws/linux/tools/testing/selftests/bpf/tools/build/resolve_btfids//resolve_btfids] Error 1
make: *** [Makefile:404: /ws/linux/tools/testing/selftests/bpf/tools/build/resolve_btfids/resolve_btfids] Error 2
make: *** Waiting for unfinished jobs....