Skip to contentSkip to conversation

tools build: Fixes for libbfd -lzstd dependency

PATCH Applied Ian Rogers 4 participants 15 messages Nov 4 – Nov 15

Subsystems (4)
lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

v3 cover tools build: Fixes for libbfd -lzstd dependency

This series addresses build problems when linking against static libbfd/libopcodes on distributions like Fedora where binutils is built with zstd section decompression support (requiring '-liberty -lz -lzstd' together).

In v2, commit 89d001d48ec7 ("tools build: Add zstd to the binutils library feature tests") landed in tools/build/feature/Makefile at the same time, creating a merge conflict and only adding '|| $(BUILD_BFD) -lzstd' without '-liberty -lz' or the corresponding libbfd-liberty-z-zstd feature check in perf and bpftool (so even if test-libbfd.bin passed with -lzstd, perf and bpftool would link only '-lbfd -lopcodes' without '-lzstd').

v3 rebases onto perf-tools-next (v7.4-rc1), fixes commit 89d001d48ec7 in patch 1/4, collects the Acked-by tags from Quentin Monnet and Peter Zijlstra, updates the LIBOPCODES_LIBS comment in tools/objtool/Makefile, and moves the AI assistance disclosure from commit trailers to the cover letter.

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

AI Assistance Disclosure (per Documentation/process/coding-assistants.rst):
- Tools used: Antigravity coding assistant and Sashiko automated patch review.
- Summary of prompts and assistance: Rebased the 4-patch series onto perf-tools-next, resolved the conflict with commit 89d001d48ec7 in tools/build/feature/Makefile, incorporated review feedback and Acked-by tags, and verified with scripts/checkpatch.pl.

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 | 19 +++++++++++++------
 tools/objtool/Makefile       |  7 ++++---
 tools/perf/Makefile.config   |  3 +++
 5 files changed, 26 insertions(+), 10 deletions(-)
Signature · 1 line
2.56.0.385.gac671c819a-goog
author reviewer
#1 lore raw

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

Distributions like Fedora ship a statically compiled binutils libbfd that depends on zstd (along with libiberty and zlib) to decompress sections (e.g. undefined reference to 'ZSTD_decompress').

Commit 89d001d48ec7 ("tools build: Add zstd to the binutils library feature tests") added '|| $(BUILD_BFD) -lzstd' directly to test-libbfd.bin, test-libbfd-threadsafe.bin, and test-disassembler-four-args.bin. However, static libbfd requires '-liberty -lz -lzstd' together, and setting feature-libbfd=1 when extra libraries are needed causes callers (perf, bpftool) to link only '-lbfd -lopcodes' without '-lzstd'.

Restore test-libbfd.bin to test only $(BUILD_BFD), add the test-libbfd-liberty-z-zstd.bin feature test and FEATURE_GROUP_MEMBERS-libbfd entry, and append the '-liberty -lz -lzstd' fallback to test-libbfd-threadsafe.bin, test-disassembler-four-args.bin, and test-disassembler-init-styled.bin.

Fixes 89d001d48ec7 ("tools build: Add zstd to the binutils library feature tests")
---
 tools/build/Makefile.feature |  3 ++-
 tools/build/feature/Makefile | 19 +++++++++++++------
 2 files changed, 15 insertions(+), 7 deletions(-)
tools/build/Makefile.feature +2 -1
index 4d37d11f674c..c010049d9720 100644
@@ -121,6 +121,7 @@ FEATURE_TESTS_EXTRA :=                  \
          libcheck                       \
          libbfd-liberty                 \
          libbfd-liberty-z               \
+         libbfd-liberty-z-zstd          \
          libopencsd                     \
          llvm                           \
          libbpf                         \
@@ -160,7 +161,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 +13 -6
index 10340a537224..359da8b98bc5 100644
@@ -20,6 +20,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			\
@@ -249,18 +250,21 @@ $(OUTPUT)test-python-module.bin:
 	$(BUILD) $(FLAGS_PYTHON_EMBED)
 
 $(OUTPUT)test-libbfd.bin:
-	$(BUILD_BFD) || $(BUILD_BFD) -lzstd
+	$(BUILD_BFD)
 
 $(OUTPUT)test-libbfd-threadsafe.bin:
