Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame^] | 1 | From 21909e3f9096fa8e4825df8c65114ee92ab3d532 Mon Sep 17 00:00:00 2001 |
| 2 | From: Zang Ruochen <zangrc.fnst@cn.fujitsu.com> |
| 3 | Date: Wed, 7 Aug 2019 02:57:35 +0900 |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 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> |
| 20 | --- |
| 21 | kpatch-build/kpatch-build | 13 +++++++++++-- |
| 22 | kpatch-build/kpatch-gcc | 4 ++-- |
| 23 | 2 files changed, 13 insertions(+), 4 deletions(-) |
| 24 | |
| 25 | diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame^] | 26 | index 9ef3809..463dab1 100755 |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 27 | --- a/kpatch-build/kpatch-build |
| 28 | +++ b/kpatch-build/kpatch-build |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame^] | 29 | @@ -198,7 +198,7 @@ gcc_version_check() { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 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")" |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame^] | 36 | if [[ -n "$OOT_MODULE" ]]; then |
| 37 | kgccver="$(gcc_version_from_file "$OOT_MODULE")" |
| 38 | @@ -411,6 +411,8 @@ usage() { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 39 | echo " (can be specified multiple times)" >&2 |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame^] | 40 | echo " -e, --oot-module Enable patching out-of-tree module," >&2 |
| 41 | echo " specify current version of module" >&2 |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 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 |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame^] | 45 | echo " --skip-gcc-check Skip gcc version matching check" >&2 |
| 46 | echo " (not recommended)" >&2 |
| 47 | @@ -416,7 +418,7 @@ usage() { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 48 | echo " (not recommended)" >&2 |
| 49 | } |
| 50 | |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame^] | 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" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 53 | |
| 54 | eval set -- "$options" |
| 55 | |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame^] | 56 | @@ -479,6 +481,10 @@ while [[ $# -gt 0 ]]; do |
| 57 | OOT_MODULE="$(readlink -f "$2")" |
| 58 | shift |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 59 | ;; |
| 60 | + --cross-compile) |
| 61 | + KPATCH_CROSS_COMPILE="$2" |
| 62 | + shift |
| 63 | + ;; |
| 64 | --skip-cleanup) |
| 65 | echo "Skipping cleanup" |
| 66 | SKIPCLEANUP=1 |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame^] | 67 | @@ -757,6 +763,8 @@ if [[ $DEBUG -ge 4 ]]; then |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 68 | export KPATCH_GCC_DEBUG=1 |
| 69 | fi |
| 70 | |
| 71 | +export KPATCH_CROSS_COMPILE |
| 72 | + |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame^] | 73 | echo "Building original source" |
| 74 | [[ -n "$OOT_MODULE" ]] || ./scripts/setlocalversion --save-scmversion || die |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 75 | unset KPATCH_GCC_TEMPDIR |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame^] | 76 | @@ -940,6 +948,7 @@ fi |
| 77 | KPATCH_BUILD="$KPATCH_BUILD" KPATCH_NAME="$MODNAME" \ |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 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 |
| 84 | diff --git a/kpatch-build/kpatch-gcc b/kpatch-build/kpatch-gcc |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame^] | 85 | index 9663290..56e6c8f 100755 |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 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=("$@") |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame^] | 97 | @@ -84,4 +84,4 @@ elif [[ "$TOOLCHAINCMD" = "ld" ]] ; then |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 98 | done |
| 99 | fi |
| 100 | |
| 101 | -exec "$TOOLCHAINCMD" "${args[@]}" |
| 102 | +exec ${KPATCH_CROSS_COMPILE}${TOOLCHAINCMD} "${args[@]}" |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame^] | 103 | -- |
| 104 | 2.7.4 |
| 105 | |