Re: [PATCH] bpftool: Fix failure with static linkage

Quentin Monnet
2024-12-05T10:58:10Z

2024-12-05 10:23 UTC+0000 ~ Leo Yan <leo.yan@arm.com>
> On Wed, Dec 04, 2024 at 10:55:32PM +0000, Quentin Monnet wrote:
>
> [...]
>
>>>>> I was about to report exactly the same. :)
>>>>
>>>> Thank you both. This has been reported before [0] but I didn't find the
>>>> time to look into a proper fix.
>>>>
>>>> The tricky part is that static linkage works well without libzstd for
>>>> older versions of elfutils [1], but newer versions now require this
>>>> library. Which means that we don't want to link against libzstd
>>>> unconditionally, or users trying to build bpftool may have to install
>>>> unnecessary dependencies. Instead we should add a new probe under
>>>> tools/build/feature (Note that we already have several combinations in
>>>> there, libbfd, libbfd-liberty, libbfd-liberty-z, and I'm not sure what's
>>>> the best approach in terms of new combinations).
>>>
>>> I think you can use pkg-config if available.
>>>
>>> $ pkg-config --static --libs libelf
>>> -lelf -lz -lzstd -pthread
>>
>> That's another dependency that I'd like to avoid if I can :)
>
> Seems to me, pkg-config is the right tool for doing such kind thing -
> not only it is nature for local building, it is also friendly for build
> system (e.g. buildroot, OpenEmbedded / Yocto). Though I have no deep
> knowledge for building.

pkg-config would be nice but is not always installed by default. We've
been handling build options without it so far, if we can fix the current
issue without struggling too much with probes I'd just as well avoid
adding a build dependency.

> I am a bit confused why this issue is related to build features libbfd,
> libbfd-liberty, libbfd-liberty-z. Should not the issue is related to
> libelf? build/feature has several libelf checking, maybe we can add new
> one libelf-zstd?

Apologies, I was the one getting confused. You're correct, this affects
libelf and not libbfd, and yes libelf-zstd is likely the way to go.

Thank you,
Quentin