kpatch-build: make gcc version check distribution independent

gcc --version varies too much for sane comparisons with vmlinux's
.comment section. Therefore compile a test file and compare its .comment
section.

Also fix gcc 4.8 check which used a lexicographically comparison which
will break for gcc versions >= 10. Instead check for the required
compiler options.

Closes #565.
This commit is contained in:
Simon Ruderich 2017-10-12 17:17:56 +02:00
parent fa6a6dd821
commit 0b8a53163d

View File

@ -167,10 +167,28 @@ find_core_symvers() {
[[ -e "$SYMVERSFILE" ]]
}
gcc_version_from_file() {
readelf -p .comment "$1" | grep -o 'GCC:.*'
}
gcc_version_check() {
local c="$TEMPDIR/test.c" o="$TEMPDIR/test.o"
local out gccver kgccver
# gcc --version varies between distributions therefore extract version
# by compiling a test file and compare it to vmlinux's version.
echo 'void main(void) {}' > "$c"
out="$(gcc -c -pg -ffunction-sections -o "$o" "$c" 2>&1)"
gccver="$(gcc_version_from_file "$o")"
kgccver="$(gcc_version_from_file "$VMLINUX")"
rm -f "$c" "$o"
if [[ -n "$out" ]]; then
warn "gcc >= 4.8 required for -pg -ffunction-settings"
echo "gcc output: $out"
return 1
fi
# ensure gcc version matches that used to build the kernel
local gccver="$(gcc --version |head -n1 |cut -d' ' -f3-)"
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"
@ -180,23 +198,6 @@ gcc_version_check() {
return 1
fi
# On ppc64le, livepatch needs the GCC -mprofile-kernel flag. A script
# is run during the kernel build to ensure the flag is present:
#
# <linux>/arch/powerpc/tools/gcc-check-mprofile-kernel.sh
#
# Postpone the check to the kernel build instead of duplicating it here.
if [[ "$ARCH" = "ppc64le" ]]; then
return
else
# ensure gcc version is >= 4.8
gccver="$(echo "$gccver" |cut -d'.' -f1,2)"
if [[ "$gccver" < 4.8 ]]; then
warn "gcc >= 4.8 required"
return 1
fi
fi
return
}