Commit 59953303 authored by Alexandre Chartre's avatar Alexandre Chartre Committed by Peter Zijlstra
Browse files

objtool: Disassemble code with libopcodes instead of running objdump



objtool executes the objdump command to disassemble code. Use libopcodes
instead to have more control about the disassembly scope and output.
If libopcodes is not present then objtool is built without disassembly
support.

Signed-off-by: default avatarAlexandre Chartre <alexandre.chartre@oracle.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: default avatarJosh Poimboeuf <jpoimboe@kernel.org>
Link: https://patch.msgid.link/20251121095340.464045-4-alexandre.chartre@oracle.com
parent 1013f2e3
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
# SPDX-License-Identifier: GPL-2.0-only
arch/x86/lib/inat-tables.c
/objtool
feature
FEATURE-DUMP.objtool
fixdep
libsubcmd/
+2 −1
Original line number Diff line number Diff line
@@ -7,7 +7,8 @@ objtool-y += special.o
objtool-y += builtin-check.o
objtool-y += elf.o
objtool-y += objtool.o
objtool-y += disas.o

objtool-$(BUILD_DISAS) += disas.o

objtool-$(BUILD_ORC) += orc_gen.o orc_dump.o
objtool-$(BUILD_KLP) += builtin-klp.o klp-diff.o klp-post-link.o
+25 −0
Original line number Diff line number Diff line
@@ -70,6 +70,29 @@ OBJTOOL_CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
# Always want host compilation.
HOST_OVERRIDES := CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)"

#
# To support disassembly, objtool needs libopcodes which is provided
# with libbdf (binutils-dev or binutils-devel package).
#
FEATURE_USER = .objtool
FEATURE_TESTS = libbfd disassembler-init-styled
FEATURE_DISPLAY =
include $(srctree)/tools/build/Makefile.feature

ifeq ($(feature-disassembler-init-styled), 1)
	OBJTOOL_CFLAGS += -DDISASM_INIT_STYLED
endif

BUILD_DISAS := n

ifeq ($(feature-libbfd),1)
	BUILD_DISAS := y
	OBJTOOL_CFLAGS += -DDISAS
	OBJTOOL_LDFLAGS += -lopcodes
endif

export BUILD_DISAS

AWK = awk
MKDIR = mkdir

@@ -103,6 +126,8 @@ clean: $(LIBSUBCMD)-clean
	$(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
	$(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
	$(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep
	$(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.objtool
	$(Q)$(RM) -r -- $(OUTPUT)feature

FORCE:

+12 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-or-later
#include <string.h>
#include <objtool/check.h>
#include <objtool/disas.h>
#include <objtool/warn.h>
#include <asm/inst.h>
#include <asm/orc_types.h>
@@ -414,3 +415,14 @@ unsigned long arch_jump_table_sym_offset(struct reloc *reloc, struct reloc *tabl
		return reloc->sym->offset + reloc_addend(reloc);
	}
}

#ifdef DISAS

int arch_disas_info_init(struct disassemble_info *dinfo)
{
	return disas_info_init(dinfo, bfd_arch_loongarch,
			       bfd_mach_loongarch32, bfd_mach_loongarch64,
			       NULL);
}

#endif /* DISAS */
+12 −0
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <objtool/check.h>
#include <objtool/disas.h>
#include <objtool/elf.h>
#include <objtool/arch.h>
#include <objtool/warn.h>
@@ -127,3 +128,14 @@ unsigned int arch_reloc_size(struct reloc *reloc)
		return 8;
	}
}

#ifdef DISAS

int arch_disas_info_init(struct disassemble_info *dinfo)
{
	return disas_info_init(dinfo, bfd_arch_powerpc,
			       bfd_mach_ppc, bfd_mach_ppc64,
			       NULL);
}

#endif /* DISAS */
Loading