Re: [PATCH bpf v3 01/15] selftests/bpf: Pass through build flags to bpftool and resolve_btfids
From: Ihor Solodrai
Date: Mon Mar 02 2026 - 13:03:22 EST
On 3/2/26 7:22 AM, Vitaly Chikunov wrote:
> Ihor,
>
> On Fri, Feb 20, 2026 at 08:23:51PM -0800, Ihor Solodrai wrote:
>>
>>
>> On 2/20/26 2:57 PM, bot+bpf-ci@xxxxxxxxxx wrote:
>>>> 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 "|| echo -lzstd" fallback makes zstd an unconditional link
>>> dependency. On systems where libzstd-dev is not installed, pkg-config
>>> fails and the fallback provides -lzstd, but the linker cannot find the
>>> library and the build fails.
>>>
>>> bpftool handles the same transitive dependency conditionally via a
>>> feature test:
>>>
>>> tools/bpf/bpftool/Makefile:
>>> ifeq ($(feature-libelf-zstd),1)
>>> LIBS += -lzstd
>>> LIBS_BOOTSTRAP += -lzstd
>>> endif
>>>
>>> Would it be safer to drop the fallback here so ZSTD_LIBS is empty
>>> when zstd is not available?
>>>
>>> ZSTD_LIBS := $(shell $(HOSTPKG_CONFIG) libzstd --libs 2>/dev/null)
>>>
>>> This would still link zstd when present (needed for the static linking
>>> case where libelf.a pulls in ZSTD symbols from elf_compress.o), but
>>> avoid breaking dynamic builds on systems without libzstd-dev.
>>
>> [...]
>>
>>
>> So, while AI may be technically correct that the build will fail if
>> libelf is installed and libzstd is not, it seems a far-fetched
>> situation, given that libelf depends on libzstd.
>
> This is not far-fetched, and we have build failure for v7.0-rc2 due to
> this.
>
> ld: cannot find -lzstd: No such file or directory
>
> Even though libelf is linked with libzstd, this does not imply
> libzstd-devel (with headers and so library) is there when building.
Does AI's suggestion make sense in your case then?
That is, make ZSTD_LIBS empty in case pkg-config didn't find libzstd?
I'm happy to fix this, the build shouldn't fail unless it must.
But I am curious how and why an environment building Linux with BTF
(requiring build and run of resolve_btfids), which needs libelf-dev
and presumably its dependencies, would exclude/avoid installing
libzstd-dev?
Thanks.
>
> Thanks,
>
>>
>> I think we can leave the default -lzstd to have an explicit
>> dependency in the Makefile.
>>
>>
>>>
>>> [ ... ]