objtool is built for a specific architecture determined by SRCARCH at compile time. However, the binary currently provides no way to report this target architecture, making it difficult for scripts or test suites to verify compatibility before processing object files.
Pass SRCARCH as a preprocessor define and add a --arch (-a) option to klp diff that prints the target architecture and exits: $ objtool klp diff --arch x86 This is mutually exclusive with normal operation: when --arch is given, all other options and arguments are ignored. Assisted-by: Cursor:claude-4.6-opus Signed-off-by: Joe Lawrence <[email protected]> --- tools/objtool/Makefile | 3 ++- tools/objtool/klp-diff.c | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile index 94aabeee9736..79694444053c 100644 --- a/tools/objtool/Makefile +++ b/tools/objtool/Makefile @@ -65,7 +65,8 @@ INCLUDES := -I$(srctree)/tools/include \ -I$(srctree)/tools/lib OBJTOOL_CFLAGS := -std=gnu11 -fomit-frame-pointer -O2 -g $(WARNINGS) \ - $(INCLUDES) $(LIBELF_FLAGS) $(LIBXXHASH_CFLAGS) $(HOSTCFLAGS) + $(INCLUDES) $(LIBELF_FLAGS) $(LIBXXHASH_CFLAGS) $(HOSTCFLAGS) \ + -DOBJTOOL_ARCH=$(SRCARCH) OBJTOOL_LDFLAGS := $(LIBSUBCMD) $(LIBELF_LIBS) $(LIBXXHASH_LIBS) $(HOSTLDFLAGS) diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index ebe4a2a087ca..8710ae8708df 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -35,7 +35,7 @@ struct export { }; static const char *symvers_path = "Module.symvers"; -bool debug, debug_correlate, debug_clone; +bool show_arch, debug, debug_correlate, debug_clone; int indent; static const char * const klp_diff_usage[] = { @@ -45,6 +45,7 @@ static const char * const klp_diff_usage[] = { static const struct option klp_diff_options[] = { OPT_GROUP("Options:"), + OPT_BOOLEAN('a', "arch", &show_arch, "display target architecture"), OPT_BOOLEAN('d', "debug", &debug, "enable all debug output"), OPT_BOOLEAN(0, "debug-correlate", &debug_correlate, "enable correlation debug output"), OPT_BOOLEAN(0, "debug-clone", &debug_clone, "enable cloning debug output"), @@ -2366,6 +2367,12 @@ int cmd_klp_diff(int argc, const char **argv) int ret; argc = parse_options(argc, argv, klp_diff_options, klp_diff_usage, 0); + + if (show_arch) { + printf("%s\n", __stringify(OBJTOOL_ARCH)); + return 0; + } + if (argc != 3) usage_with_options(klp_diff_usage, klp_diff_options); -- 2.53.0
