Skip to contentSkip to conversation

tools build: Fixes for libbfd -lzstd dependency

PATCH Superseded Ian Rogers 5 participants 15 messages Sep 9 – Sep 10

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

v2 cover tools build: Fixes for libbfd -lzstd dependency

This is a fuller set of patches from v1 addressing build problems linking with libbfd when zstd is a dependency. The original issue was exposed on Fedora with perf's build-test. This series separates the build from the perf changes and adds in bpftool and objtool fixes caught by Sashiko. The changes follow the pattern used by the zlib -lz dependency and so appear correct but are untested.

v1: https://lore.kernel.org/linux-perf-users/[email protected]/

Ian Rogers (4):
tools build: Add explicitly sequenced -lzstd to libbfd feature
fallback
perf build: Add explicitly sequenced -lzstd to libbfd feature fallback
bpftool: Add explicitly sequenced -lzstd to libbfd feature fallback
objtool: Add explicitly sequenced -lzstd to libopcodes fallback

 tools/bpf/bpftool/Makefile   |  4 ++++
 tools/build/Makefile.feature |  3 ++-
 tools/build/feature/Makefile | 12 +++++++++---
 tools/objtool/Makefile       |  3 ++-
 tools/perf/Makefile.config   |  3 +++
 5 files changed, 20 insertions(+), 5 deletions(-)
Signature · 1 line
2.55.0.1003.g10538fe699-goog
author reviewer
#1 lore raw

PATCH v2 1/4 tools build: Add explicitly sequenced -lzstd to libbfd feature fallback

Distributions like Fedora currently ship a statically compiled binutils libbfd that natively depends on zstd to decompress sections (e.g. undefined reference to 'ZSTD_decompress').

Extend the testing cascade in tools/build/feature/Makefile to natively probe for '-lz -lzstd' when the basic fallback variants fail. This adds the generic framework for referencing static binutils across all tools.

Assisted-by Antigravity:gemini-3.1-pro
---
 tools/build/Makefile.feature |  3 ++-
 tools/build/feature/Makefile | 12 +++++++++---
 2 files changed, 11 insertions(+), 4 deletions(-)
tools/build/Makefile.feature +2 -1
index 99eb0ea09537..1268ac6f130e 100644
@@ -121,6 +121,7 @@ FEATURE_TESTS_EXTRA :=                  \
          libcheck                       \
          libbfd-liberty                 \
          libbfd-liberty-z               \
+         libbfd-liberty-z-zstd          \
          libopencsd                     \
          libperl                        \
          llvm                           \
@@ -161,7 +162,7 @@ FEATURE_DISPLAY ?=              \
 # Declare group members of a feature to display the logical OR of the detection
 # result instead of each member result.
 #
-FEATURE_GROUP_MEMBERS-libbfd = libbfd-liberty libbfd-liberty-z
+FEATURE_GROUP_MEMBERS-libbfd = libbfd-liberty libbfd-liberty-z libbfd-liberty-z-zstd
 
 #
 # Declare list of feature dependency packages that provide pkg-config files.
tools/build/feature/Makefile +9 -3
index 7d165018116a..410987df3a48 100644
@@ -21,6 +21,7 @@ FILES=                                          \
          test-reallocarray.bin			\
          test-libbfd-liberty.bin                \
          test-libbfd-liberty-z.bin              \
+         test-libbfd-liberty-z-zstd.bin         \
          test-cplus-demangle.bin                \
          test-cxa-demangle.bin                  \
          test-libcap.bin			\
@@ -272,15 +273,17 @@ $(OUTPUT)test-libbfd.bin:
 	$(BUILD_BFD)
 
 $(OUTPUT)test-libbfd-threadsafe.bin:
-	$(BUILD_BFD) || $(BUILD_BFD) -liberty || $(BUILD_BFD) -liberty -lz
+	$(BUILD_BFD) || $(BUILD_BFD) -liberty || $(BUILD_BFD) -liberty -lz || $(BUILD_BFD) -liberty -lz -lzstd
 
 $(OUTPUT)test-disassembler-four-args.bin:
 	$(BUILD_BFD) -lopcodes || $(BUILD_BFD) -lopcodes -liberty || \
-	$(BUILD_BFD) -lopcodes -liberty -lz
+	$(BUILD_BFD) -lopcodes -liberty -lz || \
+	$(BUILD_BFD) -lopcodes -liberty -lz -lzstd
 
 $(OUTPUT)test-disassembler-init-styled.bin:
 	$(BUILD_BFD) -lopcodes || $(BUILD_BFD) -lopcodes -liberty || \
