mirror of
https://github.com/dynup/kpatch
synced 2025-01-21 12:22:47 +00:00
1330b4a3e5
When building the patched version of the kernel, vmlinux has to be linked with the '--warn-unresolved-symbols' linker flag. Otherwise the link will fail if the patch uses kpatch-specific symbols like kpatch_shadow_alloc() and friends. As of upstream Linux commit b36fad65d61f ("kbuild: Initialize exported variables"), LDFLAGS_vmlinux= no longer works from the command line, resulting in '--warn-unresolved-symbols' no longer getting set. Instead we can use kpatch-gcc to pass the flag to the linker. Fixes #627.
75 lines
1.4 KiB
Bash
Executable File
75 lines
1.4 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
|
|
;;
|
|
.tmp_vmlinux*|vmlinux)
|
|
args+=(--warn-unresolved-symbols)
|
|
break
|
|
;;
|
|
*)
|
|
break
|
|
;;
|
|
esac
|
|
fi
|
|
shift
|
|
done
|
|
fi
|
|
|
|
exec "$TOOLCHAINCMD" "${args[@]}"
|