-	$(BUILD_BFD) || $(BUILD_BFD) -lzstd || $(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 -lzstd || $(BUILD_BFD) -lopcodes -liberty || \
-	$(BUILD_BFD) -lopcodes -liberty -lz
+	$(BUILD_BFD) -lopcodes || $(BUILD_BFD) -lopcodes -liberty || \
+	$(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 || $(BUILD_BFD) -lopcodes -liberty || \
+	$(BUILD_BFD) -lopcodes -liberty -lz || \
+	$(BUILD_BFD) -lopcodes -liberty -lz -lzstd
 
 $(OUTPUT)test-reallocarray.bin:
 	$(BUILD)
@@ -271,6 +275,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.56.0.385.gac671c819a-goog
#2 lore raw

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

Sashiko has reviewed this patch and found no issues.
Quoted 12 lines

Distributions like Fedora ship a statically compiled binutils libbfd that depends on zstd (along with libiberty and zlib) to decompress sections (e.g. undefined reference to 'ZSTD_decompress').

Commit 89d001d48ec7 ("tools build: Add zstd to the binutils library feature tests") added '|| $(BUILD_BFD) -lzstd' directly to test-libbfd.bin, test-libbfd-threadsafe.bin, and test-disassembler-four-args.bin. However, static libbfd requires '-liberty -lz -lzstd' together, and setting feature-libbfd=1 when extra libraries are needed causes callers (perf, bpftool) to link only '-lbfd -lopcodes' without '-lzstd'.

Quoted 8 lines

Restore test-libbfd.bin to test only $(BUILD_BFD), add the test-libbfd-liberty-z-zstd.bin feature test and FEATURE_GROUP_MEMBERS-libbfd entry, and append the '-liberty -lz -lzstd' fallback to test-libbfd-threadsafe.bin, test-disassembler-four-args.bin, and test-disassembler-init-styled.bin.

Fixes 89d001d48ec7 ("tools build: Add zstd to the binutils library feature tests")

Sashiko has reviewed this patch and found no issues.

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

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

In reply to Ian Rogers
TL;DR: Possible build break at this commit: the libbfd -lzstd fallback is removed but no consumer uses the new feature test yet, so perf may fail to link and bpftool may lose JIT disassembly.
Quoted 1 line

tools build: Add explicitly sequenced -lzstd to libbfd feature fallback

TL;DR: Possible build break at this commit: the libbfd -lzstd fallback is removed but no consumer uses the new feature test yet, so perf may fail to link and bpftool may lose JIT disassembly.

Quoted 3 lines
tools/build/feature/Makefile +0 -0

[ ... ]

tools/build/feature/Makefile $(OUTPUT)test-python-module.bin: · line 257

Quoted 11 lines
tools/build/feature/Makefile +3 -2
@@ -249,18 +250,21 @@ $(OUTPUT)test-python-module.bin:
 	$(BUILD) $(FLAGS_PYTHON_EMBED)
 
 $(OUTPUT)test-libbfd.bin:
-	$(BUILD_BFD) || $(BUILD_BFD) -lzstd
+	$(BUILD_BFD)
 
 $(OUTPUT)test-libbfd-threadsafe.bin:
-	$(BUILD_BFD) || $(BUILD_BFD) -lzstd || $(BUILD_BFD) -liberty || $(BUILD_BFD) -liberty -lz
+	$(BUILD_BFD) || $(BUILD_BFD) -liberty || $(BUILD_BFD) -liberty -lz || \
+	$(BUILD_BFD) -liberty -lz -lzstd

Can this leave perf and bpftool unable to link libbfd at this commit?

Nothing here reads the new libbfd-liberty-z-zstd result. Neither tools/perf/Makefile.config nor tools/bpf/bpftool/Makefile calls feature_check for it or has a branch that uses it.

On a system where "-lbfd -ldl" fails but "-lbfd -ldl -lzstd" links, the parent commit gave feature-libbfd=1 through the removed fallback. Here feature-libbfd, feature-libbfd-liberty and feature-libbfd-liberty-z are all 0, while feature-libbfd-threadsafe is 1 through the new "-liberty -lz -lzstd" fallback.

With BUILD_NONDISTRO=1, perf's Makefile.config then passes the threadsafe check but takes none of the EXTLIBS branches:

  ifeq ($(feature-libbfd), 1)
    EXTLIBS += -lbfd -lopcodes
  else ifeq ($(feature-libbfd-liberty), 1)
    EXTLIBS += -lbfd -lopcodes -liberty
  else ifeq ($(feature-libbfd-liberty-z), 1)
    EXTLIBS += -lbfd -lopcodes -liberty -lz
  endif

CFLAGS += -DHAVE_LIBBFD_SUPPORT

util/libbfd.o is still built, so the perf link can fail with undefined references to bfd_openr(), bfd_check_format() and disassembler(). bpftool goes down the same chain, silently drops -lbfd and -DHAVE_LIBBFD_SUPPORT, and loses JIT disassembly.

The consumers are added later in the series:

6eb66acc776f ("perf build: Add explicitly sequenced -lzstd to libbfd feature fallback")
155513d3a59d ("bpftool: Add explicitly sequenced -lzstd to libbfd feature fallback")

Would it be better to keep the old -lzstd fallback until those consumers land, or to reorder or squash so that each commit remains buildable?

---
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/41774922004

author reviewer
#4 lore raw

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

Quoted 20 lines · On Tue, Nov 3, 2026 at 9:03 PM <[email protected]> wrote:
Quoted 2 lines

tools build: Add explicitly sequenced -lzstd to libbfd feature fallback

TL;DR: Possible build break at this commit: the libbfd -lzstd fallback is removed but no consumer uses the new feature test yet, so perf may fail to link and bpftool may lose JIT disassembly.

Quoted 3 lines
tools/build/feature/Makefile +0 -0

[ ... ]

Quoted 7 lines
tools/build/feature/Makefile +1 -1
@@ -249,18 +250,21 @@ $(OUTPUT)test-python-module.bin:
      $(BUILD) $(FLAGS_PYTHON_EMBED)
 
 $(OUTPUT)test-libbfd.bin:
-     $(BUILD_BFD) || $(BUILD_BFD) -lzstd
+     $(BUILD_BFD)
 
Quoted 6 lines

tools/build/feature/Makefile $(OUTPUT)test-python-module.bin: · line 257

Quoted 4 lines
tools/build/feature/Makefile +2 -1
 $(OUTPUT)test-libbfd-threadsafe.bin:
-     $(BUILD_BFD) || $(BUILD_BFD) -lzstd || $(BUILD_BFD) -liberty || $(BUILD_BFD) -liberty -lz
+     $(BUILD_BFD) || $(BUILD_BFD) -liberty || $(BUILD_BFD) -liberty -lz || \
+     $(BUILD_BFD) -liberty -lz -lzstd

Can this leave perf and bpftool unable to link libbfd at this commit?

So the concern is that at this commit, not later in the series, a feature test for a libbfd built with zstd that previously failed to link in this feature test will now succeed, but the parent Makefile will not pass the -zstd flag and so break the build. This issue is fixed later in the series by adding the -lzstd. Will this impact anything? It will turn one broken build into a different kind of broken build. I can reengineer the series to maintain bisectability but this seems like a low priority issue to address.

Thanks,
Ian

Quoted 44 lines

Nothing here reads the new libbfd-liberty-z-zstd result. Neither tools/perf/Makefile.config nor tools/bpf/bpftool/Makefile calls feature_check for it or has a branch that uses it.

On a system where "-lbfd -ldl" fails but "-lbfd -ldl -lzstd" links, the parent commit gave feature-libbfd=1 through the removed fallback. Here feature-libbfd, feature-libbfd-liberty and feature-libbfd-liberty-z are all 0, while feature-libbfd-threadsafe is 1 through the new "-liberty -lz -lzstd" fallback.

With BUILD_NONDISTRO=1, perf's Makefile.config then passes the threadsafe check but takes none of the EXTLIBS branches:

  ifeq ($(feature-libbfd), 1)
    EXTLIBS += -lbfd -lopcodes
  else ifeq ($(feature-libbfd-liberty), 1)
    EXTLIBS += -lbfd -lopcodes -liberty
  else ifeq ($(feature-libbfd-liberty-z), 1)
    EXTLIBS += -lbfd -lopcodes -liberty -lz
  endif

CFLAGS += -DHAVE_LIBBFD_SUPPORT

util/libbfd.o is still built, so the perf link can fail with undefined references to bfd_openr(), bfd_check_format() and disassembler(). bpftool goes down the same chain, silently drops -lbfd and -DHAVE_LIBBFD_SUPPORT, and loses JIT disassembly.

The consumers are added later in the series:

6eb66acc776f ("perf build: Add explicitly sequenced -lzstd to libbfd feature fallback")
155513d3a59d ("bpftool: Add explicitly sequenced -lzstd to libbfd feature fallback")

Would it be better to keep the old -lzstd fallback until those consumers land, or to reorder or squash so that each commit remains buildable?

---
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/41774922004

maintainer
#5 lore raw

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

Quoted 28 lines · Ian Rogers
Quoted 20 lines · On Tue, Nov 3, 2026 at 9:03 PM <[email protected]> wrote:
Quoted 2 lines

tools build: Add explicitly sequenced -lzstd to libbfd feature fallback

TL;DR: Possible build break at this commit: the libbfd -lzstd fallback is removed but no consumer uses the new feature test yet, so perf may fail to link and bpftool may lose JIT disassembly.

Quoted 3 lines
tools/build/feature/Makefile +0 -0

[ ... ]

Quoted 7 lines
tools/build/feature/Makefile +1 -1
@@ -249,18 +250,21 @@ $(OUTPUT)test-python-module.bin:
      $(BUILD) $(FLAGS_PYTHON_EMBED)
 
 $(OUTPUT)test-libbfd.bin:
-     $(BUILD_BFD) || $(BUILD_BFD) -lzstd
+     $(BUILD_BFD)
 
Quoted 6 lines

tools/build/feature/Makefile $(OUTPUT)test-python-module.bin: · line 257

Quoted 4 lines
tools/build/feature/Makefile +2 -1
 $(OUTPUT)test-libbfd-threadsafe.bin:
-     $(BUILD_BFD) || $(BUILD_BFD) -lzstd || $(BUILD_BFD) -liberty || $(BUILD_BFD) -liberty -lz
+     $(BUILD_BFD) || $(BUILD_BFD) -liberty || $(BUILD_BFD) -liberty -lz || \
+     $(BUILD_BFD) -liberty -lz -lzstd

Can this leave perf and bpftool unable to link libbfd at this commit?

Quoted 8 lines

So the concern is that at this commit, not later in the series, a feature test for a libbfd built with zstd that previously failed to link in this feature test will now succeed, but the parent Makefile will not pass the -zstd flag and so break the build. This issue is fixed later in the series by adding the -lzstd. Will this impact anything? It will turn one broken build into a different kind of broken build. I can reengineer the series to maintain bisectability but this seems like a low priority issue to address.

Ok, fair enough. As it got acked from other maintainers, I think it's good to go.

Thanks,
Namhyung

author reviewer
#6 lore raw

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

In reply to Ian Rogers

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

Since libbfd does not reliably distribute a .pc file for pkg-config, perf probes manual linker flag combinations in fallback chains (-lbfd -ldl -liberty -lz).

Extend the testing cascade in tools/perf/Makefile.config to check libbfd-liberty-z-zstd and append '-lbfd -lopcodes -liberty -lz -lzstd' when detected.

---
 tools/perf/Makefile.config | 3 +++
 1 file changed, 3 insertions(+)
tools/perf/Makefile.config +3 -0
index b4764f69f47f..78423b0dcc73 100644
@@ -896,6 +896,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)
@@ -909,6 +910,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.56.0.385.gac671c819a-goog
#7 lore raw

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

Sashiko has reviewed this patch and found no issues.
Quoted 8 lines

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

Since libbfd does not reliably distribute a .pc file for pkg-config, perf probes manual linker flag combinations in fallback chains (-lbfd -ldl -liberty -lz).

Quoted 5 lines

Extend the testing cascade in tools/perf/Makefile.config to check libbfd-liberty-z-zstd and append '-lbfd -lopcodes -liberty -lz -lzstd' when detected.

Sashiko has reviewed this patch and found no issues.

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

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

In reply to Ian Rogers

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

Add libbfd-liberty-z-zstd to FEATURE_TESTS and FEATURE_DISPLAY in tools/bpf/bpftool/Makefile and append the '-lbfd -ldl -lopcodes -liberty -lz -lzstd' branch to the libbfd fallback chain.

---
 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.56.0.385.gac671c819a-goog
#9 lore raw

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

Sashiko has reviewed this patch and found no issues.
Quoted 10 lines

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

Add libbfd-liberty-z-zstd to FEATURE_TESTS and FEATURE_DISPLAY in tools/bpf/bpftool/Makefile and append the '-lbfd -ldl -lopcodes -liberty -lz -lzstd' branch to the libbfd fallback chain.

Sashiko has reviewed this patch and found no issues.

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

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

In reply to Ian Rogers

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

Because objtool resolves host dependencies sequentially via a manual HOSTCC shell loop, linking against static binutils fails with undefined references to 'ZSTD_decompress' unless the loop probes for -lzstd.

Add the '-lopcodes -lbfd -liberty -lz -lzstd' combination to the LIBOPCODES_LIBS fallback chain.

---
 tools/objtool/Makefile | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
tools/objtool/Makefile +4 -3
index db99c4759b2c..238da6fd277f 100644
@@ -81,14 +81,15 @@ HOST_OVERRIDES := CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)"
 #
 # When using shared libraries, -lopcodes is sufficient as dependencies are
 # resolved automatically. With static libraries, we must explicitly link
