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

From: Leo Yan
Date: Thu Dec 05 2024 - 05:24:23 EST


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.

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?

Thanks,
Leo