From d3abeb667aae0269f668758e048b13f913c6aa14 Mon Sep 17 00:00:00 2001 From: Seth Jennings Date: Wed, 1 Oct 2014 13:57:53 -0500 Subject: [PATCH] Allow user to skip gcc version check Right now, unless the entire gcc version string, including build date and package version, matches the distro kernel exactly, kpatch-build won't proceed. For some distros, it is very difficult to rollback to a previous version of gcc and keep that version pinned on the system so that the package manager doesn't update it. For these user, add a --skip-gcc-check flag to kpatch-build to allow the version check to be skipped. If the user does this, it is assumed they know what they are doing. This flag is documented as "not recommended". Signed-off-by: Seth Jennings --- kpatch-build/kpatch-build | 17 +++++++++++++++-- man/kpatch-build.1 | 9 +++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build index f0747cf..b560fbd 100755 --- a/kpatch-build/kpatch-build +++ b/kpatch-build/kpatch-build @@ -48,6 +48,7 @@ VERSIONFILE="$CACHEDIR/version" TEMPDIR= APPLIEDPATCHFILE="kpatch.patch" DEBUG=0 +SKIPGCCCHECK=0 warn() { echo "ERROR: $1" >&2 @@ -110,6 +111,10 @@ gcc_version_check() { local kgccver=$(readelf -p .comment $VMLINUX |grep GCC: | tr -s ' ' | cut -d ' ' -f6-) if [[ $gccver != $kgccver ]]; then warn "gcc/kernel version mismatch" + echo "gcc version: $gccver" + echo "kernel version: $kgccver" + echo "Install the matching gcc version (recommended) or use --skip-gcc-check" + echo "to skip the version matching enforcement (not recommended)" return 1 fi @@ -192,9 +197,11 @@ usage() { echo " -v, --vmlinux Specify original vmlinux" >&2 echo " -t, --target Specify custom kernel build targets" >&2 echo " -d, --debug Keep scratch files in /tmp" >&2 + echo " --skip-gcc-check Skip gcc version matching check" >&2 + echo " (not recommended)" >&2 } -options=$(getopt -o hr:s:c:v:t:d -l "help,sourcerpm:,sourcedir:,config:,vmlinux:,target:,debug" -- "$@") || die "getopt failed" +options=$(getopt -o hr:s:c:v:t:d -l "help,sourcerpm:,sourcedir:,config:,vmlinux:,target:,debug,skip-gcc-check" -- "$@") || die "getopt failed" eval set -- "$options" @@ -236,6 +243,10 @@ while [[ $# -gt 0 ]]; do DEBUG=1 set -o xtrace ;; + --skip-gcc-check) + echo "WARNING: Skipping gcc version matching check (not recommended)" + SKIPGCCCHECK=1 + ;; --) if [[ -z "$2" ]]; then warn "no patch file specified" @@ -309,7 +320,9 @@ elif [[ $DISTRO = ubuntu ]] || [[ $DISTRO = debian ]]; then export PATH=/usr/lib/ccache:$PATH fi -gcc_version_check || die +if [[ $SKIPGCCCHECK -eq 0 ]]; then + gcc_version_check || die +fi if [[ -n "$USERSRCDIR" ]]; then echo "Using source directory at $USERSRCDIR" diff --git a/man/kpatch-build.1 b/man/kpatch-build.1 index 03556c3..e9fb893 100644 --- a/man/kpatch-build.1 +++ b/man/kpatch-build.1 @@ -37,6 +37,15 @@ to work on other distros. -d|--debug Keep scratch files in /tmp +--skip-gcc-check + Skips check that ensures that the system gcc version and + the gcc version that built the kernel match. Skipping this + check is not recommended, but is useful if the exact gcc + version is not available or is not easily installed. Use + only when confident that the two versions of gcc output + identical objects for a given target. Otherwise, use of + this option might result in unexpected changed objects + being detected. .SH SEE ALSO kpatch(1)