resolve_btfids: Drop -lzstd fallback if libzstd not found
Subsystems (3)
Ihor Solodrai
reviewerPATCH 1/1 resolve_btfids: Drop -lzstd fallback if libzstd not found
The "|| echo -lzstd" default makes zstd an unconditional link dependency of resolve_btfids. On systems where libzstd-dev is not installed and pkg-config fails, the linker fails:
ld: cannot find -lzstd: No such file or directory
libzstd is a transitive dependency of libelf, so the -lzstd flag is strictly necessary only for static builds [1].
Drop the -lzstd fallback to enable builds on systems without libzstd-dev installed.
--- tools/bpf/resolve_btfids/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/bpf/resolve_btfids/Makefile +1 -1
@@ -66,7 +66,7 @@ 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) +ZSTD_LIBS := $(shell $(HOSTPKG_CONFIG) libzstd --libs 2>/dev/null) HOSTCFLAGS_resolve_btfids += -g \ -I$(srctree)/tools/include \
Signature · 1 line
2.53.0
Quoted 26 lines · Ihor Solodrai
The "|| echo -lzstd" default makes zstd an unconditional link dependency of
resolve_btfids. On systems where libzstd-dev is not installed and pkg-config fails, the linker fails:ld: cannot find -lzstd: No such file or directory
libzstd is a transitive dependency of libelf, so the -lzstd flag is strictly necessary only for static builds [1].
Drop the -lzstd fallback to enable builds on systems without libzstd-dev installed.
Reported-by BPF CI Bot (Claude Opus 4.6) <[email protected]>Reported-by Vitaly Chikunov <[email protected]>Fixes 4021848a903e ("selftests/bpf: Pass through build flags to bpftool and resolve_btfids")Signed-off-by Ihor Solodrai <[email protected]>--- tools/bpf/resolve_btfids/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/bpf/resolve_btfids/Makefile +0
-0
tools/bpf/resolve_btfids/Makefile LIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libelf --cflags 2>/dev/null) · line 69
Quoted 5 lines
tools/bpf/resolve_btfids/Makefile +1
-1@@ -66,7 +66,7 @@ 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) +ZSTD_LIBS := $(shell $(HOSTPKG_CONFIG) libzstd --libs 2>/dev/null)
This change is currently failing in CI with "undefined reference to `ZSTD_xxx'" when trying to build resolve_btfids. I think this is happening because the selftests use static linking with PKG_CONFIG='pkg-config --static' but then the same isn't done for resolve_btfids, so "pkg-config libelf --libs" doesn't return -lzstd.
So maybe the solution is to define HOSTPKG_CONFIG when building resolve_btfids, as in the following diff:
tools/testing/selftests/bpf/Makefile +1 -0
@@ -409,6 +409,7 @@ $(RESOLVE_BTFIDS): $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/resolve_btfids \ CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)" \ LIBBPF_INCLUDE=$(HOST_INCLUDE_DIR) \ EXTRA_LDFLAGS='$(SAN_LDFLAGS) $(EXTRA_LDFLAGS)' \ + HOSTPKG_CONFIG=$(PKG_CONFIG) \ OUTPUT=$(HOST_BUILD_DIR)/resolve_btfids/ BPFOBJ=$(HOST_BPFOBJ) # Get Clang's default includes on this system, as opposed to those seen by
Quoted 7 lines
tools/bpf/resolve_btfids/Makefile +0
-0HOSTCFLAGS_resolve_btfids += -g \ -I$(srctree)/tools/include \Signature · 1 line
2.53.0
Ihor Solodrai
reviewerQuoted 29 lines · Paul Chaignon
Quoted 28 lines · Ihor Solodrai
The "|| echo -lzstd" default makes zstd an unconditional link dependency of
resolve_btfids. On systems where libzstd-dev is not installed and pkg-config fails, the linker fails:ld: cannot find -lzstd: No such file or directory
libzstd is a transitive dependency of libelf, so the -lzstd flag is strictly necessary only for static builds [1].
Drop the -lzstd fallback to enable builds on systems without libzstd-dev installed.
Reported-by BPF CI Bot (Claude Opus 4.6) <[email protected]>Reported-by Vitaly Chikunov <[email protected]>Fixes 4021848a903e ("selftests/bpf: Pass through build flags to bpftool and resolve_btfids")Signed-off-by Ihor Solodrai <[email protected]>--- tools/bpf/resolve_btfids/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/bpf/resolve_btfids/Makefile +0
-0@@ -66,7 +66,7 @@ LIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libelf --cflags 2>/dev/null) LIBELF_LIBS := $(shell $(HOSTPKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf)
Quoted 6 lines
tools/bpf/resolve_btfids/Makefile LIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libelf --cflags 2>/dev/null) · line 69
Quoted 3 lines
tools/bpf/resolve_btfids/Makefile +1
-1ZLIB_LIBS := $(shell $(HOSTPKG_CONFIG) zlib --libs 2>/dev/null || echo -lz) -ZSTD_LIBS := $(shell $(HOSTPKG_CONFIG) libzstd --libs 2>/dev/null || echo -lzstd) +ZSTD_LIBS := $(shell $(HOSTPKG_CONFIG) libzstd --libs 2>/dev/null)This change is currently failing in CI with "undefined reference to `ZSTD_xxx'" when trying to build
resolve_btfids. I think this is
Hi Paul, thanks for taking a look.
I'm aware, I sent a v2 yesterday (with changed subject):
https://lore.kernel.org/bpf/[email protected]/
Your diagnosis is correct, the HOSTPKG_CONFIG wasn't set. I fixed that by adding a default in resolve_btfids/Makefile, but your diff makes sense too, I think we should apply both.
Quoted 27 lines
happening because the selftests use static linking with PKG_CONFIG='pkg-config --static' but then the same isn't done for
resolve_btfids, so "pkg-config libelf --libs" doesn't return -lzstd.So maybe the solution is to define
HOSTPKG_CONFIGwhen buildingresolve_btfids, as in the following diff:tools/testing/selftests/bpf/Makefile +1
-0@@ -409,6 +409,7 @@ $(RESOLVE_BTFIDS): $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/resolve_btfids \ CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)" \ LIBBPF_INCLUDE=$(HOST_INCLUDE_DIR) \ EXTRA_LDFLAGS='$(SAN_LDFLAGS) $(EXTRA_LDFLAGS)' \ + HOSTPKG_CONFIG=$(PKG_CONFIG) \ OUTPUT=$(HOST_BUILD_DIR)/resolve_btfids/ BPFOBJ=$(HOST_BPFOBJ) # Get Clang's default includes on this system, as opposed to those seen byQuoted 8 lines
tools/bpf/resolve_btfids/Makefile +0
-0HOSTCFLAGS_resolve_btfids += -g \ -I$(srctree)/tools/include \Signature · 1 line
2.53.0
Quoted 37 lines · Ihor Solodrai
Quoted 29 lines · Paul Chaignon
Quoted 28 lines · Ihor Solodrai
The "|| echo -lzstd" default makes zstd an unconditional link dependency of
resolve_btfids. On systems where libzstd-dev is not installed and pkg-config fails, the linker fails:ld: cannot find -lzstd: No such file or directory
libzstd is a transitive dependency of libelf, so the -lzstd flag is strictly necessary only for static builds [1].
Drop the -lzstd fallback to enable builds on systems without libzstd-dev installed.
Reported-by BPF CI Bot (Claude Opus 4.6) <[email protected]>Reported-by Vitaly Chikunov <[email protected]>Fixes 4021848a903e ("selftests/bpf: Pass through build flags to bpftool and resolve_btfids")Signed-off-by Ihor Solodrai <[email protected]>--- tools/bpf/resolve_btfids/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/bpf/resolve_btfids/Makefile +0
-0@@ -66,7 +66,7 @@ LIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libelf --cflags 2>/dev/null) LIBELF_LIBS := $(shell $(HOSTPKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf)Quoted 6 lines
tools/bpf/resolve_btfids/Makefile LIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libelf --cflags 2>/dev/null) · line 69
Quoted 3 lines
tools/bpf/resolve_btfids/Makefile +1
-1ZLIB_LIBS := $(shell $(HOSTPKG_CONFIG) zlib --libs 2>/dev/null || echo -lz) -ZSTD_LIBS := $(shell $(HOSTPKG_CONFIG) libzstd --libs 2>/dev/null || echo -lzstd) +ZSTD_LIBS := $(shell $(HOSTPKG_CONFIG) libzstd --libs 2>/dev/null)This change is currently failing in CI with "undefined reference to `ZSTD_xxx'" when trying to build
resolve_btfids. I think this is
Quoted 4 lines
Hi Paul, thanks for taking a look.
I'm aware, I sent a v2 yesterday (with changed subject):
https://lore.kernel.org/bpf/[email protected]/
Ah, v1 was still marked as New in patchwork (probably due to changed subject) so I missed it wasn't the latest :')
Quoted 33 lines
Your diagnosis is correct, the
HOSTPKG_CONFIGwasn't set. I fixed that by adding a default in resolve_btfids/Makefile, but your diff makes sense too, I think we should apply both.Quoted 27 lines
happening because the selftests use static linking with PKG_CONFIG='pkg-config --static' but then the same isn't done for
resolve_btfids, so "pkg-config libelf --libs" doesn't return -lzstd.So maybe the solution is to define
HOSTPKG_CONFIGwhen buildingresolve_btfids, as in the following diff:tools/testing/selftests/bpf/Makefile +1
-0@@ -409,6 +409,7 @@ $(RESOLVE_BTFIDS): $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/resolve_btfids \ CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)" \ LIBBPF_INCLUDE=$(HOST_INCLUDE_DIR) \ EXTRA_LDFLAGS='$(SAN_LDFLAGS) $(EXTRA_LDFLAGS)' \ + HOSTPKG_CONFIG=$(PKG_CONFIG) \ OUTPUT=$(HOST_BUILD_DIR)/resolve_btfids/ BPFOBJ=$(HOST_BPFOBJ) # Get Clang's default includes on this system, as opposed to those seen byQuoted 8 lines
tools/bpf/resolve_btfids/Makefile +0
-0HOSTCFLAGS_resolve_btfids += -g \ -I$(srctree)/tools/include \Signature · 1 line
2.53.0