[tip: objtool/core] objtool: Forward toolchain variables to the klp test runner
From: tip-bot2 for Joe Lawrence
Date: Fri Sep 18 2026 - 06:39:06 EST
The following commit has been merged into the objtool/core branch of tip:
Commit-ID: c0c07fbcdbb1e5b8b6d9e940ab8b848530150f57
Gitweb: https://git.kernel.org/tip/c0c07fbcdbb1e5b8b6d9e940ab8b848530150f57
Author: Joe Lawrence <joe.lawrence@xxxxxxxxxx>
AuthorDate: Wed, 16 Sep 2026 11:43:04 -07:00
Committer: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
CommitterDate: Wed, 16 Sep 2026 17:13:27 -07:00
objtool: Forward toolchain variables to the klp test runner
The tests target already passes ARCH and CROSS_COMPILE into
run-tests.sh. lib.sh uses those to pick a default compiler and
binutils:
CC=${CC:-${CROSS_COMPILE}gcc}
LD=${LD:-${CROSS_COMPILE}ld}
READELF=${READELF:-${CROSS_COMPILE}readelf}
OBJCOPY=${OBJCOPY:-${CROSS_COMPILE}objcopy}
Those defaults only apply when the variables reach the shell that sources
lib.sh. The recipe passed OBJTOOL, ARCH and CROSS_COMPILE explicitly, but
not CC or the binutils. Makefile-assigned values (e.g. from LLVM=1) are
not visible in the recipe environment unless forwarded:
$ LLVM=1 make -C tools/objtool tests
...
# preflight
# compiler gcc (GCC) ...
Pass CC, LD, READELF and OBJCOPY the same way as ARCH and CROSS_COMPILE,
so fixtures are built and inspected with the toolchain make selected:
$ LLVM=1 make -C tools/objtool tests
...
# preflight
# compiler clang version 21.1.8 ...
Signed-off-by: Joe Lawrence <joe.lawrence@xxxxxxxxxx>
Assisted-by: Claude:claude-opus-5
Signed-off-by: Song Liu <song@xxxxxxxxxx>
Link: https://patch.msgid.link/20260916184351.2720310-12-song@xxxxxxxxxx
Signed-off-by: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
---
tools/objtool/Documentation/klp-test-design.txt | 12 +++++++++++-
tools/objtool/Makefile | 9 +++++++++
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/tools/objtool/Documentation/klp-test-design.txt b/tools/objtool/Documentation/klp-test-design.txt
index 67d20bf..2082c27 100644
--- a/tools/objtool/Documentation/klp-test-design.txt
+++ b/tools/objtool/Documentation/klp-test-design.txt
@@ -243,7 +243,17 @@ setting a cross compiler cannot produce one the host is unable to run. ARCH
selects both the objtool target and the directory of tests to run.
clang needs telling, since it defaults to the host triple however it is
-invoked. The fixtures include no kernel headers, so no sysroot is needed:
+invoked. LLVM=1 with CROSS_COMPILE does that for you -- the --target= it
+derives is forwarded to the tests -- and the fixtures include no kernel
+headers, so no sysroot is needed:
+
+::
+
+ ARCH=x86_64 CROSS_COMPILE=x86_64-linux-gnu- LLVM=1 \
+ make -C tools/objtool tests
+
+Naming the compiler by hand works too, and is what to reach for when the
+target triple is not the one CROSS_COMPILE implies:
::
diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile
index ed5cf14..47afe1e 100644
--- a/tools/objtool/Makefile
+++ b/tools/objtool/Makefile
@@ -151,8 +151,17 @@ clean: $(LIBSUBCMD)-clean
mrproper: clean
$(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
+# The kernel's own Makefile sets OBJCOPY, to llvm-objcopy under LLVM and to
+# $(CROSS_COMPILE)objcopy otherwise; tools/scripts/Makefile.include names only
+# LLVM_OBJCOPY and leaves OBJCOPY unset. Forwarding it unset would hand the
+# tests an empty string, and they would fall back to GNU objcopy even when
+# asked for an LLVM toolchain.
+OBJCOPY ?= $(if $(LLVM),$(LLVM_OBJCOPY),$(CROSS_COMPILE)objcopy)
+
tests: $(OBJTOOL)
$(Q)OBJTOOL=$(abspath $(OBJTOOL)) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) \
+ CC='$(CC) $(CLANG_CROSS_FLAGS)' LD='$(LD)' \
+ READELF='$(READELF)' OBJCOPY='$(OBJCOPY)' \
KEEP=$(KEEP) $(srctree)/tools/objtool/tests/run-tests.sh
FORCE: