Re: [RFC 03/13] objtool: Disassemble code with libopcodes instead of running objdump

From: Alexandre Chartre
Date: Wed Jun 11 2025 - 09:37:22 EST



On 6/11/25 14:23, Peter Zijlstra wrote:
On Fri, Jun 06, 2025 at 05:34:30PM +0200, Alexandre Chartre wrote:
objtool executes the objdump command to disassemble code. Use libopcodes
instead to have more control about the disassembly scope and output.

Signed-off-by: Alexandre Chartre <alexandre.chartre@xxxxxxxxxx>
---
tools/objtool/Makefile | 2 +-
tools/objtool/arch/loongarch/decode.c | 6 +
tools/objtool/arch/powerpc/decode.c | 6 +
tools/objtool/arch/x86/decode.c | 7 +
tools/objtool/check.c | 4 +-
tools/objtool/disas.c | 186 +++++++++++++++---------
tools/objtool/include/objtool/arch.h | 5 +
tools/objtool/include/objtool/check.h | 5 +
tools/objtool/include/objtool/objtool.h | 4 +
9 files changed, 154 insertions(+), 71 deletions(-)

diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile
index 8c20361dd100..00350fc7c662 100644
--- a/tools/objtool/Makefile
+++ b/tools/objtool/Makefile
@@ -34,7 +34,7 @@ INCLUDES := -I$(srctree)/tools/include \
# is passed here to match a legacy behavior.
WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs
OBJTOOL_CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS)
-OBJTOOL_LDFLAGS := $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS)
+OBJTOOL_LDFLAGS := $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS) -lopcodes

Would it be possible to make this optional? Such that when people do not
have libopcodes installed they can still build the kernel.

Or is libopcodes a mandatory part of any binutils installation?

I guess that libopcodes is mandatory because it is used by as (and also objdump).
But I can check if it is effectively present anyway.

alex.