All of lore.kernel.org
 help / color / mirror / Atom feed
* [OE-core][PATCH 0/3] kernel: make the kernel toolchain switchable to clang
@ 2026-07-08  2:28 mark.yang
  2026-07-08  2:28 ` [OE-core][PATCH 1/3] module.bbclass/make-mod-scripts: inhibit default dependencies mark.yang
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: mark.yang @ 2026-07-08  2:28 UTC (permalink / raw)
  To: openembedded-core; +Cc: mark.yang

From: "mark.yang" <mark.yang@lge.com>

Building the kernel with clang currently means overriding TOOLCHAIN and
the KERNEL_* variables in a bbappend. The kernel builds, but modules and
make-mod-scripts keep the gcc defaults and run the shared kernel build
tree with the other compiler. kbuild then re-runs syncconfig against the
shared .config and silently drops compiler-dependent options: a
CONFIG_CFI_CLANG kernel loses kCFI as soon as any module is built.
Documentation/kbuild/llvm.rst requires the same toolchain for every make
invocation against one tree.

This series adds a KERNEL_TOOLCHAIN switch so the kernel, modules and
make-mod-scripts move to clang together. gcc remains the default.

Tested on qemux86-64 with clang and gcc: both toolchains
build linux-yocto, make-mod-scripts and cryptodev-module, the shared
.config stays consistent across module builds (also with ld-is-lld),
and core-image-sato boots.

mark.yang (3):
  module.bbclass/make-mod-scripts: inhibit default dependencies
  kernel-yocto: export CLANG_FLAGS for the kconfiglib config audit
  kernel-arch: add KERNEL_TOOLCHAIN for building the kernel with clang

 meta/classes-recipe/kernel-arch.bbclass             | 13 ++++++++++++-
 meta/classes-recipe/kernel-yocto.bbclass            |  7 +++++++
 meta/classes-recipe/module.bbclass                  |  5 +++++
 .../make-mod-scripts/make-mod-scripts_1.0.bb        |  5 +++++
 4 files changed, 29 insertions(+), 1 deletion(-)



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [OE-core][PATCH 1/3] module.bbclass/make-mod-scripts: inhibit default dependencies
  2026-07-08  2:28 [OE-core][PATCH 0/3] kernel: make the kernel toolchain switchable to clang mark.yang
@ 2026-07-08  2:28 ` mark.yang
  2026-07-08  2:28 ` [OE-core][PATCH 2/3] kernel-yocto: export CLANG_FLAGS for the kconfiglib config audit mark.yang
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: mark.yang @ 2026-07-08  2:28 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 like kernel.bbclass does.

This also avoids dragging compiler-rt and libcxx into every module
build when TOOLCHAIN is set to clang.

Signed-off-by: mark.yang <mark.yang@lge.com>
---
 meta/classes-recipe/module.bbclass                           | 5 +++++
 meta/recipes-kernel/make-mod-scripts/make-mod-scripts_1.0.bb | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/meta/classes-recipe/module.bbclass b/meta/classes-recipe/module.bbclass
index 6b2c09f441..a65744d33e 100644
--- a/meta/classes-recipe/module.bbclass
+++ b/meta/classes-recipe/module.bbclass
@@ -6,6 +6,11 @@
 
 inherit module-base kernel-module-split pkgconfig
 
+# Modules build with the kernel toolchain against the shared kernel build tree
+# and do not need the default userspace toolchain/libc dependencies.
+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..97521c89e9 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,11 @@ DEV_PKG_DEPENDENCY = ""
 DEPENDS += "bc-native bison-native"
 DEPENDS += "gmp-native"
 
+# The scripts build uses the kernel toolchain against the shared kernel build
+# tree and does not need the default userspace toolchain/libc dependencies.
+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] 6+ messages in thread

* [OE-core][PATCH 2/3] kernel-yocto: export CLANG_FLAGS for the kconfiglib config audit
  2026-07-08  2:28 [OE-core][PATCH 0/3] kernel: make the kernel toolchain switchable to clang mark.yang
  2026-07-08  2:28 ` [OE-core][PATCH 1/3] module.bbclass/make-mod-scripts: inhibit default dependencies mark.yang
