public inbox for live-patching@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] klp-build: Support clang/llvm built kernel
@ 2026-01-29 17:03 Song Liu
  2026-01-29 18:08 ` Josh Poimboeuf
  2026-02-05 16:25 ` Josh Poimboeuf
  0 siblings, 2 replies; 4+ messages in thread
From: Song Liu @ 2026-01-29 17:03 UTC (permalink / raw)
  To: live-patching
  Cc: jpoimboe, kernel-team, jikos, mbenes, pmladek, joe.lawrence,
	Song Liu

When the kernel is built with clang/llvm, it is expected to run make
with "make LLVM=1 ...". The same is needed when building livepatches.

Use CONFIG_CC_IS_CLANG as the flag to detect kernel built with
clang/llvm, and add LLVM=1 to make commands from klp-build

Signed-off-by: Song Liu <song@kernel.org>
---
 scripts/livepatch/klp-build | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build
index a73515a82272..6a446ca7d968 100755
--- a/scripts/livepatch/klp-build
+++ b/scripts/livepatch/klp-build
@@ -49,6 +49,7 @@ KMOD_DIR="$TMP_DIR/kmod"
 STASH_DIR="$TMP_DIR/stash"
 TIMESTAMP="$TMP_DIR/timestamp"
 PATCH_TMP_DIR="$TMP_DIR/tmp"
+USE_LLVM=0
 
 KLP_DIFF_LOG="$DIFF_DIR/diff.log"
 
@@ -249,6 +250,8 @@ validate_config() {
 	[[ -v CONFIG_GCC_PLUGIN_RANDSTRUCT ]] &&	\
 		die "kernel option 'CONFIG_GCC_PLUGIN_RANDSTRUCT' not supported"
 
+	[[ -v CONFIG_CC_IS_CLANG ]] && USE_LLVM=1
+
 	return 0
 }
 
@@ -480,6 +483,7 @@ clean_kernel() {
 	cmd+=("--silent")
 	cmd+=("-j$JOBS")
 	cmd+=("clean")
+	[[ "$USE_LLVM" -eq 1 ]] && cmd+=("LLVM=1")
 
 	(
 		cd "$SRC"
@@ -519,6 +523,7 @@ build_kernel() {
 	cmd+=("OBJTOOL_ARGS=${objtool_args[*]}")
 	cmd+=("vmlinux")
 	cmd+=("modules")
+	[[ "$USE_LLVM" -eq 1 ]] && cmd+=("LLVM=1")
 
 	(
 		cd "$SRC"
@@ -764,6 +769,7 @@ build_patch_module() {
 	cmd+=("--directory=.")
 	cmd+=("M=$KMOD_DIR")
 	cmd+=("KCFLAGS=${cflags[*]}")
+	[[ "$USE_LLVM" -eq 1 ]] && cmd+=("LLVM=1")
 
 	# Build a "normal" kernel module with init.c and the diffed objects
 	(
-- 
2.47.3


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

* Re: [PATCH] klp-build: Support clang/llvm built kernel
  2026-01-29 17:03 [PATCH] klp-build: Support clang/llvm built kernel Song Liu
@ 2026-01-29 18:08 ` Josh Poimboeuf
  2026-02-05 16:25 ` Josh Poimboeuf
  1 sibling, 0 replies; 4+ messages in thread
From: Josh Poimboeuf @ 2026-01-29 18:08 UTC (permalink / raw)
  To: Song Liu; +Cc: live-patching, kernel-team, jikos, mbenes, pmladek, joe.lawrence

On Thu, Jan 29, 2026 at 09:03:21AM -0800, Song Liu wrote:
> When the kernel is built with clang/llvm, it is expected to run make
> with "make LLVM=1 ...". The same is needed when building livepatches.
> 
> Use CONFIG_CC_IS_CLANG as the flag to detect kernel built with
> clang/llvm, and add LLVM=1 to make commands from klp-build
> 
> Signed-off-by: Song Liu <song@kernel.org>

Indeed, I had tested by exporting LLVM=1, but this is better...  Thanks!

-- 
Josh

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

* Re: [PATCH] klp-build: Support clang/llvm built kernel
  2026-01-29 17:03 [PATCH] klp-build: Support clang/llvm built kernel Song Liu
  2026-01-29 18:08 ` Josh Poimboeuf
@ 2026-02-05 16:25 ` Josh Poimboeuf
  2026-02-05 16:50   ` Song Liu
  1 sibling, 1 reply; 4+ messages in thread
From: Josh Poimboeuf @ 2026-02-05 16:25 UTC (permalink / raw)
  To: Song Liu; +Cc: live-patching, kernel-team, jikos, mbenes, pmladek, joe.lawrence

On Thu, Jan 29, 2026 at 09:03:21AM -0800, Song Liu wrote:
> When the kernel is built with clang/llvm, it is expected to run make
> with "make LLVM=1 ...". The same is needed when building livepatches.
> 
> Use CONFIG_CC_IS_CLANG as the flag to detect kernel built with
> clang/llvm, and add LLVM=1 to make commands from klp-build
> 
> Signed-off-by: Song Liu <song@kernel.org>

Peter informed me that "LLVM=" has different syntaxes:

  LLVM=1
  LLVM=-22
  LLVM=/opt/llvm/

Debian has parallel llvm (and gcc) toolchains, and suffixes them with
-$ver.

So we dropped this patch for now.  "export LLVM=1" still works.  Not
sure if you have any other ideas?

At the very least we should probably check that LLVM=<whatever> and/or
CC=clang are set appropriately before doing a CONFIG_CC_IS_CLANG build,
and error out if not.

-- 
Josh

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

* Re: [PATCH] klp-build: Support clang/llvm built kernel
  2026-02-05 16:25 ` Josh Poimboeuf
@ 2026-02-05 16:50   ` Song Liu
  0 siblings, 0 replies; 4+ messages in thread
From: Song Liu @ 2026-02-05 16:50 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: live-patching, kernel-team, jikos, mbenes, pmladek, joe.lawrence

On Thu, Feb 5, 2026 at 8:25 AM Josh Poimboeuf <jpoimboe@kernel.org> wrote:
>
> On Thu, Jan 29, 2026 at 09:03:21AM -0800, Song Liu wrote:
> > When the kernel is built with clang/llvm, it is expected to run make
> > with "make LLVM=1 ...". The same is needed when building livepatches.
> >
> > Use CONFIG_CC_IS_CLANG as the flag to detect kernel built with
> > clang/llvm, and add LLVM=1 to make commands from klp-build
> >
> > Signed-off-by: Song Liu <song@kernel.org>
>
> Peter informed me that "LLVM=" has different syntaxes:
>
>   LLVM=1
>   LLVM=-22
>   LLVM=/opt/llvm/
>
> Debian has parallel llvm (and gcc) toolchains, and suffixes them with
> -$ver.
>
> So we dropped this patch for now.  "export LLVM=1" still works.  Not
> sure if you have any other ideas?

Hmm... I guess "export LLVM=something" is probably the best option
for now.

Thanks,
Song

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

end of thread, other threads:[~2026-02-05 16:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-29 17:03 [PATCH] klp-build: Support clang/llvm built kernel Song Liu
2026-01-29 18:08 ` Josh Poimboeuf
2026-02-05 16:25 ` Josh Poimboeuf
2026-02-05 16:50   ` Song Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox