blob: ab3b1276410592b1f832175e7e00b4470286f2f3 [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001From 70de3fecbc551907c4fd504cfff385c73be8db75 Mon Sep 17 00:00:00 2001
Brad Bishop316dfdd2018-06-25 12:45:53 -04002From: 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>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080020
Brad Bishop316dfdd2018-06-25 12:45:53 -040021---
22 kpatch-build/kpatch-build | 13 +++++++++++--
23 kpatch-build/kpatch-gcc | 4 ++--
24 2 files changed, 13 insertions(+), 4 deletions(-)
25
26diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080027index a76913f..4a011aa 100755
Brad Bishop316dfdd2018-06-25 12:45:53 -040028--- a/kpatch-build/kpatch-build
29+++ b/kpatch-build/kpatch-build
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080030@@ -197,7 +197,7 @@ gcc_version_check() {
Brad Bishop316dfdd2018-06-25 12:45:53 -040031 # gcc --version varies between distributions therefore extract version
32 # by compiling a test file and compare it to vmlinux's version.
33 echo 'void main(void) {}' > "$c"
34- out="$(gcc -c -pg -ffunction-sections -o "$o" "$c" 2>&1)"
35+ out="$(${KPATCH_CROSS_COMPILE}gcc -c -pg -ffunction-sections -o "$o" "$c" 2>&1)"
36 gccver="$(gcc_version_from_file "$o")"
37 kgccver="$(gcc_version_from_file "$VMLINUX")"
38 rm -f "$c" "$o"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080039@@ -392,12 +392,14 @@ usage() {
Brad Bishop316dfdd2018-06-25 12:45:53 -040040 echo " -d, --debug Enable 'xtrace' and keep scratch files" >&2
41 echo " in <CACHEDIR>/tmp" >&2
42 echo " (can be specified multiple times)" >&2
43+ echo " --cross-compile Specify the prefix used for all executables" >&2
44+ echo " used during compilation" >&2
45 echo " --skip-cleanup Skip post-build cleanup" >&2
46 echo " --skip-gcc-check Skip gcc version matching check" >&2
47 echo " (not recommended)" >&2
48 }
49
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,skip-gcc-check,skip-cleanup" -- "$@")" || die "getopt failed"
51+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"
52
53 eval set -- "$options"
54
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080055@@ -455,6 +457,10 @@ while [[ $# -gt 0 ]]; do
Brad Bishop316dfdd2018-06-25 12:45:53 -040056 echo "DEBUG mode enabled"
57 fi
58 ;;
59+ --cross-compile)
60+ KPATCH_CROSS_COMPILE="$2"
61+ shift
62+ ;;
63 --skip-cleanup)
64 echo "Skipping cleanup"
65 SKIPCLEANUP=1
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080066@@ -710,6 +716,8 @@ if [[ $DEBUG -ge 4 ]]; then
Brad Bishop316dfdd2018-06-25 12:45:53 -040067 export KPATCH_GCC_DEBUG=1
68 fi
69
70+export KPATCH_CROSS_COMPILE
71+
72 echo "Building original kernel"
73 ./scripts/setlocalversion --save-scmversion || die
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080074 unset KPATCH_GCC_TEMPDIR
75@@ -874,6 +882,7 @@ cd "$TEMPDIR/patch" || die
Brad Bishop316dfdd2018-06-25 12:45:53 -040076 KPATCH_BUILD="$SRCDIR" KPATCH_NAME="$MODNAME" \
77 KBUILD_EXTRA_SYMBOLS="$KBUILD_EXTRA_SYMBOLS" \
78 KPATCH_LDFLAGS="$KPATCH_LDFLAGS" \
79+CROSS_COMPILE="$KPATCH_CROSS_COMPILE" \
80 make 2>&1 | logger || die
81
82 if ! "$KPATCH_MODULE"; then
83diff --git a/kpatch-build/kpatch-gcc b/kpatch-build/kpatch-gcc
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080084index 2d56da1..59a4255 100755
Brad Bishop316dfdd2018-06-25 12:45:53 -040085--- a/kpatch-build/kpatch-gcc
86+++ b/kpatch-build/kpatch-gcc
87@@ -8,7 +8,7 @@ TOOLCHAINCMD="$1"
88 shift
89
90 if [[ -z "$KPATCH_GCC_TEMPDIR" ]]; then
91- exec "$TOOLCHAINCMD" "$@"
92+ exec ${KPATCH_CROSS_COMPILE}${TOOLCHAINCMD} "$@"
93 fi
94
95 declare -a args=("$@")
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080096@@ -82,4 +82,4 @@ elif [[ "$TOOLCHAINCMD" = "ld" ]] ; then
Brad Bishop316dfdd2018-06-25 12:45:53 -040097 done
98 fi
99
100-exec "$TOOLCHAINCMD" "${args[@]}"
101+exec ${KPATCH_CROSS_COMPILE}${TOOLCHAINCMD} "${args[@]}"