@ 2026-07-08  2:28 ` mark.yang
  2026-07-08  2:28 ` [OE-core][PATCH 3/3] kernel-arch: add KERNEL_TOOLCHAIN for building the kernel with clang mark.yang
  2026-07-08  2:37 ` [OE-core][PATCH 0/3] kernel: make the kernel toolchain switchable to clang Bruce Ashfield
  3 siblings, 0 replies; 6+ messages in thread
From: mark.yang @ 2026-07-08  2:28 UTC (permalink / raw)
  To: openembedded-core; +Cc: mark.yang

From: "mark.yang" <mark.yang@lge.com>

do_kernel_configcheck evaluates Kconfig with kconfiglib instead of
kbuild make, so scripts/Makefile.clang never sets CLANG_FLAGS and the
compiler checks in scripts/Kconfig.include pick it up from the
environment. With TOOLCHAIN = "clang" the audit fails:

  Sorry, this assembler is not supported.

as-version.sh needs -fintegrated-as in the arguments to recognize the
integrated assembler. Export the flags kbuild would use, with gcc this
expands to nothing.

Signed-off-by: mark.yang <mark.yang@lge.com>
---
 meta/classes-recipe/kernel-yocto.bbclass | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/meta/classes-recipe/kernel-yocto.bbclass b/meta/classes-recipe/kernel-yocto.bbclass
index e7fdeb5d4b..46ccc69e75 100644
--- a/meta/classes-recipe/kernel-yocto.bbclass
+++ b/meta/classes-recipe/kernel-yocto.bbclass
@@ -578,6 +578,13 @@ python do_config_analysis() {
                 bb.warn( analysis )
 }
 
+# The kconfiglib audit evaluates Kconfig's compiler checks outside kbuild make,
+# where scripts/Makefile.clang would normally set CLANG_FLAGS, so provide it
+# via the environment.
+CLANG_FLAGS ?= ""
+CLANG_FLAGS:toolchain-clang = "--target=${HOST_SYS} -fintegrated-as"
+export CLANG_FLAGS
+
 python do_kernel_configcheck() {
     import re, string, sys, subprocess
 


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [OE-core][PATCH 3/3] kernel-arch: add KERNEL_TOOLCHAIN for building the kernel with clang
  2026-07-08  2:28 [OE-core][PATCH 0/3] kernel: make the kernel toolchain switchable to clang mark.yang
  2026-07-08  2:28 ` [OE-core][PATCH 1/3] module.bbclass/make-mod-scripts: inhibit default dependencies mark.yang
  2026-07-08  2:28 ` [OE-core][PATCH 2/3] kernel-yocto: export CLANG_FLAGS for the kconfiglib config audit mark.yang
@ 2026-07-08  2:28 ` mark.yang
  2026-07-08  2:37 ` [OE-core][PATCH 0/3] kernel: make the kernel toolchain switchable to clang Bruce Ashfield
  3 siblings, 0 replies; 6+ messages in thread
From: mark.yang @ 2026-07-08  2:28 UTC (permalink / raw)
  To: openembedded-core; +Cc: mark.yang

From: "mark.yang" <mark.yang@lge.com>

kernel-arch pins TOOLCHAIN to gcc, so a clang kernel needs TOOLCHAIN
and the KERNEL_* variables overridden per recipe. Modules and
make-mod-scripts then keep the gcc defaults and run make against the
shared kernel build tree with a different compiler: kbuild detects the
CC_VERSION_TEXT mismatch, re-runs syncconfig and silently drops
compiler-dependent options such as CONFIG_CFI_CLANG.

Add toolchain-clang variants of KERNEL_CC, KERNEL_LD and KERNEL_AR and
a KERNEL_TOOLCHAIN switch covering all kernel-arch recipes, so the
kernel, modules and make-mod-scripts change toolchain together. The
default stays gcc.

-fuse-ld is left out of KERNEL_CC because the kernel links with
KERNEL_LD directly and kbuild's -Werror=unused-command-line-argument
rejects the unused option. KERNEL_LD uses ld.lld when the distro has
ld-is-lld (clang-cross only installs the symlink then), GNU ld.bfd
otherwise.

Signed-off-by: mark.yang <mark.yang@lge.com>
---
 meta/classes-recipe/kernel-arch.bbclass | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/meta/classes-recipe/kernel-arch.bbclass b/meta/classes-recipe/kernel-arch.bbclass
index 7aea9cd3e8..7e83a09b1c 100644
--- a/meta/classes-recipe/kernel-arch.bbclass
+++ b/meta/classes-recipe/kernel-arch.bbclass
@@ -76,9 +76,20 @@ KERNEL_CC = "${CCACHE}${HOST_PREFIX}gcc ${HOST_CC_KERNEL_ARCH} \
  -ffile-prefix-map=${STAGING_KERNEL_DIR}=${KERNEL_SRC_PATH} \
  -ffile-prefix-map=${STAGING_KERNEL_BUILDDIR}=${KERNEL_SRC_PATH} \
 "
+KERNEL_CC:toolchain-clang = "${CCACHE}${HOST_PREFIX}clang ${HOST_CC_KERNEL_ARCH} \
+ ${DEBUG_PREFIX_MAP} \
+ -ffile-prefix-map=${STAGING_KERNEL_DIR}=${KERNEL_SRC_PATH} \
+ -ffile-prefix-map=${STAGING_KERNEL_BUILDDIR}=${KERNEL_SRC_PATH} \
+"
 KERNEL_LD = "${HOST_PREFIX}ld.bfd ${HOST_LD_KERNEL_ARCH}"
+KERNEL_LD:toolchain-clang = "${@bb.utils.contains('DISTRO_FEATURES', 'ld-is-lld', '${HOST_PREFIX}ld.lld', '${HOST_PREFIX}ld.bfd', d)} ${HOST_LD_KERNEL_ARCH}"
 KERNEL_AR = "${HOST_PREFIX}ar ${HOST_AR_KERNEL_ARCH}"
+KERNEL_AR:toolchain-clang = "${HOST_PREFIX}llvm-ar ${HOST_AR_KERNEL_ARCH}"
 KERNEL_OBJCOPY = "${HOST_PREFIX}objcopy ${HOST_OBJCOPY_KERNEL_ARCH}"
 # Code in package.py can't handle options on KERNEL_STRIP
 KERNEL_STRIP = "${HOST_PREFIX}strip"
-TOOLCHAIN = "gcc"
+# The kernel, out-of-tree modules and make-mod-scripts share one kernel build
+# tree and must agree on the toolchain, so switch it with KERNEL_TOOLCHAIN
+# rather than setting TOOLCHAIN on individual recipes.
+KERNEL_TOOLCHAIN ?= "gcc"
+TOOLCHAIN = "${KERNEL_TOOLCHAIN}"


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [OE-core][PATCH 0/3] kernel: make the kernel toolchain switchable to clang
  2026-07-08  2:28 [OE-core][PATCH 0/3] kernel: make the kernel toolchain switchable to clang mark.yang
                   ` (2 preceding siblings ...)
  2026-07-08  2:28 ` [OE-core][PATCH 3/3] kernel-arch: add KERNEL_TOOLCHAIN for building the kernel with clang mark.yang
@ 2026-07-08  2:37 ` Bruce Ashfield
  2026-07-08  2:44   ` [PATCH " mark.yang
  3 siblings, 1 reply; 6+ messages in thread
From: Bruce Ashfield @ 2026-07-08  2:37 UTC (permalink / raw)
  To: mark.yang; +Cc: openembedded-core

Why do we have this series, when it is almost identical to the one
sent by Harish Sadineni ?

Bruce

On Tue, Jul 7, 2026 at 10:30 PM mark.yang via lists.openembedded.org
<mark.yang=lge.com@lists.openembedded.org> wrote:
>
> From: "mark.yang" <mark.yang@lge.com>
>
> Building the kernel with clang currently means overriding TOOLCHAIN and
> the KERNEL_* variables in a bbappend. The kernel builds, but modules and
> make-mod-scripts keep the gcc defaults and run the shared kernel build
> tree with the other compiler. kbuild then re-runs syncconfig against the
> shared .config and silently drops compiler-dependent options: a
> CONFIG_CFI_CLANG kernel loses kCFI as soon as any module is built.
> Documentation/kbuild/llvm.rst requires the same toolchain for every make
> invocation against one tree.
>
> This series adds a KERNEL_TOOLCHAIN switch so the kernel, modules and
> make-mod-scripts move to clang together. gcc remains the default.
>
> Tested on qemux86-64 with clang and gcc: both toolchains
> build linux-yocto, make-mod-scripts and cryptodev-module, the shared
> .config stays consistent across module builds (also with ld-is-lld),
> and core-image-sato boots.
>
> mark.yang (3):
>   module.bbclass/make-mod-scripts: inhibit default dependencies
>   kernel-yocto: export CLANG_FLAGS for the kconfiglib config audit
>   kernel-arch: add KERNEL_TOOLCHAIN for building the kernel with clang
>
>  meta/classes-recipe/kernel-arch.bbclass             | 13 ++++++++++++-
>  meta/classes-recipe/kernel-yocto.bbclass            |  7 +++++++
>  meta/classes-recipe/module.bbclass                  |  5 +++++
>  .../make-mod-scripts/make-mod-scripts_1.0.bb        |  5 +++++
>  4 files changed, 29 insertions(+), 1 deletion(-)
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#240415): https://lists.openembedded.org/g/openembedded-core/message/240415
> Mute This Topic: https://lists.openembedded.org/mt/120168206/1050810
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [bruce.ashfield@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>


-- 
- Thou shalt not follow the NULL pointer, for chaos and madness await
thee at its end
- "Use the force Harry" - Gandalf, Star Trek II


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/3] kernel: make the kernel toolchain switchable to clang
  2026-07-08  2:37 ` [OE-core][PATCH 0/3] kernel: make the kernel toolchain switchable to clang Bruce Ashfield
