代码拉取完成,页面将自动刷新
From 5f97ec32a8a98810811949ea9feeefe583a0fbd3 Mon Sep 17 00:00:00 2001
From: Zhipeng Xie <xiezhipeng1@huawei.com>
Date: Wed, 26 Feb 2020 06:44:06 -0500
Subject: [PATCH 08/38] kpatch-build: enhance for out of tree module
support set USERMODBUILDDIR to build patch for out
of tree module.
Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
---
kpatch-build/kpatch-build | 56 +++++++++++++++++++++++++++++++--------
kpatch-build/kpatch-cc | 4 ++-
2 files changed, 48 insertions(+), 12 deletions(-)
diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build
index 7f3bbce..8bd721b 100755
--- a/kpatch-build/kpatch-build
+++ b/kpatch-build/kpatch-build
@@ -571,6 +571,12 @@ find_parent_obj() {
[[ -n "$PARENT" ]] && return
fi
+ # try to find parent in OOT Module directory
+ if [[ -n "$USERMODBUILDDIR" ]]; then
+ find_parent_obj_in_dir "$file" "$USERMODBUILDDIR"
+ [[ -n "$PARENT" ]] && return
+ fi
+
# prevent known deep finds
if [[ $file = drivers/gpu/drm/amd/* ]]; then
find_parent_obj_in_dir "$file" "drivers/gpu/drm/amd/amdgpu"
@@ -789,6 +795,11 @@ if [[ -n "$SRCRPM" ]]; then
ARCHVERSION="${ARCHVERSION#alt-}"
fi
+if [[ -n "$USERMODBUILDDIR" ]]; then
+ OOT_MODULE="yes"
+ OOT_MODULE_SRCDIR=$USERMODBUILDDIR
+fi
+
if [[ -n "$OOT_MODULE" ]] && [[ -z "$OOT_MODULE_SRCDIR" ]]; then
warn "--oot-module requires --oot-module-src"
exit 1
@@ -819,7 +830,7 @@ if [[ -n "$USERSRCDIR" ]]; then
fi
fi
-if [[ -n "$OOT_MODULE" ]]; then
+if [[ -n "$OOT_MODULE" ]] && [[ "$OOT_MODULE" != "yes" ]]; then
ARCHVERSION="$(modinfo -F vermagic "$OOT_MODULE" | awk '{print $1}')"
fi
@@ -868,7 +879,7 @@ fi
[[ "$ARCHVERSION" =~ .el7a. ]] && ALT="-alt"
-[[ -z "$TARGETS" ]] && TARGETS="vmlinux modules"
+[[ -z "$TARGETS" ]] && [[ -z "$OOT_MODULE" ]] && TARGETS="vmlinux modules"
if [[ "$DISTRO" = fedora ]] || [[ "$DISTRO" = rhel ]] || [[ "$DISTRO" = ol ]] ||
[[ "$DISTRO" = centos ]] || [[ "$DISTRO" = openEuler ]] ||
@@ -1150,7 +1161,7 @@ if [[ -n "$CONFIG_CC_IS_CLANG" ]]; then
fi
if [[ "$SKIPCOMPILERCHECK" -eq 0 ]]; then
- if [[ -n "$OOT_MODULE" ]]; then
+ if [[ -n "$OOT_MODULE" ]] && [[ "$OOT_MODULE" != "yes" ]]; then
target="$OOT_MODULE"
else
target="$VMLINUX"
@@ -1211,10 +1222,16 @@ fi
# $TARGETS used as list, no quotes.
# shellcheck disable=SC2086
-make "${MAKEVARS[@]}" "-j$CPUS" $TARGETS 2>&1 | logger || die
+if [[ -z "$USERMODBUILDDIR" ]]; then
+ make "${MAKEVARS[@]}" "-j$CPUS" $TARGETS 2>&1 | logger || die
+else
+ make "${MAKEVARS[@]}" -C "$USERMODBUILDDIR" M="$USERMODBUILDDIR" $USERMODFLAGS "-j$CPUS" $TARGETS 2>&1 | logger || die
+fi
# Save original module symvers
-cp -f "$BUILDDIR/Module.symvers" "$TEMPDIR/Module.symvers" || die
+if [[ "$OOT_MODULE" != "yes" ]]; then
+ cp -f "$BUILDDIR/Module.symvers" "$TEMPDIR/Module.symvers" || die
+fi
echo "Building patched source"
apply_patches
@@ -1224,7 +1241,12 @@ export KPATCH_GCC_SRCDIR="$BUILDDIR"
save_env
# $TARGETS used as list, no quotes.
# shellcheck disable=SC2086
-KBUILD_MODPOST_WARN=1 make "${MAKEVARS[@]}" "-j$CPUS" $TARGETS 2>&1 | logger || die
+
+if [[ -z "$USERMODBUILDDIR" ]]; then
+ KBUILD_MODPOST_WARN=1 make "${MAKEVARS[@]}" "-j$CPUS" $TARGETS 2>&1 | logger || die
+else
+ KBUILD_MODPOST_WARN=1 make "${MAKEVARS[@]}" -C "$USERMODBUILDDIR" M="$USERMODBUILDDIR" $USERMODFLAGS "-j$CPUS" $TARGETS 2>&1 | logger || die
+fi
# source.c:(.section+0xFF): undefined reference to `symbol'
grep "undefined reference" "$LOGFILE" | sed -r "s/^.*\`(.*)'$/\\1/" \
@@ -1239,7 +1261,7 @@ fi
grep -q vmlinux "$KERNEL_SRCDIR/Module.symvers" || die "truncated $KERNEL_SRCDIR/Module.symvers file"
-if [[ -n "$CONFIG_MODVERSIONS" ]]; then
+if [[ -n "$CONFIG_MODVERSIONS" ]] && [[ "$OOT_MODULE" != "yes" ]]; then
trace_off "reading Module.symvers"
while read -ra sym_line; do
if [[ ${#sym_line[@]} -lt 4 ]]; then
@@ -1269,7 +1291,11 @@ fi
for i in $(cat "$TEMPDIR/changed_objs")
do
mkdir -p "$TEMPDIR/patched/$(dirname "$i")" || die
- cp -f "$BUILDDIR/$i" "$TEMPDIR/patched/$i" || die
+ if [ -z "$USERMODBUILDDIR" ];then
+ cp -f "$BUILDDIR/$i" "$TEMPDIR/patched/$i" || die
+ else
+ cp -f "$i" "$TEMPDIR/patched/$i" || die
+ fi
done
echo "Extracting new and modified ELF sections"
@@ -1303,7 +1329,7 @@ CHANGED=0
ERROR=0
# Prepare OOT module symvers file
-if [[ -n "$OOT_MODULE" ]]; then
+if [[ -n "$OOT_MODULE" ]] && [[ "$OOT_MODULE" != "yes" ]]; then
cp -f "$OOT_MODULE_SRCDIR/Module.symvers" "$TEMPDIR/Module.symvers" || die
awk '{ print $1 "\t" $2 "\t" $3 "\t" $4}' "${KERNEL_SRCDIR}/Module.symvers" >> "$TEMPDIR/Module.symvers"
fi
@@ -1322,7 +1348,7 @@ for i in $FILES; do
find_kobj "$i"
cd "$TEMPDIR" || die
if [[ -e "orig/$i" ]]; then
- if [[ -n $OOT_MODULE ]]; then
+ if [[ -n $OOT_MODULE ]] && [[ "$OOT_MODULE" != "yes" ]]; then
KOBJFILE_NAME="$(basename --suffix=.ko "$OOT_MODULE")"
KOBJFILE_NAME="${KOBJFILE_NAME//-/_}"
KOBJFILE_PATH="$OOT_MODULE"
@@ -1339,6 +1365,14 @@ for i in $FILES; do
KOBJFILE_PATH="${TEMPDIR}/module/$KOBJFILE"
SYMTAB="${KOBJFILE_PATH}.symtab"
SYMVERS_FILE="$BUILDDIR/Module.symvers"
+
+ if [ "$OOT_MODULE" == "yes" ];then
+ MODBUILDDIR="/lib/modules/$ARCHVERSION/build/"
+ SYMVERS_FILE="$TEMPDIR/Module.symvers"
+ [[ -e $BUILDDIR/Module.symvers ]] && cp "$BUILDDIR/Module.symvers" "$SYMVERS_FILE"
+ [[ -e $USERMODBUILDDIR/Module.symvers ]] && cp "$USERMODBUILDDIR/Module.symvers" $SYMVERS_FILE
+ awk '{ print $1 "\t" $2 "\t" $3 "\t" $4}' "${MODBUILDDIR}/Module.symvers" >> "$SYMVERS_FILE"
+ fi
fi
"$READELF" -s --wide "$KOBJFILE_PATH" > "$SYMTAB"
@@ -1487,7 +1521,7 @@ fi
# column containing lines unique to first file.
UNDEFINED=$(comm -23 <(sort -u "${TEMPDIR}"/undefined_references) \
<(sort -u "${TEMPDIR}"/new_symbols) | tr '\n' ' ')
-[[ -n "$UNDEFINED" ]] && die "Undefined symbols: $UNDEFINED"
+[[ -z "$USERMODBUILDDIR" ]] && [[ -n "$UNDEFINED" ]] && die "Undefined symbols: $UNDEFINED"
cp -f "$TEMPDIR/patch/$MODNAME.ko" "$BASE" || die
diff --git a/kpatch-build/kpatch-cc b/kpatch-build/kpatch-cc
index 17aae25..ce72e55 100755
--- a/kpatch-build/kpatch-cc
+++ b/kpatch-build/kpatch-cc
@@ -24,7 +24,9 @@ if [[ "$TOOLCHAINCMD" =~ ^(.*-)?gcc$ || "$TOOLCHAINCMD" =~ ^(.*-)?clang$ ]] ; th
[[ "$obj" = */.tmp_*.o ]] && obj="${obj/.tmp_/}"
relobj=${obj##"$KPATCH_GCC_SRCDIR"/}
- case "$relobj" in
+ tmpobj=$(readlink -f $obj)
+ relobj2=${tmpobj##"$KPATCH_GCC_SRCDIR"/}
+ case "$relobj2" in
*.mod.o|\
*built-in.o|\
*built-in.a|\
--
2.33.0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。