From 1330b4a3e5e96b5ee63866ae4bb8479026f345bd Mon Sep 17 00:00:00 2001 From: Josh Poimboeuf Date: Mon, 5 Dec 2016 20:12:49 -0600 Subject: [PATCH] kpatch-build: fix 'undefined reference to kpatch_shadow_*' errors 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. --- kpatch-build/kpatch-build | 3 --- kpatch-build/kpatch-gcc | 4 ++++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build index ac9c904..34debd0 100755 --- a/kpatch-build/kpatch-build +++ b/kpatch-build/kpatch-build @@ -513,10 +513,7 @@ patch -N -p1 < "$APPLIEDPATCHFILE" >> "$LOGFILE" 2>&1 || die mkdir -p "$TEMPDIR/orig" "$TEMPDIR/patched" KPATCH_GCC_TEMPDIR=$TEMPDIR export KPATCH_GCC_TEMPDIR -# TODO: remove custom LDFLAGS and ugly "undefined reference" grep when core -# module gets moved to the kernel tree CROSS_COMPILE="$TOOLSDIR/kpatch-gcc " \ - LDFLAGS_vmlinux="--warn-unresolved-symbols" \ KBUILD_MODPOST_WARN=1 \ make "-j$CPUS" $TARGETS "O=$OBJDIR" >> "$LOGFILE" 2>&1 || die [[ "${PIPESTATUS[0]}" -eq 0 ]] || die diff --git a/kpatch-build/kpatch-gcc b/kpatch-build/kpatch-gcc index ab01040..f6db069 100755 --- a/kpatch-build/kpatch-gcc +++ b/kpatch-build/kpatch-gcc @@ -58,6 +58,10 @@ elif [[ "$TOOLCHAINCMD" = "ld" ]] ; then cp -f "$obj" "$KPATCH_GCC_TEMPDIR/module/$obj" break ;; + .tmp_vmlinux*|vmlinux) + args+=(--warn-unresolved-symbols) + break + ;; *) break ;;