Skip to contentSkip to conversation

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

PATCH Superseded Ian Rogers 2 participants 2 messages Sep 9 perf events

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/1 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').

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/build/feature/Makefile and tools/perf/Makefile.config to probe for '-lz -lzstd' when the basic fallback variants fail, natively supporting statically compiled binutils on recent distributions.

Assisted-by Antigravity:gemini-3.1-pro
---
 tools/build/Makefile.feature |  3 ++-
 tools/build/feature/Makefile | 12 +++++++++---
 tools/perf/Makefile.config   |  2 ++
 3 files changed, 13 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
 
tools/perf/Makefile.config +2 -0
index 4d5993da9f94..24a99545c9bc 100644
@@ -906,6 +906,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
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The newly added fallback feature test 'libbfd-liberty-z-zstd' is never executed, making the new…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The newly added fallback feature test 'libbfd-liberty-z-zstd' is never executed, making the new libbfd zstd fallback condition dead code and failing to fix the link error. --

commit 5475f00ff10a072611b6ed7d2a3b54cfea18c571
Author: Ian Rogers <[email protected]>

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

This commit extends the build feature testing cascade to probe for -lz -lzstd when basic libbfd fallback variants fail. This aims to natively support recent distributions that ship statically compiled binutils with zstd dependencies.

Quoted 3 lines
tools/perf/Makefile.config +0 -0

[ ... ]

tools/perf/Makefile.config ifdef BUILD_NONDISTRO · line 909

Quoted 6 lines
tools/perf/Makefile.config +2 -0
@@ -905,6 +905,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

[Severity: Medium]
Is the feature-libbfd-liberty-z-zstd check actually executed?

It looks like $(call feature_check,libbfd-liberty-z-zstd) is missing from the BUILD_NONDISTRO feature checks earlier in tools/perf/Makefile.config. Without the feature check being called to trigger the evaluation, will this conditional always evaluate to false and act as dead code, leaving the build still failing on systems requiring the zstd fallback?

Quoted 3 lines
tools/perf/Makefile.config +0 -0
   endif
 
   CFLAGS += -DHAVE_LIBBFD_SUPPORT
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1