* [PATCH v3 0/3] kernel: make the kernel toolchain switchable to clang
@ 2026-07-20 9:31 mark.yang
2026-07-20 9:31 ` [PATCH v3 1/3] kernel-arch: fall back to GNU ld unless ld-is-lld is in DISTRO_FEATURES mark.yang
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: mark.yang @ 2026-07-20 9:31 UTC (permalink / raw)
To: openembedded-core; +Cc: mark.yang
From: "mark.yang" <mark.yang@lge.com>
Since v1, clang kernel toolchain support has been merged to master
with 928d81916f ("kernel-arch: Add clang toolchain support") and
e88ee794a3 ("kernel-yocto: Set CLANG_FLAGS for kernel config checks
when using clang"), superseding two of the three v1 patches. As
discussed on the v1 thread, this rework contains what remains on top
of current master.
On current master a clang kernel only builds when ld-is-lld happens to
be in DISTRO_FEATURES, since nothing else stages a bare ld.lld:
scripts/Kconfig.include:41: linker 'ld.lld ' not found
Full log: https://errors.yoctoproject.org/Errors/Build/242422/
Patch 1 falls back to GNU ld in that case.
kbuild wants the same toolchain for every make invocation against a
build tree (Documentation/kbuild/llvm.rst: "The same value used for
LLVM= should be set for each invocation of make"), and the out-of-tree
module and make-mod-scripts builds run make against that same tree.
Setting TOOLCHAIN on the kernel recipe alone leaves them on the gcc
defaults: kbuild spots the CC_VERSION_TEXT mismatch and silently
regenerates .config. On current master, building cryptodev-module
after a clang kernel succeeds without a warning, produces a gcc .ko
and flips the shared .config back to CONFIG_CC_IS_GCC.
The toolchain has to be known at parse time to set up the cross
toolchain dependencies, so this needs to be a configuration variable.
Patch 2 moves modules and make-mod-scripts onto explicit cross
toolchain dependencies and patch 3 adds a KERNEL_TOOLCHAIN switch
covering the kernel, modules and make-mod-scripts.
Tested on qemux86-64 (master aa33c4317d, clang 22.1.8, gcc 16.1.0):
with KERNEL_TOOLCHAIN unset, core-image-minimal and cryptodev-module
build with gcc as before. With KERNEL_TOOLCHAIN = "clang" the kernel,
make-mod-scripts and cryptodev-module all build with clang, the shared
.config keeps CONFIG_CC_IS_CLANG after the module build, and linking
uses GNU ld, or LLD with ld-is-lld in DISTRO_FEATURES. u-boot keeps
building with gcc.
mark.yang (3):
kernel-arch: fall back to GNU ld unless ld-is-lld is in
DISTRO_FEATURES
module.bbclass/make-mod-scripts: inhibit default dependencies
kernel: add KERNEL_TOOLCHAIN to switch the whole kernel toolchain
meta/classes-recipe/kernel-arch.bbclass | 3 ++-
meta/classes-recipe/kernel.bbclass | 1 +
meta/classes-recipe/module-base.bbclass | 1 +
meta/classes-recipe/module.bbclass | 3 +++
meta/recipes-kernel/make-mod-scripts/make-mod-scripts_1.0.bb | 4 ++++
5 files changed, 11 insertions(+), 1 deletion(-)
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v3 1/3] kernel-arch: fall back to GNU ld unless ld-is-lld is in DISTRO_FEATURES
2026-07-20 9:31 [PATCH v3 0/3] kernel: make the kernel toolchain switchable to clang mark.yang
@ 2026-07-20 9:31 ` mark.yang
2026-07-20 9:31 ` [PATCH v3 2/3] module.bbclass/make-mod-scripts: inhibit default dependencies mark.yang
2026-07-20 9:31 ` [PATCH v3] kernel: add KERNEL_TOOLCHAIN to switch the whole kernel toolchain mark.yang
2 siblings, 0 replies; 4+ messages in thread
From: mark.yang @ 2026-07-20 9:31 UTC (permalink / raw)
To: openembedded-core; +Cc: mark.yang
From: "mark.yang" <mark.yang@lge.com>
Nothing stages a bare ld.lld unless ld-is-lld is in DISTRO_FEATURES,
so a clang kernel fails its first linker check on any other setup.
Use GNU ld.bfd from binutils-cross instead.
Signed-off-by: mark.yang <mark.yang@lge.com>
---
v3: no changes
v2: new patch; the merged clang support uses a bare ld.lld which
nothing stages without ld-is-lld
meta/classes-recipe/kernel-arch.bbclass | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/meta/classes-recipe/kernel-arch.bbclass b/meta/classes-recipe/kernel-arch.bbclass
index 6ebc0f13ea..321c9ed577 100644
--- a/meta/classes-recipe/kernel-arch.bbclass
+++ b/meta/classes-recipe/kernel-arch.bbclass
@@ -88,7 +88,7 @@ KERNEL_CC:toolchain-clang = "${CCACHE}clang ${HOST_CC_KERNEL_ARCH} \
-ffile-prefix-map=${STAGING_KERNEL_DIR}=${KERNEL_SRC_PATH} \
-ffile-prefix-map=${STAGING_KERNEL_BUILDDIR}=${KERNEL_SRC_PATH} \
"
-KERNEL_LD:toolchain-clang = "ld.lld ${HOST_LD_KERNEL_ARCH}"
+KERNEL_LD:toolchain-clang = "${@bb.utils.contains('DISTRO_FEATURES', 'ld-is-lld', 'ld.lld', '${HOST_PREFIX}ld.bfd', d)} ${HOST_LD_KERNEL_ARCH}"
KERNEL_AR:toolchain-clang = "llvm-ar ${HOST_AR_KERNEL_ARCH}"
KERNEL_OBJCOPY:toolchain-clang = "llvm-objcopy ${HOST_OBJCOPY_KERNEL_ARCH}"
KERNEL_STRIP:toolchain-clang = "llvm-strip"
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH v3 2/3] module.bbclass/make-mod-scripts: inhibit default dependencies
2026-07-20 9:31 [PATCH v3 0/3] kernel: make the kernel toolchain switchable to clang mark.yang
2026-07-20 9:31 ` [PATCH v3 1/3] kernel-arch: fall back to GNU ld unless ld-is-lld is in DISTRO_FEATURES mark.yang
@ 2026-07-20 9:31 ` mark.yang
2026-07-20 9:31 ` [PATCH v3] kernel: add KERNEL_TOOLCHAIN to switch the whole kernel toolchain mark.yang
2 siblings, 0 replies; 4+ messages in thread
From: mark.yang @ 2026-07-20 9:31 UTC (permalink / raw)
To: openembedded-core; +Cc: mark.yang
From: "mark.yang" <mark.yang@lge.com>
Modules and make-mod-scripts build against the shared kernel build
tree with the kernel toolchain, so the default virtual/libc and
virtual/compilerlibs dependencies are unused. Inhibit them and add
the cross toolchain explicitly, as kernel.bbclass does, which also
keeps compiler-rt and libcxx out of module builds with clang.
Signed-off-by: mark.yang <mark.yang@lge.com>
---
v3: no changes
v2: split out of the KERNEL_TOOLCHAIN patch
meta/classes-recipe/module.bbclass | 3 +++
meta/recipes-kernel/make-mod-scripts/make-mod-scripts_1.0.bb | 3 +++
2 files changed, 6 insertions(+)
diff --git a/meta/classes-recipe/module.bbclass b/meta/classes-recipe/module.bbclass
index 6b2c09f441..ce5898125b 100644
--- a/meta/classes-recipe/module.bbclass
+++ b/meta/classes-recipe/module.bbclass
@@ -6,6 +6,9 @@
inherit module-base kernel-module-split pkgconfig
+INHIBIT_DEFAULT_DEPS = "1"
+DEPENDS += "virtual/cross-cc virtual/cross-binutils"
+
EXTRA_OEMAKE += "KERNEL_SRC=${STAGING_KERNEL_DIR}"
MODULES_INSTALL_TARGET ?= "modules_install"
diff --git a/meta/recipes-kernel/make-mod-scripts/make-mod-scripts_1.0.bb b/meta/recipes-kernel/make-mod-scripts/make-mod-scripts_1.0.bb
index 4b0630313f..338a50de91 100644
--- a/meta/recipes-kernel/make-mod-scripts/make-mod-scripts_1.0.bb
+++ b/meta/recipes-kernel/make-mod-scripts/make-mod-scripts_1.0.bb
@@ -18,6 +18,9 @@ DEV_PKG_DEPENDENCY = ""
DEPENDS += "bc-native bison-native"
DEPENDS += "gmp-native"
+INHIBIT_DEFAULT_DEPS = "1"
+DEPENDS += "virtual/cross-cc virtual/cross-binutils"
+
EXTRA_OEMAKE = " HOSTCC="${BUILD_CC}" HOSTCFLAGS="${BUILD_CFLAGS}" HOSTLDFLAGS="${BUILD_LDFLAGS}" HOSTCPP="${BUILD_CPP}""
EXTRA_OEMAKE += " HOSTCXX="${BUILD_CXX} ${BUILD_CXXFLAGS} ${BUILD_LDFLAGS}" CROSS_COMPILE=${TARGET_PREFIX}"
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH v3] kernel: add KERNEL_TOOLCHAIN to switch the whole kernel toolchain
2026-07-20 9:31 [PATCH v3 0/3] kernel: make the kernel toolchain switchable to clang mark.yang
2026-07-20 9:31 ` [PATCH v3 1/3] kernel-arch: fall back to GNU ld unless ld-is-lld is in DISTRO_FEATURES mark.yang
2026-07-20 9:31 ` [PATCH v3 2/3] module.bbclass/make-mod-scripts: inhibit default dependencies mark.yang
@ 2026-07-20 9:31 ` mark.yang
2 siblings, 0 replies; 4+ messages in thread
From: mark.yang @ 2026-07-20 9:31 UTC (permalink / raw)
To: openembedded-core; +Cc: mark.yang
From: "mark.yang" <mark.yang@lge.com>
Setting TOOLCHAIN on the kernel recipe alone leaves modules and
make-mod-scripts running make against the shared build tree with gcc;
kbuild spots the CC_VERSION_TEXT mismatch and silently regenerates
the shared .config. Add a KERNEL_TOOLCHAIN switch so the kernel,
modules and make-mod-scripts change toolchain together, gcc by default.
Set TOOLCHAIN from it in the kbuild consumers rather than in
kernel-arch: kernel-arch is also inherited by u-boot and barebox for
the ARCH mapping, and the u-boot kbuild hardcodes ${CROSS_COMPILE}gcc,
so switching them too would drop the gcc cross dependency they need:
/bin/sh: 1: x86_64-oe-linux-gcc: not found
Full log: https://errors.yoctoproject.org/Errors/Build/242654/
Signed-off-by: mark.yang <mark.yang@lge.com>
---
v3: set TOOLCHAIN from the kbuild consumers instead of kernel-arch,
which is also inherited by u-boot and barebox
v2: rebased on the merged clang toolchain support which supersedes
the other v1 patches; dependency changes split out into patch 2
meta/classes-recipe/kernel-arch.bbclass | 1 +
meta/classes-recipe/kernel.bbclass | 1 +
meta/classes-recipe/module-base.bbclass | 1 +
meta/recipes-kernel/make-mod-scripts/make-mod-scripts_1.0.bb | 1 +
4 files changed, 4 insertions(+)
diff --git a/meta/classes-recipe/kernel-arch.bbclass b/meta/classes-recipe/kernel-arch.bbclass
index 321c9ed577..b15e0aca80 100644
--- a/meta/classes-recipe/kernel-arch.bbclass
+++ b/meta/classes-recipe/kernel-arch.bbclass
@@ -92,4 +92,5 @@ KERNEL_LD:toolchain-clang = "${@bb.utils.contains('DISTRO_FEATURES', 'ld-is-lld'
KERNEL_AR:toolchain-clang = "llvm-ar ${HOST_AR_KERNEL_ARCH}"
KERNEL_OBJCOPY:toolchain-clang = "llvm-objcopy ${HOST_OBJCOPY_KERNEL_ARCH}"
KERNEL_STRIP:toolchain-clang = "llvm-strip"
+KERNEL_TOOLCHAIN ?= "gcc"
TOOLCHAIN = "gcc"
diff --git a/meta/classes-recipe/kernel.bbclass b/meta/classes-recipe/kernel.bbclass
index 48e394b650..a90122354a 100644
--- a/meta/classes-recipe/kernel.bbclass
+++ b/meta/classes-recipe/kernel.bbclass
@@ -214,6 +214,7 @@ python do_symlink_kernsrc () {
addtask symlink_kernsrc before do_patch do_configure after do_unpack
inherit kernel-arch deploy
+TOOLCHAIN = "${KERNEL_TOOLCHAIN}"
PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-module-.*"
PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-image-.*"
diff --git a/meta/classes-recipe/module-base.bbclass b/meta/classes-recipe/module-base.bbclass
index 2a225881ba..cae71a9b15 100644
--- a/meta/classes-recipe/module-base.bbclass
+++ b/meta/classes-recipe/module-base.bbclass
@@ -5,6 +5,7 @@
#
inherit kernel-arch
+TOOLCHAIN = "${KERNEL_TOOLCHAIN}"
# We do the dependency this way because the output is not preserved
# in sstate, so we must force do_compile to run (once).
diff --git a/meta/recipes-kernel/make-mod-scripts/make-mod-scripts_1.0.bb b/meta/recipes-kernel/make-mod-scripts/make-mod-scripts_1.0.bb
index 338a50de91..d11afa86a1 100644
--- a/meta/recipes-kernel/make-mod-scripts/make-mod-scripts_1.0.bb
+++ b/meta/recipes-kernel/make-mod-scripts/make-mod-scripts_1.0.bb
@@ -4,6 +4,7 @@ LICENSE = "GPL-2.0-only"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/GPL-2.0-only;md5=801f80980d171dd6425610833a22dbe6"
inherit kernel-arch linux-kernel-base
+TOOLCHAIN = "${KERNEL_TOOLCHAIN}"
inherit pkgconfig
PACKAGE_ARCH = "${MACHINE_ARCH}"
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-07-20 9:31 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-20 9:31 [PATCH v3 0/3] kernel: make the kernel toolchain switchable to clang mark.yang
2026-07-20 9:31 ` [PATCH v3 1/3] kernel-arch: fall back to GNU ld unless ld-is-lld is in DISTRO_FEATURES mark.yang
2026-07-20 9:31 ` [PATCH v3 2/3] module.bbclass/make-mod-scripts: inhibit default dependencies mark.yang
2026-07-20 9:31 ` [PATCH v3] kernel: add KERNEL_TOOLCHAIN to switch the whole kernel toolchain mark.yang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox