Add support for cross-compilation. The user must export ARCH, and either CROSS_COMPILE or LLVM as needed.
Signed-off-by: Josh Poimboeuf <[email protected]> --- scripts/livepatch/klp-build | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build index 911ada05673c2..e83973567c878 100755 --- a/scripts/livepatch/klp-build +++ b/scripts/livepatch/klp-build @@ -432,6 +432,25 @@ validate_patches() { revert_patches } +cross_compile_init() { + if [[ -v LLVM && -n "$LLVM" ]]; then + local prefix="" + local suffix="" + + if [[ "$LLVM" == */ ]]; then + # LLVM=/path/to/bin/ + prefix="$LLVM" + elif [[ "$LLVM" == -* ]]; then + # LLVM=-14 + suffix="$LLVM" + fi + + OBJCOPY="${prefix}llvm-objcopy${suffix}" + else + OBJCOPY="${CROSS_COMPILE:-}objcopy" + fi +} + do_init() { # We're not yet smart enough to handle anything other than in-tree # builds in pwd. @@ -462,6 +481,7 @@ do_init() { validate_config set_module_name set_kernelversion + cross_compile_init } # Refresh the patch hunk headers, specifically the line numbers and counts. @@ -871,7 +891,7 @@ build_patch_module() { cp -f "$kmod_file" "$kmod_file.orig" # Work around issue where slight .config change makes corrupt BTF - objcopy --remove-section=.BTF "$kmod_file" + "$OBJCOPY" --remove-section=.BTF "$kmod_file" # Fix (and work around) linker wreckage for klp syms / relocs "$OBJTOOL" klp post-link "$kmod_file" || die "objtool klp post-link failed" -- 2.53.0

