1From 21909e3f9096fa8e4825df8c65114ee92ab3d532 Mon Sep 17 00:00:00 2001 2From: Zang Ruochen <zangrc.fnst@cn.fujitsu.com> 3Date: Wed, 7 Aug 2019 02:57:35 +0900 4Subject: [PATCH] kpatch-build: add cross-compilation support 5 6This patch introduces new option for kpatch-build 7script "--cross-compile" which can be used for 8specifying cross-complier prefix. 9It allows to build live patches not only on 10target system, but also on hosts for a target other 11than the one on which the compiler is running 12 13Also removed quotes in exec lines, so it is 14possible to pass multy-component strings like 15"ccache x86_64-xelinux-linux-" as cross-compiler 16 17Upstream-Status: Pending 18 19Signed-off-by: Ruslan Bilovol <rbilovol@cisco.com> 20--- 21 kpatch-build/kpatch-build | 13 +++++++++++-- 22 kpatch-build/kpatch-gcc | 4 ++-- 23 2 files changed, 13 insertions(+), 4 deletions(-) 24 25diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build 26index 9ef3809..463dab1 100755 27--- a/kpatch-build/kpatch-build 28+++ b/kpatch-build/kpatch-build 29@@ -198,7 +198,7 @@ gcc_version_check() { 30 # gcc --version varies between distributions therefore extract version 31 # by compiling a test file and compare it to vmlinux's version. 32 echo 'void main(void) {}' > "$c" 33- out="$(gcc -c -pg -ffunction-sections -o "$o" "$c" 2>&1)" 34+ out="$(${KPATCH_CROSS_COMPILE}gcc -c -pg -ffunction-sections -o "$o" "$c" 2>&1)" 35 gccver="$(gcc_version_from_file "$o")" 36 if [[ -n "$OOT_MODULE" ]]; then 37 kgccver="$(gcc_version_from_file "$OOT_MODULE")" 38@@ -411,6 +411,8 @@ usage() { 39 echo " (can be specified multiple times)" >&2 40 echo " -e, --oot-module Enable patching out-of-tree module," >&2 41 echo " specify current version of module" >&2 42+ echo " --cross-compile Specify the prefix used for all executables" >&2 43+ echo " used during compilation" >&2 44 echo " --skip-cleanup Skip post-build cleanup" >&2 45 echo " --skip-gcc-check Skip gcc version matching check" >&2 46 echo " (not recommended)" >&2 47@@ -416,7 +418,7 @@ usage() { 48 echo " (not recommended)" >&2 49 } 50 51-options="$(getopt -o ha:r:s:c:v:j:t:n:o:de: -l "help,archversion:,sourcerpm:,sourcedir:,config:,vmlinux:,jobs:,target:,name:,output:,oot-module:,debug,skip-gcc-check,skip-cleanup" -- "$@")" || die "getopt failed" 52+options="$(getopt -o ha:r:s:c:v:j:t:n:o:de: -l "help,archversion:,sourcerpm:,sourcedir:,config:,vmlinux:,jobs:,target:,name:,output:,oot-module:,debug,cross-compile:,skip-gcc-check,skip-cleanup" -- "$@")" || die "getopt failed" 53 54 eval set -- "$options" 55 56@@ -479,6 +481,10 @@ while [[ $# -gt 0 ]]; do 57 OOT_MODULE="$(readlink -f "$2")" 58 shift 59 ;; 60+ --cross-compile) 61+ KPATCH_CROSS_COMPILE="$2" 62+ shift 63+ ;; 64 --skip-cleanup) 65 echo "Skipping cleanup" 66 SKIPCLEANUP=1 67@@ -757,6 +763,8 @@ if [[ $DEBUG -ge 4 ]]; then 68 export KPATCH_GCC_DEBUG=1 69 fi 70 71+export KPATCH_CROSS_COMPILE 72+ 73 echo "Building original source" 74 [[ -n "$OOT_MODULE" ]] || ./scripts/setlocalversion --save-scmversion || die 75 unset KPATCH_GCC_TEMPDIR 76@@ -940,6 +948,7 @@ fi 77 KPATCH_BUILD="$KPATCH_BUILD" KPATCH_NAME="$MODNAME" \ 78 KBUILD_EXTRA_SYMBOLS="$KBUILD_EXTRA_SYMBOLS" \ 79 KPATCH_LDFLAGS="$KPATCH_LDFLAGS" \ 80+CROSS_COMPILE="$KPATCH_CROSS_COMPILE" \ 81 make 2>&1 | logger || die 82 83 if ! "$KPATCH_MODULE"; then 84diff --git a/kpatch-build/kpatch-gcc b/kpatch-build/kpatch-gcc 85index 9663290..56e6c8f 100755 86--- a/kpatch-build/kpatch-gcc 87+++ b/kpatch-build/kpatch-gcc 88@@ -8,7 +8,7 @@ TOOLCHAINCMD="$1" 89 shift 90 91 if [[ -z "$KPATCH_GCC_TEMPDIR" ]]; then 92- exec "$TOOLCHAINCMD" "$@" 93+ exec ${KPATCH_CROSS_COMPILE}${TOOLCHAINCMD} "$@" 94 fi 95 96 declare -a args=("$@") 97@@ -84,4 +84,4 @@ elif [[ "$TOOLCHAINCMD" = "ld" ]] ; then 98 done 99 fi 100 101-exec "$TOOLCHAINCMD" "${args[@]}" 102+exec ${KPATCH_CROSS_COMPILE}${TOOLCHAINCMD} "${args[@]}" 103-- 1042.7.4 105 106