kpatch/kpatch-build/kpatch-gcc
Martin Carroll 145d1289dc kpatch-build: do not assume that TEMPDIR is unexported on entry to script
The user's environment might have TEMPDIR exported.  If so, then kpatch-build
dies with a bogus "invalid ancestor" error. If you turn those bogus errors into
warnings, then the script goes on to incorrectly put into the generated .ko file
every single function that was compiled in the *original* kernel build, thereby
producing an immense .ko file with more than 64k sections that the linux kernel
cannot load.  This fix makes sure that TEMPDIR is unexported on the build of the
original kernel.  Actually, this fix uses a separate KPATCH_GCC_TEMPDIR variable,
so that if the kernel build is interrupted, the cleanup function in the kpatch-kbuild
script will still have TEMPDIR set correctly.

Signed-off-by: Martin Carroll <martin.carroll@alcatel-lucent.com>
2016-07-25 11:02:37 -04:00

71 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
set -x
TOOLCHAINCMD="$1"
shift
if [[ -z "$KPATCH_GCC_TEMPDIR" ]]; then
exec "$TOOLCHAINCMD" "$@"
fi
declare -a args=("$@")
if [[ "$TOOLCHAINCMD" = "gcc" ]] ; then
while [ "$#" -gt 0 ]; do
if [ "$1" = "-o" ]; then
obj=$2
[[ $2 = */.tmp_*.o ]] && obj=${2/.tmp_/}
case "$obj" in
*.mod.o|\
*built-in.o|\
vmlinux.o|\
.tmp_kallsyms1.o|\
.tmp_kallsyms2.o|\
init/version.o|\
arch/x86/boot/version.o|\
arch/x86/boot/compressed/eboot.o|\
arch/x86/boot/header.o|\
arch/x86/boot/compressed/efi_stub_64.o|\
arch/x86/boot/compressed/piggy.o|\
kernel/system_certificates.o|\
arch/x86/vdso/*|\
arch/x86/entry/vdso/*|\
drivers/firmware/efi/libstub/*|\
.*.o)
break
;;
*.o)
mkdir -p "$KPATCH_GCC_TEMPDIR/orig/$(dirname $obj)"
[[ -e $obj ]] && cp -f "$obj" "$KPATCH_GCC_TEMPDIR/orig/$obj"
echo "$obj" >> "$KPATCH_GCC_TEMPDIR/changed_objs"
break
;;
*)
break
;;
esac
fi
shift
done
elif [[ "$TOOLCHAINCMD" = "ld" ]] ; then
while [ "$#" -gt 0 ]; do
if [ "$1" = "-o" ]; then
obj=$2
case "$obj" in
*.ko)
mkdir -p "$KPATCH_GCC_TEMPDIR/module/$(dirname $obj)"
cp -f "$obj" "$KPATCH_GCC_TEMPDIR/module/$obj"
break
;;
*)
break
;;
esac
fi
shift
done
fi
exec "$TOOLCHAINCMD" "${args[@]}"