From: "tip-bot2 for Sasha Levin" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
Sasha Levin <sashal@kernel.org>,
"Peter Zijlstra (Intel)" <peterz@infradead.org>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: objtool/urgent] objtool: Fix libopcodes linking with static libraries
Date: Wed, 21 Jan 2026 19:28:40 -0000 [thread overview]
Message-ID: <176902372065.510.12809888165013587029.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20260121162532.1596238-1-sashal@kernel.org>
The following commit has been merged into the objtool/urgent branch of tip:
Commit-ID: 3f2de814c0597c97d5abe09a1635d8c4e2fddaf2
Gitweb: https://git.kernel.org/tip/3f2de814c0597c97d5abe09a1635d8c4e2fddaf2
Author: Sasha Levin <sashal@kernel.org>
AuthorDate: Wed, 21 Jan 2026 11:25:32 -05:00
Committer: Peter Zijlstra <peterz@infradead.org>
CommitterDate: Wed, 21 Jan 2026 20:25:14 +01:00
objtool: Fix libopcodes linking with static libraries
Commit 436326bc525d ("objtool: fix build failure due to missing libopcodes
check") tests for libopcodes using an empty main(), which passes even when
static libraries lack their dependencies. This causes undefined reference
errors (xmalloc, bfd_get_bits, etc.) when linking against static libopcodes
without its required libbfd and libiberty.
Fix by testing with an actual libopcodes symbol and trying increasingly
complete library combinations until one succeeds.
Fixes: 436326bc525d ("objtool: fix build failure due to missing libopcodes check")
Reported-by: Rafael J. Wysocki <rafael@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: Rafael J. Wysocki (Intel) <rafael@kernel.org>
Link: https://patch.msgid.link/20260121162532.1596238-1-sashal@kernel.org
---
tools/objtool/Makefile | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile
index 9b45031..a40f302 100644
--- a/tools/objtool/Makefile
+++ b/tools/objtool/Makefile
@@ -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
prev parent reply other threads:[~2026-01-21 19:28 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-19 20:19 [Regression in 6.19-rc6] Build breakage after commit 436326bc525d Rafael J. Wysocki
2026-01-20 10:28 ` Peter Zijlstra
2026-01-20 17:40 ` Sasha Levin
2026-01-20 18:29 ` Rafael J. Wysocki
2026-01-20 19:58 ` Sasha Levin
2026-01-20 20:04 ` Rafael J. Wysocki
2026-01-20 20:22 ` Sasha Levin
2026-01-20 21:33 ` Rafael J. Wysocki
2026-01-21 1:18 ` Sasha Levin
2026-01-21 5:29 ` Josh Poimboeuf
2026-01-21 12:06 ` Sasha Levin
2026-01-21 16:25 ` [PATCH] objtool: fix libopcodes linking with static libraries Sasha Levin
2026-01-21 19:08 ` Rafael J. Wysocki
2026-01-21 19:25 ` Peter Zijlstra
2026-01-21 19:28 ` tip-bot2 for Sasha Levin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=176902372065.510.12809888165013587029.tip-bot2@tip-bot2 \
--to=tip-bot2@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=rafael@kernel.org \
--cc=sashal@kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®