Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 1 | From 70de3fecbc551907c4fd504cfff385c73be8db75 Mon Sep 17 00:00:00 2001 |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 2 | From: Ruslan Bilovol <rbilovol@cisco.com> |
| 3 | Date: Tue, 19 Dec 2017 15:59:04 +0200 |
| 4 | Subject: [PATCH] kpatch-build: add cross-compilation support |
| 5 | |
| 6 | This patch introduces new option for kpatch-build |
| 7 | script "--cross-compile" which can be used for |
| 8 | specifying cross-complier prefix. |
| 9 | It allows to build live patches not only on |
| 10 | target system, but also on hosts for a target other |
| 11 | than the one on which the compiler is running |
| 12 | |
| 13 | Also removed quotes in exec lines, so it is |
| 14 | possible to pass multy-component strings like |
| 15 | "ccache x86_64-xelinux-linux-" as cross-compiler |
| 16 | |
| 17 | Upstream-Status: Pending |
| 18 | |
| 19 | Signed-off-by: Ruslan Bilovol <rbilovol@cisco.com> |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 20 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 21 | --- |
| 22 | kpatch-build/kpatch-build | 13 +++++++++++-- |
| 23 | kpatch-build/kpatch-gcc | 4 ++-- |
| 24 | 2 files changed, 13 insertions(+), 4 deletions(-) |
| 25 | |
| 26 | diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 27 | index a76913f..4a011aa 100755 |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 28 | --- a/kpatch-build/kpatch-build |
| 29 | +++ b/kpatch-build/kpatch-build |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 30 | @@ -197,7 +197,7 @@ gcc_version_check() { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 31 | # 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 Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 39 | @@ -392,12 +392,14 @@ usage() { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 40 | 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 Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 55 | @@ -455,6 +457,10 @@ while [[ $# -gt 0 ]]; do |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 56 | 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 Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 66 | @@ -710,6 +716,8 @@ if [[ $DEBUG -ge 4 ]]; then |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 67 | 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 Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 74 | unset KPATCH_GCC_TEMPDIR |
| 75 | @@ -874,6 +882,7 @@ cd "$TEMPDIR/patch" || die |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 76 | 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 |
| 83 | diff --git a/kpatch-build/kpatch-gcc b/kpatch-build/kpatch-gcc |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 84 | index 2d56da1..59a4255 100755 |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 85 | --- 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 Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 96 | @@ -82,4 +82,4 @@ elif [[ "$TOOLCHAINCMD" = "ld" ]] ; then |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 97 | done |
| 98 | fi |
| 99 | |
| 100 | -exec "$TOOLCHAINCMD" "${args[@]}" |
| 101 | +exec ${KPATCH_CROSS_COMPILE}${TOOLCHAINCMD} "${args[@]}" |