-# against libopcodes' dependencies: libbfd, libiberty, and sometimes libz.
-# Try each combination and use the first one that succeeds.
+# against libopcodes' dependencies: libbfd, libiberty, and sometimes libz
+# and libzstd. Try each combination and use the first one that succeeds.
 #
 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 \
 		printf '%s\n' \
 		       '$(pound)include <bfd.h>' \
 		       '$(pound)include <dis-asm.h>' \
Signature · 1 line
2.56.0.385.gac671c819a-goog
#11 lore raw

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

Sashiko has reviewed this patch and found no issues.
Quoted 8 lines

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

Because objtool resolves host dependencies sequentially via a manual HOSTCC shell loop, linking against static binutils fails with undefined references to 'ZSTD_decompress' unless the loop probes for -lzstd.

Quoted 5 lines

Add the '-lopcodes -lbfd -liberty -lz -lzstd' combination to the LIBOPCODES_LIBS fallback chain.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
author reviewer
#12 lore raw
In reply to Ian Rogers
Quoted 5 lines · Ian Rogers

This series addresses build problems when linking against static libbfd/libopcodes on distributions like Fedora where binutils is built with zstd section decompression support (requiring '-liberty -lz -lzstd' together).

Hi,

Namhyung/Arnaldo, could you help review the tools/build and tools/perf parts of this (patches 1 and 2)? The objtool and bpftool changes have Peter's and Quentin's tags.

