From 4f2d5d209c41d2951918e1196c4ca52dff4ead53 Mon Sep 17 00:00:00 2001 From: Seth Jennings Date: Mon, 17 Feb 2014 14:55:57 -0600 Subject: [PATCH 1/2] variablize strip command and add --keep-file-symbols We need to keep the file symbols around for add-patches-section and link-vmlinux-syms to resolve ambigous symbols in vmlinux. Signed-off-by: Seth Jennings --- kpatch-build/kpatch-build | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build index 0ba88d9..9761478 100755 --- a/kpatch-build/kpatch-build +++ b/kpatch-build/kpatch-build @@ -30,6 +30,7 @@ KSRCDIR="$HOME/.kpatch/$ARCHVERSION" KSRCDIR_DIR="$(dirname $KSRCDIR)" KSRCDIR_CACHE="$KSRCDIR.tgz" TEMPDIR= +STRIPCMD="strip -d --keep-file-symbols" cleanup() { rm -Rf "$KSRCDIR" "$LOGFILE" "$TEMPDIR" > /dev/null 2>/dev/null @@ -127,7 +128,7 @@ mkdir "$TEMPDIR/patched" for i in "$(cat $TEMPDIR/changed_objs)"; do rm -f "$i" KCFLAGS="-ffunction-sections -fdata-sections" make "$i" >> "$LOGFILE" 2>&1 || die - strip -d "$i" >> "$LOGFILE" 2>&1 || die + "$STRIPCMD" "$i" >> "$LOGFILE" 2>&1 || die cp -f "$i" "$TEMPDIR/patched/" || die done @@ -136,7 +137,7 @@ mkdir "$TEMPDIR/orig" for i in "$(cat $TEMPDIR/changed_objs)"; do rm -f "$i" KCFLAGS="-ffunction-sections -fdata-sections" make "$i" >> "$LOGFILE" 2>&1 || die - strip -d "$i" >> "$LOGFILE" 2>&1 || die + "$STRIPCMD" -d "$i" >> "$LOGFILE" 2>&1 || die cp -f "$i" "$TEMPDIR/orig/" || die done @@ -158,7 +159,7 @@ cd patch ld -r -o output.o ../output/* >> "$LOGFILE" 2>&1 || die "$TOOLSDIR"/add-patches-section output.o ../vmlinux >> "$LOGFILE" 2>&1 || die KPATCH_BASEDIR="$TEMPDIR/core" KPATCH_BUILD="$KSRCDIR" KPATCH_NAME="$PATCHNAME" make >> "$LOGFILE" 2>&1 || die -strip -d "kpatch-$PATCHNAME.ko" >> "$LOGFILE" 2>&1 || die +"$STRIPCMD" "kpatch-$PATCHNAME.ko" >> "$LOGFILE" 2>&1 || die "$TOOLSDIR"/link-vmlinux-syms "kpatch-$PATCHNAME.ko" ../vmlinux >> "$LOGFILE" 2>&1 || die cp -f "$TEMPDIR/patch/kpatch-$PATCHNAME.ko" "$TEMPDIR/core/kpatch.ko" "$BASE" || die From 062355a186e4a0f81d27f6fdac3562b9edaf0d1e Mon Sep 17 00:00:00 2001 From: Seth Jennings Date: Mon, 17 Feb 2014 15:22:01 -0600 Subject: [PATCH 2/2] retain source tree directory structure with objects The source tree directory structure should be maintained in the TEMPDIR while building the hotpatch module so that changed objects in different directories with the same name don't collide during the build process. Signed-off-by: Seth Jennings --- kpatch-build/kpatch-build | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build index 9761478..976b102 100755 --- a/kpatch-build/kpatch-build +++ b/kpatch-build/kpatch-build @@ -129,7 +129,8 @@ for i in "$(cat $TEMPDIR/changed_objs)"; do rm -f "$i" KCFLAGS="-ffunction-sections -fdata-sections" make "$i" >> "$LOGFILE" 2>&1 || die "$STRIPCMD" "$i" >> "$LOGFILE" 2>&1 || die - cp -f "$i" "$TEMPDIR/patched/" || die + mkdir -p "$TEMPDIR/patched/$(dirname $i)" + cp -f "$i" "$TEMPDIR/patched/$i" || die done patch -R -p1 < "$PATCHFILE" >> "$LOGFILE" 2>&1 @@ -138,15 +139,18 @@ for i in "$(cat $TEMPDIR/changed_objs)"; do rm -f "$i" KCFLAGS="-ffunction-sections -fdata-sections" make "$i" >> "$LOGFILE" 2>&1 || die "$STRIPCMD" -d "$i" >> "$LOGFILE" 2>&1 || die - cp -f "$i" "$TEMPDIR/orig/" || die + mkdir -p "$TEMPDIR/orig/$(dirname $i)" + cp -f "$i" "$TEMPDIR/orig/$i" || die done echo "Extracting new and modified ELF sections" +cd "$TEMPDIR/orig" +FILES="$(find * -type f)" cd "$TEMPDIR" mkdir output -for i in orig/*; do - FILE="$(basename $i)" - "$TOOLSDIR"/create-diff-object "orig/$FILE" "patched/$FILE" "output/$FILE" >> "$LOGFILE" 2>&1 || die +for i in $FILES; do + mkdir -p "output/$(dirname $i)" + "$TOOLSDIR"/create-diff-object "orig/$i" "patched/$i" "output/$i" >> "$LOGFILE" 2>&1 || die done echo "Building core module: kpatch.ko" @@ -155,8 +159,9 @@ KPATCH_BUILD="$KSRCDIR" make >> "$LOGFILE" 2>&1 || die cd .. echo "Building patch module: kpatch-$PATCHNAME.ko" -cd patch -ld -r -o output.o ../output/* >> "$LOGFILE" 2>&1 || die +cd "$TEMPDIR/output" +ld -r -o ../patch/output.o $FILES >> "$LOGFILE" 2>&1 || die +cd "$TEMPDIR/patch" "$TOOLSDIR"/add-patches-section output.o ../vmlinux >> "$LOGFILE" 2>&1 || die KPATCH_BASEDIR="$TEMPDIR/core" KPATCH_BUILD="$KSRCDIR" KPATCH_NAME="$PATCHNAME" make >> "$LOGFILE" 2>&1 || die "$STRIPCMD" "kpatch-$PATCHNAME.ko" >> "$LOGFILE" 2>&1 || die