-	$(BUILD_BFD) -lopcodes -liberty -lz
+	$(BUILD_BFD) -lopcodes -liberty -lz || \
+	$(BUILD_BFD) -lopcodes -liberty -lz -lzstd
 
 $(OUTPUT)test-reallocarray.bin:
 	$(BUILD)
@@ -291,6 +294,9 @@ $(OUTPUT)test-libbfd-liberty.bin:
 $(OUTPUT)test-libbfd-liberty-z.bin:
 	$(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty -lz
 
+$(OUTPUT)test-libbfd-liberty-z-zstd.bin:
+	$(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty -lz -lzstd
+
 $(OUTPUT)test-cplus-demangle.bin:
 	$(BUILD) -liberty
 
Signature · 1 line
2.55.0.1003.g10538fe699-goog
#2 lore raw

Re: [PATCH v2 1/4] tools build: Add explicitly sequenced -lzstd to libbfd feature fallback

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines

Distributions like Fedora currently ship a statically compiled binutils libbfd that natively depends on zstd to decompress sections (e.g. undefined reference to 'ZSTD_decompress').

Extend the testing cascade in tools/build/feature/Makefile to natively probe for '-lz -lzstd' when the basic fallback variants fail. This adds the generic framework for referencing static binutils across all tools.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
author reviewer
#3 lore raw

PATCH v2 2/4 perf build: Add explicitly sequenced -lzstd to libbfd feature fallback

In reply to Ian Rogers

Distributions like Fedora currently ship a statically compiled binutils libbfd that natively depends on zstd to decompress sections (e.g. undefined reference to 'ZSTD_decompress').

Since libbfd generally does not reliably distribute a .pc file for pkg-config (e.g. 'binutils-dev' evaluates missing on standard PKG_CONFIG_PATH checks), perf historically supplements manual linker flags in fallback chains (-lbfd -ldl -liberty -lz).

Extend the testing cascade in tools/perf/Makefile.config to utilize the newly introduced 'libbfd-liberty-z-zstd' feature test.

Assisted-by Antigravity:gemini-3.1-pro
---
 tools/perf/Makefile.config | 3 +++
 1 file changed, 3 insertions(+)
tools/perf/Makefile.config +3 -0
index 4d5993da9f94..f589a461f4be 100644
@@ -893,6 +893,7 @@ ifdef BUILD_NONDISTRO
   $(call feature_check,libbfd-threadsafe)
   $(call feature_check,libbfd-liberty)
   $(call feature_check,libbfd-liberty-z)
+  $(call feature_check,libbfd-liberty-z-zstd)
 
   ifneq ($(feature-libbfd-threadsafe), 1)
     $(error binutils-dev(el) 2.42 or later is required for non-distro builds)
@@ -906,6 +907,8 @@ ifdef BUILD_NONDISTRO
     EXTLIBS += -lbfd -lopcodes -liberty
   else ifeq ($(feature-libbfd-liberty-z), 1)
     EXTLIBS += -lbfd -lopcodes -liberty -lz
+  else ifeq ($(feature-libbfd-liberty-z-zstd), 1)
+    EXTLIBS += -lbfd -lopcodes -liberty -lz -lzstd
   endif
 
   CFLAGS += -DHAVE_LIBBFD_SUPPORT
Signature · 1 line
2.55.0.1003.g10538fe699-goog
#4 lore raw

Re: [PATCH v2 2/4] perf build: Add explicitly sequenced -lzstd to libbfd feature fallback

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines

Distributions like Fedora currently ship a statically compiled binutils libbfd that natively depends on zstd to decompress sections (e.g. undefined reference to 'ZSTD_decompress').

Since libbfd generally does not reliably distribute a .pc file for pkg-config (e.g. 'binutils-dev' evaluates missing on standard PKG_CONFIG_PATH checks), perf historically supplements manual linker flags in fallback chains (-lbfd -ldl -liberty -lz).

Quoted 4 lines

Extend the testing cascade in tools/perf/Makefile.config to utilize the newly introduced 'libbfd-liberty-z-zstd' feature test.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
author reviewer
#5 lore raw

PATCH v2 3/4 bpftool: Add explicitly sequenced -lzstd to libbfd feature fallback

In reply to Ian Rogers

Distributions like Fedora currently ship a statically compiled binutils libbfd that natively depends on zstd to decompress sections (e.g. undefined reference to 'ZSTD_decompress').

Extend the newly supplemented libbfd-liberty-z-zstd feature probe into bpftool's Makefile so it can natively build against static binutils distributions.

Assisted-by Antigravity:gemini-3.1-pro
---
 tools/bpf/bpftool/Makefile | 4 ++++
 1 file changed, 4 insertions(+)
tools/bpf/bpftool/Makefile +4 -0
index b0f7168e7943..1cac4508eb0c 100644
@@ -125,6 +125,7 @@ FEATURE_TESTS += libcap
 FEATURE_TESTS += libbfd
 FEATURE_TESTS += libbfd-liberty
 FEATURE_TESTS += libbfd-liberty-z
+FEATURE_TESTS += libbfd-liberty-z-zstd
 FEATURE_TESTS += disassembler-four-args
 FEATURE_TESTS += disassembler-init-styled
 FEATURE_TESTS += libelf-zstd
@@ -135,6 +136,7 @@ FEATURE_DISPLAY += libcap
 FEATURE_DISPLAY += libbfd
 FEATURE_DISPLAY += libbfd-liberty
 FEATURE_DISPLAY += libbfd-liberty-z
+FEATURE_DISPLAY += libbfd-liberty-z-zstd
 endif
 
 check_feat := 1
@@ -201,6 +203,8 @@ else
     LIBS += -lbfd -ldl -lopcodes -liberty
   else ifeq ($(feature-libbfd-liberty-z),1)
     LIBS += -lbfd -ldl -lopcodes -liberty -lz
+  else ifeq ($(feature-libbfd-liberty-z-zstd),1)
+    LIBS += -lbfd -ldl -lopcodes -liberty -lz -lzstd
   endif
 
   # If one of the above feature combinations is set, we support libbfd
Signature · 1 line
2.55.0.1003.g10538fe699-goog
#6 lore raw

Re: [PATCH v2 3/4] bpftool: Add explicitly sequenced -lzstd to libbfd feature fallback

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines

Distributions like Fedora currently ship a statically compiled binutils libbfd that natively depends on zstd to decompress sections (e.g. undefined reference to 'ZSTD_decompress').

Extend the newly supplemented libbfd-liberty-z-zstd feature probe into bpftool's Makefile so it can natively build against static binutils distributions.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#7 lore raw

Re: [PATCH v2 3/4] bpftool: Add explicitly sequenced -lzstd to libbfd feature fallback

In reply to Ian Rogers
This isn't a bug, but the subject line uses the phrase "explicitly sequenced" which doesn't appear to describe what the patch does. Looking at the diff, the patch adds libbfd-liberty-z-zstd to…
Quoted 6 lines

bpftool: Add explicitly sequenced -lzstd to libbfd feature fallback

Distributions like Fedora currently ship a statically compiled binutils libbfd that natively depends on zstd to decompress sections (e.g. undefined reference to 'ZSTD_decompress').

Quoted 6 lines

Extend the newly supplemented libbfd-liberty-z-zstd feature probe into bpftool's Makefile so it can natively build against static binutils distributions.

Assisted-by Antigravity:gemini-3.1-pro

This isn't a bug, but the subject line uses the phrase "explicitly sequenced" which doesn't appear to describe what the patch does. Looking at the diff, the patch adds libbfd-liberty-z-zstd to FEATURE_TESTS and FEATURE_DISPLAY, then appends a new fallback branch with '-lz -lzstd' to the existing cascade.

Similarly, "Extend the newly supplemented ... probe into bpftool's Makefile" is a bit indirect. The patch adds the probe to FEATURE_TESTS and appends the matching link flags to the fallback chain.

Also, "natively" appears twice ("natively depends on zstd", "natively build against static binutils") but doesn't add meaning to either phrase.

Would a more direct subject such as "bpftool: Use libbfd-liberty-z-zstd feature in the libbfd fallback chain" describe the change more clearly, and could the body state simply that the new probe is added to FEATURE_TESTS and a matching '-lz -lzstd' branch appended to the fallback?

---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/34404437407

maintainer
#8 lore raw

Re: [PATCH v2 3/4] bpftool: Add explicitly sequenced -lzstd to libbfd feature fallback

In reply to Ian Rogers
Quoted 35 lines · Ian Rogers

Distributions like Fedora currently ship a statically compiled binutils libbfd that natively depends on zstd to decompress sections (e.g. undefined reference to 'ZSTD_decompress').

Extend the newly supplemented libbfd-liberty-z-zstd feature probe into bpftool's Makefile so it can natively build against static binutils distributions.

Assisted-by Antigravity:gemini-3.1-pro
---
 tools/bpf/bpftool/Makefile | 4 ++++
 1 file changed, 4 insertions(+)
tools/bpf/bpftool/Makefile +2 -0
index b0f7168e7943..1cac4508eb0c 100644
@@ -125,6 +125,7 @@ FEATURE_TESTS += libcap
 FEATURE_TESTS += libbfd
 FEATURE_TESTS += libbfd-liberty
 FEATURE_TESTS += libbfd-liberty-z
+FEATURE_TESTS += libbfd-liberty-z-zstd
 FEATURE_TESTS += disassembler-four-args
 FEATURE_TESTS += disassembler-init-styled
 FEATURE_TESTS += libelf-zstd
@@ -135,6 +136,7 @@ FEATURE_DISPLAY += libcap
 FEATURE_DISPLAY += libbfd
 FEATURE_DISPLAY += libbfd-liberty
 FEATURE_DISPLAY += libbfd-liberty-z
+FEATURE_DISPLAY += libbfd-liberty-z-zstd
 endif
 
 check_feat := 1

tools/bpf/bpftool/Makefile else · line 210

Quoted 8 lines
tools/bpf/bpftool/Makefile +2 -0
@@ -201,6 +203,8 @@ else
     LIBS += -lbfd -ldl -lopcodes -liberty
   else ifeq ($(feature-libbfd-liberty-z),1)
     LIBS += -lbfd -ldl -lopcodes -liberty -lz
+  else ifeq ($(feature-libbfd-liberty-z-zstd),1)
+    LIBS += -lbfd -ldl -lopcodes -liberty -lz -lzstd
   endif
 
   # If one of the above feature combinations is set, we support libbfd

Hi Ian, thanks for this!

Just checking: my understanding is that if libbfd depends on libzstd, then it always also depends on zlib, so we never need to check some variant such as "feature-libbfd-liberty-zstd" (without the "-z"), is this correct?

Quentin

author reviewer
#9 lore raw

Re: [PATCH v2 3/4] bpftool: Add explicitly sequenced -lzstd to libbfd feature fallback

Quoted 49 lines · Quentin Monnet
Quoted 35 lines · Ian Rogers

Distributions like Fedora currently ship a statically compiled binutils libbfd that natively depends on zstd to decompress sections (e.g. undefined reference to 'ZSTD_decompress').

Extend the newly supplemented libbfd-liberty-z-zstd feature probe into bpftool's Makefile so it can natively build against static binutils distributions.

Assisted-by Antigravity:gemini-3.1-pro
---
 tools/bpf/bpftool/Makefile | 4 ++++
 1 file changed, 4 insertions(+)
tools/bpf/bpftool/Makefile +2 -0
index b0f7168e7943..1cac4508eb0c 100644
@@ -125,6 +125,7 @@ FEATURE_TESTS += libcap
 FEATURE_TESTS += libbfd
 FEATURE_TESTS += libbfd-liberty
 FEATURE_TESTS += libbfd-liberty-z
+FEATURE_TESTS += libbfd-liberty-z-zstd
 FEATURE_TESTS += disassembler-four-args
 FEATURE_TESTS += disassembler-init-styled
 FEATURE_TESTS += libelf-zstd
@@ -135,6 +136,7 @@ FEATURE_DISPLAY += libcap
 FEATURE_DISPLAY += libbfd
 FEATURE_DISPLAY += libbfd-liberty
 FEATURE_DISPLAY += libbfd-liberty-z
+FEATURE_DISPLAY += libbfd-liberty-z-zstd
 endif
 
 check_feat := 1

tools/bpf/bpftool/Makefile else · line 210

Quoted 8 lines
tools/bpf/bpftool/Makefile +2 -0
@@ -201,6 +203,8 @@ else
     LIBS += -lbfd -ldl -lopcodes -liberty
   else ifeq ($(feature-libbfd-liberty-z),1)
     LIBS += -lbfd -ldl -lopcodes -liberty -lz
+  else ifeq ($(feature-libbfd-liberty-z-zstd),1)
+    LIBS += -lbfd -ldl -lopcodes -liberty -lz -lzstd
   endif
 
   # If one of the above feature combinations is set, we support libbfd

Hi Ian, thanks for this!

Quoted 4 lines

Just checking: my understanding is that if libbfd depends on libzstd, then it always also depends on zlib, so we never need to check some variant such as "feature-libbfd-liberty-zstd" (without the "-z"), is this correct?

Hi,

You make a good point. Normally we want to use pkg-config to get the libraries necessary for a dependency. Unfortunately pkg-config is generally broken around binutils/libbfd. This is why we have all of these tests to determine the list of libraries we need to link with libbfd for things to work, which pkg-config normally provides. It is perfectly possible to build libbfd with libzstd and without libz, but currently, we haven't encountered a distribution doing this. I can imagine a memory hardened future where libz has become zlib-rs that conveniently provides C headers.

For perf we don't build with binutils by default; this matter is only an issue for our build tests. We don't depend on libbfd because its GPLv3+ license isn't compatible with perf's GPLv2 license, which would create an undistributable binary. This isn't an issue for bpftool because its BSD 2-clause license is compatible with libbfd. In perf we've been replacing libbfd based functionality with that in elfutils. libLLVM is another consideration, but it's generally too heavyweight for the effort to be worthwhile (it is generally large, distributions don't want a dependency on it, and it runs many initialization hooks at startup that don't benefit perf). Hopefully elfutils can provide a stable API for its disassembler (libasm) as that would cover pretty much everything perf needs without requiring us to fork objdump, use libcapstone or use libLLVM.

Anyway, we could add another flavor (zstd without libz) to the feature tests for libbfd but since this isn't currently an issue I think we can cross our fingers for binutils to fix pkg-config or for other tools in the kernel, like perf, to migrate away from the use of libbfd. If we add every flavor of libbfd's dependencies, it feels like a lot of build clutter (imo) and I don't know where we stop.

Thanks,
Ian

Quoted 1 line

Quentin

maintainer Acked-by
#10 lore raw

Re: [PATCH v2 3/4] bpftool: Add explicitly sequenced -lzstd to libbfd feature fallback

2026-09-10 08:37 UTC-0700 ~ Ian Rogers <[email protected]>

Quoted 67 lines · Quentin Monnet
Quoted 49 lines · Ian Rogers
Quoted 35 lines

Distributions like Fedora currently ship a statically compiled binutils libbfd that natively depends on zstd to decompress sections (e.g. undefined reference to 'ZSTD_decompress').

Extend the newly supplemented libbfd-liberty-z-zstd feature probe into bpftool's Makefile so it can natively build against static binutils distributions.

Assisted-by Antigravity:gemini-3.1-pro
---
 tools/bpf/bpftool/Makefile | 4 ++++
 1 file changed, 4 insertions(+)
tools/bpf/bpftool/Makefile +2 -0
index b0f7168e7943..1cac4508eb0c 100644
@@ -125,6 +125,7 @@ FEATURE_TESTS += libcap
 FEATURE_TESTS += libbfd
 FEATURE_TESTS += libbfd-liberty
 FEATURE_TESTS += libbfd-liberty-z
+FEATURE_TESTS += libbfd-liberty-z-zstd
 FEATURE_TESTS += disassembler-four-args
 FEATURE_TESTS += disassembler-init-styled
 FEATURE_TESTS += libelf-zstd
@@ -135,6 +136,7 @@ FEATURE_DISPLAY += libcap
 FEATURE_DISPLAY += libbfd
 FEATURE_DISPLAY += libbfd-liberty
 FEATURE_DISPLAY += libbfd-liberty-z
+FEATURE_DISPLAY += libbfd-liberty-z-zstd
 endif
 
 check_feat := 1

tools/bpf/bpftool/Makefile else · line 210

Quoted 8 lines
tools/bpf/bpftool/Makefile +2 -0
@@ -201,6 +203,8 @@ else
     LIBS += -lbfd -ldl -lopcodes -liberty
   else ifeq ($(feature-libbfd-liberty-z),1)
     LIBS += -lbfd -ldl -lopcodes -liberty -lz
+  else ifeq ($(feature-libbfd-liberty-z-zstd),1)
+    LIBS += -lbfd -ldl -lopcodes -liberty -lz -lzstd
   endif
 
   # If one of the above feature combinations is set, we support libbfd

Hi Ian, thanks for this!

Quoted 4 lines

Just checking: my understanding is that if libbfd depends on libzstd, then it always also depends on zlib, so we never need to check some variant such as "feature-libbfd-liberty-zstd" (without the "-z"), is this correct?

Hi,

You make a good point. Normally we want to use pkg-config to get the libraries necessary for a dependency. Unfortunately pkg-config is generally broken around binutils/libbfd. This is why we have all of these tests to determine the list of libraries we need to link with libbfd for things to work, which pkg-config normally provides. It is perfectly possible to build libbfd with libzstd and without libz, but currently, we haven't encountered a distribution doing this. I can imagine a memory hardened future where libz has become zlib-rs that conveniently provides C headers.

Quoted 5 lines

For perf we don't build with binutils by default; this matter is only an issue for our build tests. We don't depend on libbfd because its GPLv3+ license isn't compatible with perf's GPLv2 license, which would create an undistributable binary. This isn't an issue for bpftool because its BSD 2-clause license is compatible with libbfd. In perf

We still have some issues for bpftool related to libbfd: for Debian packaging, building against the shared libbfd is "Not Allowed" [0]. This was one of the motivations for introducing the use of LLVM as an alternative dependency. I didn't know elfutils offered a similar feature, I should look into it.

[0] https://packages.debian.org/sid/amd64/binutils-dev

Quoted 9 lines

we've been replacing libbfd based functionality with that in elfutils. libLLVM is another consideration, but it's generally too heavyweight for the effort to be worthwhile (it is generally large, distributions don't want a dependency on it, and it runs many initialization hooks at startup that don't benefit perf). Hopefully elfutils can provide a stable API for its disassembler (libasm) as that would cover pretty much everything perf needs without requiring us to fork objdump, use libcapstone or use libLLVM.

Quoted 6 lines

Anyway, we could add another flavor (zstd without libz) to the feature tests for libbfd but since this isn't currently an issue I think we can cross our fingers for binutils to fix pkg-config or for other tools in the kernel, like perf, to migrate away from the use of libbfd. If we add every flavor of libbfd's dependencies, it feels like a lot of build clutter (imo) and I don't know where we stop.

Thanks for all the context, very much appreciated! I agree, sticking to the zlib + zstd variant sounds like a good option for now, thanks.

author reviewer
#11 lore raw

PATCH v2 4/4 objtool: Add explicitly sequenced -lzstd to libopcodes fallback

In reply to Ian Rogers

Distributions like Fedora currently ship a statically compiled binutils libbfd (an intrinsic dependency of libopcodes) that internally utilizes zstd to decompress sections.

Because objtool resolves host dependencies sequentially via a manual HOSTCC shell loop, build failures will occur (e.g. undefined reference to 'ZSTD_decompress') unless the loop probes for it.

Add the '-lopcodes -lbfd -liberty -lz -lzstd' combination to the fallback chain, assuring successful compilation on hosts packaging static binutils.

Assisted-by Antigravity:gemini-3.1-pro
---
 tools/objtool/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/objtool/Makefile +2 -1
index a4484fd22a96..141b957c566b 100644
@@ -88,7 +88,8 @@ LIBOPCODES_LIBS := $(shell \
 	for libs in "-lopcodes" \
 		    "-lopcodes -lbfd" \
 		    "-lopcodes -lbfd -liberty" \
-		    "-lopcodes -lbfd -liberty -lz"; do \
+		    "-lopcodes -lbfd -liberty -lz" \
+		    "-lopcodes -lbfd -liberty -lz -lzstd"; do \
 		echo 'extern void disassemble_init_for_target(void *);' \
 		     'int main(void) { disassemble_init_for_target(0); return 0; }' | \
 			$(HOSTCC) -xc - -o /dev/null $$libs 2>/dev/null && \
Signature · 1 line
2.55.0.1003.g10538fe699-goog
#12 lore raw

Re: [PATCH v2 4/4] objtool: Add explicitly sequenced -lzstd to libopcodes fallback

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 4 lines

Distributions like Fedora currently ship a statically compiled binutils libbfd (an intrinsic dependency of libopcodes) that internally utilizes zstd to decompress sections.

Quoted 8 lines

Because objtool resolves host dependencies sequentially via a manual HOSTCC shell loop, build failures will occur (e.g. undefined reference to 'ZSTD_decompress') unless the loop probes for it.

Add the '-lopcodes -lbfd -liberty -lz -lzstd' combination to the fallback chain, assuring successful compilation on hosts packaging static binutils.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#13 lore raw

Re: [PATCH v2 4/4] objtool: Add explicitly sequenced -lzstd to libopcodes fallback

In reply to Ian Rogers
This isn't a bug, but could the changelog say the new candidate mirrors the existing -lz fallback (and note it is untested, as the cover letter does) rather than stating it assures a successful build?
Quoted 10 lines

commit 1f030996083bc0f6f03bca8dc04fe12feb66957d

Author: Ian Rogers <[email protected]>
Date:   Wed Sep 9 13:41:22 2026 -0700

objtool: Add explicitly sequenced -lzstd to libopcodes fallback

Distributions like Fedora currently ship a statically compiled binutils libbfd (an intrinsic dependency of libopcodes) that internally utilizes zstd to decompress sections.

Quoted 6 lines

Because objtool resolves host dependencies sequentially via a manual HOSTCC shell loop, build failures will occur (e.g. undefined reference to 'ZSTD_decompress') unless the loop probes for it.

Add the '-lopcodes -lbfd -liberty -lz -lzstd' combination to the fallback chain, assuring successful compilation on hosts packaging static binutils.

This isn't a bug, but could the changelog say the new candidate mirrors the existing -lz fallback (and note it is untested, as the cover letter does) rather than stating it assures a successful build?

Quoted 8 lines
Assisted-by Antigravity:gemini-3.1-pro
tools/objtool/Makefile +0 -0
index a4484fd22a96..141b957c566b 100644

tools/objtool/Makefile LIBOPCODES_LIBS := $(shell \ · line 95

Quoted 9 lines
tools/objtool/Makefile +2 -1
@@ -88,7 +88,8 @@ LIBOPCODES_LIBS := $(shell \
 	for libs in "-lopcodes" \
 		    "-lopcodes -lbfd" \
 		    "-lopcodes -lbfd -liberty" \
-		    "-lopcodes -lbfd -liberty -lz"; do \
+		    "-lopcodes -lbfd -liberty -lz" \
+		    "-lopcodes -lbfd -liberty -lz -lzstd"; do \
 		echo 'extern void disassemble_init_for_target(void *);' \
 		     'int main(void) { disassemble_init_for_target(0); return 0; }' | \
 			$(HOSTCC) -xc - -o /dev/null $$libs 2>/dev/null && \

This isn't a bug, but should the comment above the loop also mention libzstd, so the documented dependency list still matches the candidates below it? The comment currently says "libbfd, libiberty, and sometimes libz" but the new candidate includes libzstd as well.

---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/34404437407

maintainer Acked-by on v2 4/4
#14 lore raw

Re: [PATCH v2 4/4] objtool: Add explicitly sequenced -lzstd to libopcodes fallback

In reply to Ian Rogers
Quoted 8 lines · Ian Rogers

Distributions like Fedora currently ship a statically compiled binutils libbfd (an intrinsic dependency of libopcodes) that internally utilizes zstd to decompress sections.

Because objtool resolves host dependencies sequentially via a manual HOSTCC shell loop, build failures will occur (e.g. undefined reference to 'ZSTD_decompress') unless the loop probes for it.

Quoted 5 lines

Add the '-lopcodes -lbfd -liberty -lz -lzstd' combination to the fallback chain, assuring successful compilation on hosts packaging static binutils.

Assisted-by Antigravity:gemini-3.1-pro
Quoted 21 lines
---
 tools/objtool/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/objtool/Makefile +2 -1
index a4484fd22a96..141b957c566b 100644
@@ -88,7 +88,8 @@ LIBOPCODES_LIBS := $(shell \
 	for libs in "-lopcodes" \
 		    "-lopcodes -lbfd" \
 		    "-lopcodes -lbfd -liberty" \
-		    "-lopcodes -lbfd -liberty -lz"; do \
+		    "-lopcodes -lbfd -liberty -lz" \
+		    "-lopcodes -lbfd -liberty -lz -lzstd"; do \
 		echo 'extern void disassemble_init_for_target(void *);' \
 		     'int main(void) { disassemble_init_for_target(0); return 0; }' | \
 			$(HOSTCC) -xc - -o /dev/null $$libs 2>/dev/null && \
Signature · 1 line
2.55.0.1003.g10538fe699-goog