Merge tag 'objtool-urgent-2026-01-24' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull objtool fix from Ingo Molnar:
 "Fix objtool build error in non-standard static library build
  environments"

* tag 'objtool-urgent-2026-01-24' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  objtool: Fix libopcodes linking with static libraries
This commit is contained in:
Linus Torvalds
2026-01-24 09:22:09 -08:00

View File

@@ -77,8 +77,21 @@ HOST_OVERRIDES := CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)"
# We check using HOSTCC directly rather than the shared feature framework
# because objtool is a host tool that links against host libraries.
#
HAVE_LIBOPCODES := $(shell echo 'int main(void) { return 0; }' | \
$(HOSTCC) -xc - -o /dev/null -lopcodes 2>/dev/null && echo y)
# 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.
#
LIBOPCODES_LIBS := $(shell \
for libs in "-lopcodes" \
"-lopcodes -lbfd" \
"-lopcodes -lbfd -liberty" \
"-lopcodes -lbfd -liberty -lz"; 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 && \
echo "$$libs" && break; \
done)
# Styled disassembler support requires binutils >= 2.39
HAVE_DISASM_STYLED := $(shell echo '$(pound)include <dis-asm.h>' | \
@@ -86,10 +99,10 @@ HAVE_DISASM_STYLED := $(shell echo '$(pound)include <dis-asm.h>' | \
BUILD_DISAS := n
ifeq ($(HAVE_LIBOPCODES),y)
ifneq ($(LIBOPCODES_LIBS),)
BUILD_DISAS := y
OBJTOOL_CFLAGS += -DDISAS -DPACKAGE='"objtool"'
OBJTOOL_LDFLAGS += -lopcodes
OBJTOOL_LDFLAGS += $(LIBOPCODES_LIBS)
ifeq ($(HAVE_DISASM_STYLED),y)
OBJTOOL_CFLAGS += -DDISASM_INIT_STYLED
endif