Skip to content

Commit 436326b

Browse files
Sasha LevinPeter Zijlstra
authored andcommitted
objtool: fix build failure due to missing libopcodes check
Commit 5995330 ("objtool: Disassemble code with libopcodes instead of running objdump") added support for using libopcodes for disassembly. However, the feature detection checks for libbfd availability but then unconditionally links against libopcodes: ifeq ($(feature-libbfd),1) OBJTOOL_LDFLAGS += -lopcodes endif This causes build failures in environments where libbfd is installed but libopcodes is not, since the test-libbfd.c feature test only links against -lbfd and -ldl, not -lopcodes: /usr/bin/ld: cannot find -lopcodes: No such file or directory collect2: error: ld returned 1 exit status make[4]: *** [Makefile:109: objtool] Error 1 Additionally, the shared feature framework uses $(CC) which is the cross-compiler in cross-compilation builds. Since objtool is a host tool that links with $(HOSTCC) against host libraries, the feature detection can falsely report libopcodes as available when the cross-compiler's sysroot has it but the host system doesn't. Fix this by replacing the feature framework check with a direct inline test that uses $(HOSTCC) to compile and link a test program against libopcodes, similar to how xxhash availability is detected. Fixes: 5995330 ("objtool: Disassemble code with libopcodes instead of running objdump") Assisted-by: claude-opus-4-5-20251101 Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://patch.msgid.link/20251223120357.2492008-1-sashal@kernel.org
1 parent 26bea10 commit 436326b

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

tools/objtool/Makefile

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,23 +72,27 @@ HOST_OVERRIDES := CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)"
7272

7373
#
7474
# To support disassembly, objtool needs libopcodes which is provided
75-
# with libbdf (binutils-dev or binutils-devel package).
75+
# with libbfd (binutils-dev or binutils-devel package).
7676
#
77-
FEATURE_USER = .objtool
78-
FEATURE_TESTS = libbfd disassembler-init-styled
79-
FEATURE_DISPLAY =
80-
include $(srctree)/tools/build/Makefile.feature
77+
# We check using HOSTCC directly rather than the shared feature framework
78+
# because objtool is a host tool that links against host libraries.
79+
#
80+
HAVE_LIBOPCODES := $(shell echo 'int main(void) { return 0; }' | \
81+
$(HOSTCC) -xc - -o /dev/null -lopcodes 2>/dev/null && echo y)
8182

82-
ifeq ($(feature-disassembler-init-styled), 1)
83-
OBJTOOL_CFLAGS += -DDISASM_INIT_STYLED
84-
endif
83+
# Styled disassembler support requires binutils >= 2.39
84+
HAVE_DISASM_STYLED := $(shell echo '$(pound)include <dis-asm.h>' | \
85+
$(HOSTCC) -E -xc - 2>/dev/null | grep -q disassembler_style && echo y)
8586

8687
BUILD_DISAS := n
8788

88-
ifeq ($(feature-libbfd),1)
89+
ifeq ($(HAVE_LIBOPCODES),y)
8990
BUILD_DISAS := y
90-
OBJTOOL_CFLAGS += -DDISAS -DPACKAGE="objtool"
91+
OBJTOOL_CFLAGS += -DDISAS -DPACKAGE='"objtool"'
9192
OBJTOOL_LDFLAGS += -lopcodes
93+
ifeq ($(HAVE_DISASM_STYLED),y)
94+
OBJTOOL_CFLAGS += -DDISASM_INIT_STYLED
95+
endif
9296
endif
9397

9498
export BUILD_DISAS

0 commit comments

Comments
 (0)