Skip to contentSkip to conversation

klp-build: Support clang/llvm built kernel

PATCH In review Song Liu 2 participants 4 messages Jan 29 – Feb 5 Live patching

lore
Share & tools
lore

Song Liu

author maintainer
#0 lore raw

PATCH 1/1 klp-build: Support clang/llvm built kernel

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

---
 scripts/livepatch/klp-build | 6 ++++++
 1 file changed, 6 insertions(+)
scripts/livepatch/klp-build +6 -0
index a73515a82272..6a446ca7d968 100755
@@ -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
 	(
Signature · 1 line
2.47.3
maintainer
#1 lore raw
Quoted 7 lines · 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

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

Signature · 1 line
Josh
maintainer
#2 lore raw
In reply to Song Liu
Quoted 7 lines · 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

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.

Signature · 1 line
Josh
author maintainer
#3 lore raw
Quoted 16 lines · Josh Poimboeuf
Quoted 7 lines · 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

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

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

Quoted 5 lines

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