blob: 348d82acc1435802ff6e533ed7041c79187bebcb [file] [log] [blame]
Brad Bishop26bdd442019-08-16 17:08:17 -04001From 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
Brad Bishop316dfdd2018-06-25 12:45:53 -04004Subject: [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
Brad Bishop26bdd442019-08-16 17:08:17 -040026index 9ef3809..463dab1 100755
Brad Bishop316dfdd2018-06-25 12:45:53 -040027--- a/kpatch-build/kpatch-build
28+++ b/kpatch-build/kpatch-build
Brad Bishop26bdd442019-08-16 17:08:17 -040029@@ -198,7 +198,7 @@ gcc_version_check() {
Brad Bishop316dfdd2018-06-25 12:45:53 -040030 # 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")"
Brad Bishop26bdd442019-08-16 17:08:17 -040036 if [[ -n "$OOT_MODULE" ]]; then
37 kgccver="$(gcc_version_from_file "$OOT_MODULE")"
38@@ -411,6 +411,8 @@ usage() {
Brad Bishop316dfdd2018-06-25 12:45:53 -040039 echo " (can be specified multiple times)" >&2
Brad Bishop26bdd442019-08-16 17:08:17 -040040 echo " -e, --oot-module Enable patching out-of-tree module," >&2
41 echo " specify current version of module" >&2
Brad Bishop316dfdd2018-06-25 12:45:53 -040042+ 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
Brad Bishop26bdd442019-08-16 17:08:17 -040045 echo " --skip-gcc-check Skip gcc version matching check" >&2
46 echo " (not recommended)" >&2
47@@ -416,7 +418,7 @@ usage() {
Brad Bishop316dfdd2018-06-25 12:45:53 -040048 echo " (not recommended)" >&2
49 }
50
Brad Bishop26bdd442019-08-16 17:08:17 -040051-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"
Brad Bishop316dfdd2018-06-25 12:45:53 -040053
54 eval set -- "$options"
55
Brad Bishop26bdd442019-08-16 17:08:17 -040056@@ -479,6 +481,10 @@ while [[ $# -gt 0 ]]; do
57 OOT_MODULE="$(readlink -f "$2")"
58 shift
Brad Bishop316dfdd2018-06-25 12:45:53 -040059 ;;
60+ --cross-compile)
61+ KPATCH_CROSS_COMPILE="$2"
62+ shift
63+ ;;
64 --skip-cleanup)
65 echo "Skipping cleanup"
66 SKIPCLEANUP=1
Brad Bishop26bdd442019-08-16 17:08:17 -040067@@ -757,6 +763,8 @@ if [[ $DEBUG -ge 4 ]]; then
Brad Bishop316dfdd2018-06-25 12:45:53 -040068 export KPATCH_GCC_DEBUG=1
69 fi
70
71+export KPATCH_CROSS_COMPILE
72+
Brad Bishop26bdd442019-08-16 17:08:17 -040073 echo "Building original source"
74 [[ -n "$OOT_MODULE" ]] || ./scripts/setlocalversion --save-scmversion || die
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080075 unset KPATCH_GCC_TEMPDIR
Brad Bishop26bdd442019-08-16 17:08:17 -040076@@ -940,6 +948,7 @@ fi
77 KPATCH_BUILD="$KPATCH_BUILD" KPATCH_NAME="$MODNAME" \
Brad Bishop316dfdd2018-06-25 12:45:53 -040078 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
Brad Bishop26bdd442019-08-16 17:08:17 -040085index 9663290..56e6c8f 100755
Brad Bishop316dfdd2018-06-25 12:45:53 -040086--- 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=("$@")
Brad Bishop26bdd442019-08-16 17:08:17 -040097@@ -84,4 +84,4 @@ elif [[ "$TOOLCHAINCMD" = "ld" ]] ; then
Brad Bishop316dfdd2018-06-25 12:45:53 -040098 done
99 fi
100
101-exec "$TOOLCHAINCMD" "${args[@]}"
102+exec ${KPATCH_CROSS_COMPILE}${TOOLCHAINCMD} "${args[@]}"
Brad Bishop26bdd442019-08-16 17:08:17 -0400103--
1042.7.4
105