Thanks,
Ian

Quoted 42 lines

In v2, commit 89d001d48ec7 ("tools build: Add zstd to the binutils library feature tests") landed in tools/build/feature/Makefile at the same time, creating a merge conflict and only adding '|| $(BUILD_BFD) -lzstd' without '-liberty -lz' or the corresponding libbfd-liberty-z-zstd feature check in perf and bpftool (so even if test-libbfd.bin passed with -lzstd, perf and bpftool would link only '-lbfd -lopcodes' without '-lzstd').

v3 rebases onto perf-tools-next (v7.4-rc1), fixes commit 89d001d48ec7 in patch 1/4, collects the Acked-by tags from Quentin Monnet and Peter Zijlstra, updates the LIBOPCODES_LIBS comment in tools/objtool/Makefile, and moves the AI assistance disclosure from commit trailers to the cover letter.

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

AI Assistance Disclosure (per Documentation/process/coding-assistants.rst):
- Tools used: Antigravity coding assistant and Sashiko automated patch review.
- Summary of prompts and assistance: Rebased the 4-patch series onto perf-tools-next, resolved the conflict with commit 89d001d48ec7 in tools/build/feature/Makefile, incorporated review feedback and Acked-by tags, and verified with scripts/checkpatch.pl.

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 | 19 +++++++++++++------
 tools/objtool/Makefile       |  7 ++++---
 tools/perf/Makefile.config   |  3 +++
 5 files changed, 26 insertions(+), 10 deletions(-)