@ 2026-07-08  2:44   ` mark.yang
  0 siblings, 0 replies; 6+ messages in thread
From: mark.yang @ 2026-07-08  2:44 UTC (permalink / raw)
  To: openembedded-core

[-- Attachment #1: Type: text/plain, Size: 867 bytes --]

Hi Bruce,

Bad timing on my part - I posted this before spotting Harish's series,
sorry for the noise.

It's not quite the same though: the point of this series is patches 1
and 3, keeping the kernel, out-of-tree modules and make-mod-scripts on
one toolchain. With only the kernel recipe switched to clang, modules
and make-mod-scripts still run make against the shared kernel build
tree with the gcc defaults; kbuild notices the CC_VERSION_TEXT mismatch
and re-runs syncconfig, silently dropping compiler-dependent options
from the shared .config - CONFIG_CFI_CLANG for example disappears as
soon as any out-of-tree module is built, with no error anywhere.
Reproduced on qemux86-64 with cryptodev-module.

I'll drop the two patches that overlap with Harish's series and send a
v2 with the module/make-mod-scripts side rebased on top of his.

Mark

[-- Attachment #2: Type: text/html, Size: 950 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-07-08  2:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-08  2:28 [OE-core][PATCH 0/3] kernel: make the kernel toolchain switchable to clang mark.yang
2026-07-08  2:28 ` [OE-core][PATCH 1/3] module.bbclass/make-mod-scripts: inhibit default dependencies mark.yang
2026-07-08  2:28 ` [OE-core][PATCH 2/3] kernel-yocto: export CLANG_FLAGS for the kconfiglib config audit mark.yang
2026-07-08  2:28 ` [OE-core][PATCH 3/3] kernel-arch: add KERNEL_TOOLCHAIN for building the kernel with clang mark.yang
2026-07-08  2:37 ` [OE-core][PATCH 0/3] kernel: make the kernel toolchain switchable to clang Bruce Ashfield
2026-07-08  2:44   ` [PATCH " mark.yang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.