Skip to contentSkip to conversation

bpftool: Fix failure with static linkage

PATCH Superseded Leo Yan 5 participants 10 messages Dec 4, 2024 – Dec 10, 2024

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Leo Yan

author
#0 lore raw

PATCH 1/1 bpftool: Fix failure with static linkage

When building perf with static linkage:

make O=/build LDFLAGS="-static" -C tools/perf VF=1 DEBUG=1
...
LINK /build/util/bpf_skel/.tmp/bootstrap/bpftool
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/libelf.a(elf_compress.o): in function `__libelf_compress':
(.text+0x113): undefined reference to `ZSTD_createCCtx'
/usr/bin/ld: (.text+0x2a9): undefined reference to `ZSTD_compressStream2'
/usr/bin/ld: (.text+0x2b4): undefined reference to `ZSTD_isError'
/usr/bin/ld: (.text+0x2db): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x5a0): undefined reference to `ZSTD_compressStream2'
/usr/bin/ld: (.text+0x5ab): undefined reference to `ZSTD_isError'
/usr/bin/ld: (.text+0x6b9): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x835): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x86f): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x91b): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0xa12): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/libelf.a(elf_compress.o): in function `__libelf_decompress':
(.text+0xbfc): undefined reference to `ZSTD_decompress'
/usr/bin/ld: (.text+0xc04): undefined reference to `ZSTD_isError'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/libelf.a(elf_compress.o): in function `__libelf_decompress_elf':
(.text+0xd45): undefined reference to `ZSTD_decompress'
/usr/bin/ld: (.text+0xd4d): undefined reference to `ZSTD_isError'
collect2: error: ld returned 1 exit status

Building bpftool with static linkage also fails with the same errors:

make O=/build -C tools/bpf/bpftool/ V=1

To fix the issue, explicitly link libzstd.

---
 tools/bpf/bpftool/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/bpf/bpftool/Makefile +2 -2
index a4263dfb5e03..65b2671941e0 100644
@@ -130,8 +130,8 @@ include $(FEATURES_DUMP)
 endif
 endif
 
-LIBS = $(LIBBPF) -lelf -lz
-LIBS_BOOTSTRAP = $(LIBBPF_BOOTSTRAP) -lelf -lz
+LIBS = $(LIBBPF) -lelf -lz -lzstd
+LIBS_BOOTSTRAP = $(LIBBPF_BOOTSTRAP) -lelf -lz -lzstd
 ifeq ($(feature-libcap), 1)
 CFLAGS += -DUSE_LIBCAP
 LIBS += -lcap
Signature · 1 line
2.34.1
Tested-by on v1 1/1
#1 lore raw

Hi Leo,

Quoted 25 lines · Leo Yan

When building perf with static linkage:

make O=/build LDFLAGS="-static" -C tools/perf VF=1 DEBUG=1
...
LINK /build/util/bpf_skel/.tmp/bootstrap/bpftool
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/libelf.a(elf_compress.o): in function `__libelf_compress':
(.text+0x113): undefined reference to `ZSTD_createCCtx'
/usr/bin/ld: (.text+0x2a9): undefined reference to `ZSTD_compressStream2'
/usr/bin/ld: (.text+0x2b4): undefined reference to `ZSTD_isError'
/usr/bin/ld: (.text+0x2db): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x5a0): undefined reference to `ZSTD_compressStream2'
/usr/bin/ld: (.text+0x5ab): undefined reference to `ZSTD_isError'
/usr/bin/ld: (.text+0x6b9): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x835): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x86f): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x91b): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0xa12): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/libelf.a(elf_compress.o): in function `__libelf_decompress':
(.text+0xbfc): undefined reference to `ZSTD_decompress'
/usr/bin/ld: (.text+0xc04): undefined reference to `ZSTD_isError'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/libelf.a(elf_compress.o): in function `__libelf_decompress_elf':
(.text+0xd45): undefined reference to `ZSTD_decompress'
/usr/bin/ld: (.text+0xd4d): undefined reference to `ZSTD_isError'
collect2: error: ld returned 1 exit status

Quoted 5 lines

Building bpftool with static linkage also fails with the same errors:

make O=/build -C tools/bpf/bpftool/ V=1

To fix the issue, explicitly link libzstd.

I was about to report exactly the same. :)

Quoted 2 lines

Thanks,
Namhyung

Quoted 22 lines
---
 tools/bpf/bpftool/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/bpf/bpftool/Makefile +2 -2
index a4263dfb5e03..65b2671941e0 100644
@@ -130,8 +130,8 @@ include $(FEATURES_DUMP)
 endif
 endif
 
-LIBS = $(LIBBPF) -lelf -lz
-LIBS_BOOTSTRAP = $(LIBBPF_BOOTSTRAP) -lelf -lz
+LIBS = $(LIBBPF) -lelf -lz -lzstd
+LIBS_BOOTSTRAP = $(LIBBPF_BOOTSTRAP) -lelf -lz -lzstd
 ifeq ($(feature-libcap), 1)
 CFLAGS += -DUSE_LIBCAP
 LIBS += -lcap
Signature · 1 line
2.34.1
maintainer
#2 lore raw

2024-12-04 13:36 UTC-0800 ~ Namhyung Kim <[email protected]>

Quoted 28 lines

Hi Leo,

Quoted 25 lines · Leo Yan

When building perf with static linkage:

make O=/build LDFLAGS="-static" -C tools/perf VF=1 DEBUG=1
...
LINK /build/util/bpf_skel/.tmp/bootstrap/bpftool
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/libelf.a(elf_compress.o): in function `__libelf_compress':
(.text+0x113): undefined reference to `ZSTD_createCCtx'
/usr/bin/ld: (.text+0x2a9): undefined reference to `ZSTD_compressStream2'
/usr/bin/ld: (.text+0x2b4): undefined reference to `ZSTD_isError'
/usr/bin/ld: (.text+0x2db): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x5a0): undefined reference to `ZSTD_compressStream2'
/usr/bin/ld: (.text+0x5ab): undefined reference to `ZSTD_isError'
/usr/bin/ld: (.text+0x6b9): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x835): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x86f): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x91b): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0xa12): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/libelf.a(elf_compress.o): in function `__libelf_decompress':
(.text+0xbfc): undefined reference to `ZSTD_decompress'
/usr/bin/ld: (.text+0xc04): undefined reference to `ZSTD_isError'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/libelf.a(elf_compress.o): in function `__libelf_decompress_elf':
(.text+0xd45): undefined reference to `ZSTD_decompress'
/usr/bin/ld: (.text+0xd4d): undefined reference to `ZSTD_isError'
collect2: error: ld returned 1 exit status

Quoted 7 lines
Quoted 5 lines

Building bpftool with static linkage also fails with the same errors:

make O=/build -C tools/bpf/bpftool/ V=1

To fix the issue, explicitly link libzstd.

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).

Thanks,
Quentin

[0] https://github.com/libbpf/bpftool/issues/152
[1] https://github.com/libbpf/bpftool/issues/152#issuecomment-2343131810

#3 lore raw

Hello,

Quoted 40 lines · Quentin Monnet

2024-12-04 13:36 UTC-0800 ~ Namhyung Kim <[email protected]>

Quoted 28 lines

Hi Leo,

Quoted 25 lines · Leo Yan

When building perf with static linkage:

make O=/build LDFLAGS="-static" -C tools/perf VF=1 DEBUG=1
...
LINK /build/util/bpf_skel/.tmp/bootstrap/bpftool
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/libelf.a(elf_compress.o): in function `__libelf_compress':
(.text+0x113): undefined reference to `ZSTD_createCCtx'
/usr/bin/ld: (.text+0x2a9): undefined reference to `ZSTD_compressStream2'
/usr/bin/ld: (.text+0x2b4): undefined reference to `ZSTD_isError'
/usr/bin/ld: (.text+0x2db): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x5a0): undefined reference to `ZSTD_compressStream2'
/usr/bin/ld: (.text+0x5ab): undefined reference to `ZSTD_isError'
/usr/bin/ld: (.text+0x6b9): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x835): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x86f): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x91b): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0xa12): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/libelf.a(elf_compress.o): in function `__libelf_decompress':
(.text+0xbfc): undefined reference to `ZSTD_decompress'
/usr/bin/ld: (.text+0xc04): undefined reference to `ZSTD_isError'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/libelf.a(elf_compress.o): in function `__libelf_decompress_elf':
(.text+0xd45): undefined reference to `ZSTD_decompress'
/usr/bin/ld: (.text+0xd4d): undefined reference to `ZSTD_isError'
collect2: error: ld returned 1 exit status

Quoted 7 lines
Quoted 5 lines

Building bpftool with static linkage also fails with the same errors:

make O=/build -C tools/bpf/bpftool/ V=1

To fix the issue, explicitly link libzstd.

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.

Quoted 8 lines

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 

Thanks,
Namhyung

Quoted 3 lines

[0] https://github.com/libbpf/bpftool/issues/152
[1] https://github.com/libbpf/bpftool/issues/152#issuecomment-2343131810

maintainer
#4 lore raw

2024-12-04 14:25 UTC-0800 ~ Namhyung Kim <[email protected]>

Quoted 52 lines

Hello,

Quoted 40 lines · Quentin Monnet

2024-12-04 13:36 UTC-0800 ~ Namhyung Kim <[email protected]>

Quoted 28 lines

Hi Leo,

Quoted 25 lines · Leo Yan

When building perf with static linkage:

make O=/build LDFLAGS="-static" -C tools/perf VF=1 DEBUG=1
...
LINK /build/util/bpf_skel/.tmp/bootstrap/bpftool
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/libelf.a(elf_compress.o): in function `__libelf_compress':
(.text+0x113): undefined reference to `ZSTD_createCCtx'
/usr/bin/ld: (.text+0x2a9): undefined reference to `ZSTD_compressStream2'
/usr/bin/ld: (.text+0x2b4): undefined reference to `ZSTD_isError'
/usr/bin/ld: (.text+0x2db): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x5a0): undefined reference to `ZSTD_compressStream2'
/usr/bin/ld: (.text+0x5ab): undefined reference to `ZSTD_isError'
/usr/bin/ld: (.text+0x6b9): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x835): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x86f): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x91b): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0xa12): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/libelf.a(elf_compress.o): in function `__libelf_decompress':
(.text+0xbfc): undefined reference to `ZSTD_decompress'
/usr/bin/ld: (.text+0xc04): undefined reference to `ZSTD_isError'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/libelf.a(elf_compress.o): in function `__libelf_decompress_elf':
(.text+0xd45): undefined reference to `ZSTD_decompress'
/usr/bin/ld: (.text+0xd4d): undefined reference to `ZSTD_isError'
collect2: error: ld returned 1 exit status

Quoted 7 lines
Quoted 5 lines

Building bpftool with static linkage also fails with the same errors:

make O=/build -C tools/bpf/bpftool/ V=1

To fix the issue, explicitly link libzstd.

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.

Quoted 8 lines

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).

Quoted 5 lines

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 :)

Quentin

author
#5 lore raw

On Wed, Dec 04, 2024 at 10:55:32PM +0000, Quentin Monnet wrote:

[...]

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 1 line

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).

Quoted 6 lines
Quoted 4 lines

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

maintainer
#6 lore raw

2024-12-05 10:23 UTC+0000 ~ Leo Yan <[email protected]>

Quoted 23 lines · Quentin Monnet

[...]

Quoted 19 lines
Quoted 18 lines
Quoted 5 lines
Quoted 1 line

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.

Quoted 8 lines

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
Quoted 6 lines
Quoted 1 line

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.

Quoted 4 lines

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

#7 lore raw
In reply to Quentin Monnet
Quoted 41 lines · Quentin Monnet

2024-12-04 13:36 UTC-0800 ~ Namhyung Kim <[email protected]>

Quoted 28 lines

Hi Leo,

Quoted 25 lines · Leo Yan

When building perf with static linkage:

make O=/build LDFLAGS="-static" -C tools/perf VF=1 DEBUG=1
...
LINK /build/util/bpf_skel/.tmp/bootstrap/bpftool
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/libelf.a(elf_compress.o): in function `__libelf_compress':
(.text+0x113): undefined reference to `ZSTD_createCCtx'
/usr/bin/ld: (.text+0x2a9): undefined reference to `ZSTD_compressStream2'
/usr/bin/ld: (.text+0x2b4): undefined reference to `ZSTD_isError'
/usr/bin/ld: (.text+0x2db): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x5a0): undefined reference to `ZSTD_compressStream2'
/usr/bin/ld: (.text+0x5ab): undefined reference to `ZSTD_isError'
/usr/bin/ld: (.text+0x6b9): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x835): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x86f): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x91b): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0xa12): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/libelf.a(elf_compress.o): in function `__libelf_decompress':
(.text+0xbfc): undefined reference to `ZSTD_decompress'
/usr/bin/ld: (.text+0xc04): undefined reference to `ZSTD_isError'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/libelf.a(elf_compress.o): in function `__libelf_decompress_elf':
(.text+0xd45): undefined reference to `ZSTD_decompress'
/usr/bin/ld: (.text+0xd4d): undefined reference to `ZSTD_isError'
collect2: error: ld returned 1 exit status