--
2.56.0.385.gac671c819a-goog

maintainer
#13 lore raw
Quoted 7 lines · Ian Rogers
Quoted 5 lines · Ian Rogers

This series addresses build problems when linking against static libbfd/libopcodes on distributions like Fedora where binutils is built with zstd section decompression support (requiring '-liberty -lz -lzstd' together).

Quoted 5 lines

Hi,

Namhyung/Arnaldo, could you help review the tools/build and tools/perf parts of this (patches 1 and 2)? The objtool and bpftool changes have Peter's and Quentin's tags.

Can you please reply to the bpf bot review on the patch 1?

Thanks,
Namhyung

maintainer Applied
#14 lore raw
In reply to Ian Rogers
Quoted 13 lines · Ian Rogers

This series addresses build problems when linking against static libbfd/libopcodes on distributions like Fedora where binutils is built with zstd section decompression support (requiring '-liberty -lz -lzstd' together).

In v2, commit 89d001d48ec7 ("tools build: Add zstd to the binutils library feature tests") landed in tools/build/feature/Makefile at the same time, creating a merge conflict and only adding '|| $(BUILD_BFD) -lzstd' without '-liberty -lz' or the corresponding libbfd-liberty-z-zstd feature check in perf and bpftool (so even if test-libbfd.bin passed with -lzstd, perf and bpftool would link only '-lbfd -lopcodes' without '-lzstd').

Quoted 1 line

[...]

Applied to perf-tools-next, thanks!

Best regards
Namhyung