From: mark.yang@lge.com
To: openembedded-core@lists.openembedded.org
Cc: "mark.yang" <mark.yang@lge.com>
Subject: [OE-core][PATCH 3/3] kernel-arch: add KERNEL_TOOLCHAIN for building the kernel with clang
Date: Wed, 8 Jul 2026 11:28:56 +0900 [thread overview]
Message-ID: <20260708022856.2087339-4-mark.yang@lge.com> (raw)
In-Reply-To: <20260708022856.2087339-1-mark.yang@lge.com>
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}"
next prev parent reply other threads:[~2026-07-08 2:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260708022856.2087339-4-mark.yang@lge.com \
--to=mark.yang@lge.com \
--cc=openembedded-core@lists.openembedded.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.