blob: 459fb219772d44b1ecb699a82e0a669a3d9793ae [file] [log] [blame]
Brad Bishop316dfdd2018-06-25 12:45:53 -04001From a9a80a1f4df65892a0269295ce8a64b06f2ff61d Mon Sep 17 00:00:00 2001
2From: Ruslan Bilovol <rbilovol@cisco.com>
3Date: Tue, 19 Dec 2017 15:59:04 +0200
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 166ecbd..af24cc4 100755
27--- a/kpatch-build/kpatch-build
28+++ b/kpatch-build/kpatch-build
29@@ -195,7 +195,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 kgccver="$(gcc_version_from_file "$VMLINUX")"
37 rm -f "$c" "$o"
38@@ -381,12 +381,14 @@ usage() {
39 echo " -d, --debug Enable 'xtrace' and keep scratch files" >&2
40 echo " in <CACHEDIR>/tmp" >&2
41 echo " (can be specified multiple times)" >&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 }
48
49-options="$(getopt -o ha:r:s:c:v:j:t:n:o:d -l "help,archversion:,sourcerpm:,sourcedir:,config:,vmlinux:,jobs:,target:,name:,output:,debug,skip-gcc-check,skip-cleanup" -- "$@")" || die "getopt failed"
50+options="$(getopt -o ha:r:s:c:v:j:t:n:o:d -l "help,archversion:,sourcerpm:,sourcedir:,config:,vmlinux:,jobs:,target:,name:,output:,debug,cross-compile:,skip-gcc-check,skip-cleanup" -- "$@")" || die "getopt failed"
51
52 eval set -- "$options"
53
54@@ -444,6 +446,10 @@ while [[ $# -gt 0 ]]; do
55 echo "DEBUG mode enabled"
56 fi
57 ;;
58+ --cross-compile)
59+ KPATCH_CROSS_COMPILE="$2"
60+ shift
61+ ;;
62 --skip-cleanup)
63 echo "Skipping cleanup"
64 SKIPCLEANUP=1
65@@ -691,6 +697,8 @@ if [[ $DEBUG -ge 4 ]]; then
66 export KPATCH_GCC_DEBUG=1
67 fi
68
69+export KPATCH_CROSS_COMPILE
70+
71 echo "Building original kernel"
72 ./scripts/setlocalversion --save-scmversion || die
73 make mrproper 2>&1 | logger || die
74@@ -840,6 +848,7 @@ cd "$TEMPDIR/patch" || die
75 KPATCH_BUILD="$SRCDIR" KPATCH_NAME="$MODNAME" \
76 KBUILD_EXTRA_SYMBOLS="$KBUILD_EXTRA_SYMBOLS" \
77 KPATCH_LDFLAGS="$KPATCH_LDFLAGS" \
78+CROSS_COMPILE="$KPATCH_CROSS_COMPILE" \
79 make 2>&1 | logger || die
80
81 if ! "$KPATCH_MODULE"; then
82diff --git a/kpatch-build/kpatch-gcc b/kpatch-build/kpatch-gcc
83index 6ba133c..3937948 100755
84--- a/kpatch-build/kpatch-gcc
85+++ b/kpatch-build/kpatch-gcc
86@@ -8,7 +8,7 @@ TOOLCHAINCMD="$1"
87 shift
88
89 if [[ -z "$KPATCH_GCC_TEMPDIR" ]]; then
90- exec "$TOOLCHAINCMD" "$@"
91+ exec ${KPATCH_CROSS_COMPILE}${TOOLCHAINCMD} "$@"
92 fi
93
94 declare -a args=("$@")
95@@ -80,4 +80,4 @@ elif [[ "$TOOLCHAINCMD" = "ld" ]] ; then
96 done
97 fi
98
99-exec "$TOOLCHAINCMD" "${args[@]}"
100+exec ${KPATCH_CROSS_COMPILE}${TOOLCHAINCMD} "${args[@]}"
101--
1021.9.1
103