mirror of
https://github.com/dynup/kpatch
synced 2024-12-15 01:44:32 +00:00
build objects in separate directory to fix caching
Setting KCFLAGS="-ffunction-sections -fdata-sections" causes make to invalidate all the kernel objects, resulting in all the objects getting rebuilt on the next pass, thus no build caching. To fix that, build the objects in a separate directory (obj) for normal builds, and another separate directory (obj2) for the builds with added cflags.
This commit is contained in:
parent
4f64ad6c2a
commit
5352d8b01a
@ -26,8 +26,10 @@ DISTROVERSION="${ARCHVERSION%*.*}"
|
|||||||
CPUS="$(grep -c ^processor /proc/cpuinfo)"
|
CPUS="$(grep -c ^processor /proc/cpuinfo)"
|
||||||
LOCALVERSION="$(uname -r)"
|
LOCALVERSION="$(uname -r)"
|
||||||
LOCALVERSION="-${LOCALVERSION##*-}"
|
LOCALVERSION="-${LOCALVERSION##*-}"
|
||||||
KSRCDIR="$HOME/.kpatch/$ARCHVERSION"
|
CACHEDIR="$HOME/.kpatch"
|
||||||
KSRCDIR_DIR="$(dirname $KSRCDIR)"
|
SRCDIR="$CACHEDIR/$ARCHVERSION/src"
|
||||||
|
OBJDIR="$CACHEDIR/$ARCHVERSION/obj"
|
||||||
|
OBJDIR2="$CACHEDIR/$ARCHVERSION/obj2"
|
||||||
TEMPDIR=
|
TEMPDIR=
|
||||||
STRIPCMD="strip -d --keep-file-symbols"
|
STRIPCMD="strip -d --keep-file-symbols"
|
||||||
APPLIEDPATCHFILE="applied-patch"
|
APPLIEDPATCHFILE="applied-patch"
|
||||||
@ -73,14 +75,13 @@ TEMPDIR="$(mktemp -d)" || die "mktemp failed"
|
|||||||
|
|
||||||
trap "rm -rf $TEMPDIR" EXIT INT TERM
|
trap "rm -rf $TEMPDIR" EXIT INT TERM
|
||||||
|
|
||||||
if [[ -d "$KSRCDIR" ]]; then
|
if [[ -d "$SRCDIR" ]]; then
|
||||||
echo "Using cache at $KSRCDIR"
|
echo "Using cache at $SRCDIR"
|
||||||
cd "$KSRCDIR" || die
|
cd "$SRCDIR" || die
|
||||||
if [[ -f "$APPLIEDPATCHFILE" ]]; then
|
if [[ -f "$APPLIEDPATCHFILE" ]]; then
|
||||||
patch -R -p1 < "$APPLIEDPATCHFILE" || die "the kpatch cache is corrupted. \"rm -rf $KSRCDIR\" and try again"
|
patch -R -p1 < "$APPLIEDPATCHFILE" >> "$LOGFILE" 2>&1 || die "the kpatch cache is corrupted. \"rm -rf $CACHEDIR\" and try again"
|
||||||
rm -f "$APPLIEDPATCHFILE"
|
rm -f "$APPLIEDPATCHFILE"
|
||||||
fi
|
fi
|
||||||
make "-j$CPUS" vmlinux >> "$LOGFILE" 2>&1 || die
|
|
||||||
else
|
else
|
||||||
rpm -q --quiet rpmdevtools || die "rpmdevtools not installed"
|
rpm -q --quiet rpmdevtools || die "rpmdevtools not installed"
|
||||||
rpm -q --quiet yum-utils || die "yum-utils not installed"
|
rpm -q --quiet yum-utils || die "yum-utils not installed"
|
||||||
@ -93,25 +94,28 @@ else
|
|||||||
rpm -ivh "$TEMPDIR/kernel-$DISTROVERSION.src.rpm" >> "$LOGFILE" 2>&1 || die
|
rpm -ivh "$TEMPDIR/kernel-$DISTROVERSION.src.rpm" >> "$LOGFILE" 2>&1 || die
|
||||||
rpmbuild -bp "--target=$(uname -m)" "$HOME/rpmbuild/SPECS/kernel.spec" >> "$LOGFILE" 2>&1 ||
|
rpmbuild -bp "--target=$(uname -m)" "$HOME/rpmbuild/SPECS/kernel.spec" >> "$LOGFILE" 2>&1 ||
|
||||||
die "rpmbuild -bp failed. you may need to run 'yum-builddep kernel' first."
|
die "rpmbuild -bp failed. you may need to run 'yum-builddep kernel' first."
|
||||||
rm -rf "$KSRCDIR_DIR"
|
rm -rf "$CACHEDIR"
|
||||||
mkdir -p "$KSRCDIR_DIR"
|
mkdir -p "$OBJDIR"
|
||||||
mv "$HOME"/rpmbuild/BUILD/kernel-*/linux-"$ARCHVERSION" "$KSRCDIR" >> "$LOGFILE" 2>&1 || die
|
mv "$HOME"/rpmbuild/BUILD/kernel-*/linux-"$ARCHVERSION" "$SRCDIR" >> "$LOGFILE" 2>&1 || die
|
||||||
|
|
||||||
echo "Building original kernel"
|
cd "$SRCDIR"
|
||||||
cd "$KSRCDIR"
|
cp .config "$OBJDIR" || die
|
||||||
echo "$LOCALVERSION" > localversion || die
|
echo "$LOCALVERSION" > "$OBJDIR/localversion" || die
|
||||||
make "-j$CPUS" vmlinux >> "$LOGFILE" 2>&1 || die
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "Building original kernel"
|
||||||
|
make mrproper >> "$LOGFILE" 2>&1 || die
|
||||||
|
make "-j$CPUS" vmlinux "O=$OBJDIR" >> "$LOGFILE" 2>&1 || die
|
||||||
|
|
||||||
find_data_dir || (echo "can't find data dir" >&2 && die)
|
find_data_dir || (echo "can't find data dir" >&2 && die)
|
||||||
|
|
||||||
cp -LR "$DATADIR/patch" "$TEMPDIR" || die
|
cp -LR "$DATADIR/patch" "$TEMPDIR" || die
|
||||||
cp vmlinux "$TEMPDIR" || die
|
cp "$OBJDIR/vmlinux" "$TEMPDIR" || die
|
||||||
|
|
||||||
echo "Building patched kernel"
|
echo "Building patched kernel"
|
||||||
cp "$PATCHFILE" "$APPLIEDPATCHFILE" || die
|
cp "$PATCHFILE" "$APPLIEDPATCHFILE" || die
|
||||||
patch -p1 < "$APPLIEDPATCHFILE" >> "$LOGFILE" 2>&1 || die
|
patch -p1 < "$APPLIEDPATCHFILE" >> "$LOGFILE" 2>&1 || die
|
||||||
make "-j$CPUS" vmlinux > "$TEMPDIR/patched_build.log" 2>&1 || die
|
make "-j$CPUS" vmlinux "O=$OBJDIR" > "$TEMPDIR/patched_build.log" 2>&1 || die
|
||||||
|
|
||||||
echo "Detecting changed objects"
|
echo "Detecting changed objects"
|
||||||
grep CC "$TEMPDIR/patched_build.log" | grep -v init/version.o | awk '{print $2}' >> "$TEMPDIR/changed_objs"
|
grep CC "$TEMPDIR/patched_build.log" | grep -v init/version.o | awk '{print $2}' >> "$TEMPDIR/changed_objs"
|
||||||
@ -121,13 +125,15 @@ if [[ $? -ne 0 ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Rebuilding changed objects"
|
echo "Rebuilding changed objects"
|
||||||
|
rm -rf "$OBJDIR2"
|
||||||
|
mkdir -p "$OBJDIR2"
|
||||||
|
cp "$OBJDIR/.config" "$OBJDIR2" || die
|
||||||
mkdir "$TEMPDIR/patched"
|
mkdir "$TEMPDIR/patched"
|
||||||
for i in $(cat $TEMPDIR/changed_objs); do
|
for i in $(cat $TEMPDIR/changed_objs); do
|
||||||
rm -f "$i"
|
KCFLAGS="-ffunction-sections -fdata-sections" make "$i" "O=$OBJDIR2" >> "$LOGFILE" 2>&1 || die
|
||||||
KCFLAGS="-ffunction-sections -fdata-sections" make "$i" >> "$LOGFILE" 2>&1 || die
|
$STRIPCMD "$OBJDIR2/$i" >> "$LOGFILE" 2>&1 || die
|
||||||
$STRIPCMD "$i" >> "$LOGFILE" 2>&1 || die
|
|
||||||
mkdir -p "$TEMPDIR/patched/$(dirname $i)"
|
mkdir -p "$TEMPDIR/patched/$(dirname $i)"
|
||||||
cp -f "$i" "$TEMPDIR/patched/$i" || die
|
cp -f "$OBJDIR2/$i" "$TEMPDIR/patched/$i" || die
|
||||||
|
|
||||||
done
|
done
|
||||||
patch -R -p1 < "$APPLIEDPATCHFILE" >> "$LOGFILE" 2>&1
|
patch -R -p1 < "$APPLIEDPATCHFILE" >> "$LOGFILE" 2>&1
|
||||||
@ -135,10 +141,10 @@ rm -f "$APPLIEDPATCHFILE"
|
|||||||
mkdir "$TEMPDIR/orig"
|
mkdir "$TEMPDIR/orig"
|
||||||
for i in $(cat $TEMPDIR/changed_objs); do
|
for i in $(cat $TEMPDIR/changed_objs); do
|
||||||
rm -f "$i"
|
rm -f "$i"
|
||||||
KCFLAGS="-ffunction-sections -fdata-sections" make "$i" >> "$LOGFILE" 2>&1 || die
|
KCFLAGS="-ffunction-sections -fdata-sections" make "$i" "O=$OBJDIR2" >> "$LOGFILE" 2>&1 || die
|
||||||
$STRIPCMD -d "$i" >> "$LOGFILE" 2>&1 || die
|
$STRIPCMD -d "$OBJDIR2/$i" >> "$LOGFILE" 2>&1 || die
|
||||||
mkdir -p "$TEMPDIR/orig/$(dirname $i)"
|
mkdir -p "$TEMPDIR/orig/$(dirname $i)"
|
||||||
cp -f "$i" "$TEMPDIR/orig/$i" || die
|
cp -f "$OBJDIR2/$i" "$TEMPDIR/orig/$i" || die
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Extracting new and modified ELF sections"
|
echo "Extracting new and modified ELF sections"
|
||||||
@ -152,11 +158,14 @@ for i in $FILES; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
echo "Building patch module: kpatch-$PATCHNAME.ko"
|
echo "Building patch module: kpatch-$PATCHNAME.ko"
|
||||||
|
cp "$OBJDIR/.config" "$SRCDIR"
|
||||||
|
cd "$SRCDIR"
|
||||||
|
make prepare >> "$LOGFILE" 2>&1 || die
|
||||||
cd "$TEMPDIR/output"
|
cd "$TEMPDIR/output"
|
||||||
ld -r -o ../patch/output.o $FILES >> "$LOGFILE" 2>&1 || die
|
ld -r -o ../patch/output.o $FILES >> "$LOGFILE" 2>&1 || die
|
||||||
cd "$TEMPDIR/patch"
|
cd "$TEMPDIR/patch"
|
||||||
"$TOOLSDIR"/add-patches-section output.o ../vmlinux >> "$LOGFILE" 2>&1 || die
|
"$TOOLSDIR"/add-patches-section output.o ../vmlinux >> "$LOGFILE" 2>&1 || die
|
||||||
KPATCH_BUILD="$KSRCDIR" KPATCH_NAME="$PATCHNAME" make >> "$LOGFILE" 2>&1 || die
|
KPATCH_BUILD="$SRCDIR" KPATCH_NAME="$PATCHNAME" make "O=$OBJDIR" >> "$LOGFILE" 2>&1 || die
|
||||||
$STRIPCMD "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
|
"$TOOLSDIR"/link-vmlinux-syms "kpatch-$PATCHNAME.ko" ../vmlinux >> "$LOGFILE" 2>&1 || die
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user