Quoted 7 lines
Quoted 5 lines

Building bpftool with static linkage also fails with the same errors:

make O=/build -C tools/bpf/bpftool/ V=1

To fix the issue, explicitly link libzstd.

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.

Quoted 9 lines

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).

So what's the conclusion here? Do we apply this as a fix, or someone needs to add more feature probing?

Quoted 6 lines

Thanks,
Quentin

[0] https://github.com/libbpf/bpftool/issues/152
[1] https://github.com/libbpf/bpftool/issues/152#issuecomment-2343131810

author
#8 lore raw

Hi Andrii,

On Tue, Dec 10, 2024 at 10:26:22AM -0800, Andrii Nakryiko wrote:

[...]

Quoted 10 lines
Quoted 9 lines

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).

Quoted 2 lines

So what's the conclusion here? Do we apply this as a fix, or someone needs to add more feature probing?

I am working on a new build feature. Based on that, it will refine for perf build and bpftool build. Once get ready, I will send out for review.

Thanks,
Leo

#9 lore raw
In reply to Leo Yan
Quoted 54 lines · Leo Yan

When building perf with static linkage:

make O=/build LDFLAGS="-static" -C tools/perf VF=1 DEBUG=1
...
LINK /build/util/bpf_skel/.tmp/bootstrap/bpftool
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/libelf.a(elf_compress.o): in function `__libelf_compress':
(.text+0x113): undefined reference to `ZSTD_createCCtx'
/usr/bin/ld: (.text+0x2a9): undefined reference to `ZSTD_compressStream2'
/usr/bin/ld: (.text+0x2b4): undefined reference to `ZSTD_isError'
/usr/bin/ld: (.text+0x2db): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x5a0): undefined reference to `ZSTD_compressStream2'
/usr/bin/ld: (.text+0x5ab): undefined reference to `ZSTD_isError'
/usr/bin/ld: (.text+0x6b9): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x835): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x86f): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x91b): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: (.text+0xa12): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/libelf.a(elf_compress.o): in function `__libelf_decompress':
(.text+0xbfc): undefined reference to `ZSTD_decompress'
/usr/bin/ld: (.text+0xc04): undefined reference to `ZSTD_isError'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/libelf.a(elf_compress.o): in function `__libelf_decompress_elf':
(.text+0xd45): undefined reference to `ZSTD_decompress'
/usr/bin/ld: (.text+0xd4d): undefined reference to `ZSTD_isError'
collect2: error: ld returned 1 exit status

Building bpftool with static linkage also fails with the same errors:

make O=/build -C tools/bpf/bpftool/ V=1

To fix the issue, explicitly link libzstd.

---
 tools/bpf/bpftool/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/bpf/bpftool/Makefile +2 -2
index a4263dfb5e03..65b2671941e0 100644
@@ -130,8 +130,8 @@ include $(FEATURES_DUMP)
 endif
 endif
 
-LIBS = $(LIBBPF) -lelf -lz
-LIBS_BOOTSTRAP = $(LIBBPF_BOOTSTRAP) -lelf -lz
+LIBS = $(LIBBPF) -lelf -lz -lzstd
+LIBS_BOOTSTRAP = $(LIBBPF_BOOTSTRAP) -lelf -lz -lzstd
 ifeq ($(feature-libcap), 1)
 CFLAGS += -DUSE_LIBCAP
 LIBS += -lcap
Signature · 1 line
2.34.1

I'm not sure we 'offically' support -static builds, but this seems to be ok. Tangential: maybe time to switch to pkg-config for bpftool? IIRC, there is some flag to query for static lib dependencies... Will leave it up to Quentin.