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 <[email protected]>
---
 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


Reply via email to