12 Star 6 Fork 44

src-openEuler/kpatch

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0008-kpatch-build-enhance-for-out-of-tree-module.patch 6.40 KB
一键复制 编辑 原始数据 按行查看 历史
HuBin95 提交于 2024-03-02 00:18 . kpatch: upgrade to 0.9.9
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
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-openeuler/kpatch.git
git@gitee.com:src-openeuler/kpatch.git
src-openeuler
kpatch
kpatch
master

搜索帮助