From 02ccca667a5d7343ffee7b4c4a01a7dc2db91c8f Mon Sep 17 00:00:00 2001 From: yinbinbin Date: Wed, 9 Nov 2022 20:25:28 +0800 Subject: [PATCH 1/2] kpatch:don't need vmlinux Signed-off-by: yinbinbin --- kpatch-build/kpatch-build | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build index 5a60191..f03d4cd 100755 --- a/kpatch-build/kpatch-build +++ b/kpatch-build/kpatch-build @@ -271,9 +271,14 @@ find_core_symvers() { } gcc_version_from_file() { - "$READELF" -p .comment "$1" | grep -m 1 -o 'GCC:.*' + "$READELF" -p .comment "$1" | grep -m 1 -o 'GCC:.*'| awk '{$1=$2=""; print $0}'|awk '{gsub(/^\s+|\s+$/, "");print}' } +gcc_version_from_config() { + if [[ -n "$CONFIGFILE" ]]; then + cat "$CONFIGFILE" | grep -w "Compiler: gcc" | awk '{$1=$2=$3=$4=""; print $0}' | awk '{gsub(/^\s+|\s+$/, "");print}' + fi +} gcc_version_check() { local target="$1" local c="$TEMPDIR/test.c" o="$TEMPDIR/test.o" @@ -284,7 +289,11 @@ gcc_version_check() { echo 'void main(void) {}' > "$c" out="$("$GCC" -c -pg -ffunction-sections -o "$o" "$c" 2>&1)" gccver="$(gcc_version_from_file "$o")" + if [[ -f "$target" ]]; then kgccver="$(gcc_version_from_file "$target")" + else + kgccver="$(gcc_version_from_config)" + fi if [[ -n "$out" ]]; then warn "gcc >= 4.8 required for -pg -ffunction-settings" @@ -806,8 +815,6 @@ if [[ -n "$USERSRCDIR" ]]; then KERNEL_SRCDIR="$USERSRCDIR" [[ -z "$VMLINUX" ]] && VMLINUX="$KERNEL_SRCDIR"/vmlinux - [[ ! -e "$VMLINUX" ]] && die "can't find vmlinux" - # Extract the target kernel version from vmlinux in this case. VMLINUX_VER="$(strings "$VMLINUX" | grep -m 1 -e "^Linux version" | awk '{ print($3); }')" if [[ -n "$ARCHVERSION" ]]; then @@ -815,7 +822,7 @@ if [[ -n "$USERSRCDIR" ]]; then die "Kernel version mismatch: $ARCHVERSION was specified but vmlinux was built for $VMLINUX_VER" fi else - if [[ -z "$VMLINUX_VER" ]]; then + if [[ -z "$VMLINUX_VER" ]] && [[ -f "$VMLINUX" ]]; then die "Unable to determine the kernel version from vmlinux" fi ARCHVERSION="$VMLINUX_VER" @@ -1093,8 +1100,6 @@ fi export KCFLAGS="-I$DATADIR/patch -ffunction-sections -fdata-sections \ $ARCH_KCFLAGS $DEBUG_KCFLAGS" -echo "Reading special section data" -find_special_section_data if [[ $DEBUG -ge 4 ]]; then export KPATCH_GCC_DEBUG=1 @@ -1126,6 +1131,9 @@ fi # shellcheck disable=SC2086 make "${MAKEVARS[@]}" "-j$CPUS" $TARGETS 2>&1 | logger || die +echo "Reading special section data" +find_special_section_data + # Save original module symvers cp -f "$BUILDDIR/Module.symvers" "$TEMPDIR/Module.symvers" || die -- Gitee From b8716da7bec0a7edb51c104e2cd54a5a0f818442 Mon Sep 17 00:00:00 2001 From: yinbinbin Date: Fri, 11 Nov 2022 14:00:13 +0800 Subject: [PATCH 2/2] kpatch-build: fix some subfunction *.cold change error Signed-off-by: yinbinbin --- kpatch-build/kpatch-build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build index f03d4cd..f2b6fab 100755 --- a/kpatch-build/kpatch-build +++ b/kpatch-build/kpatch-build @@ -1097,7 +1097,7 @@ if [[ "$ARCH" = "s390x" ]]; then ARCH_KCFLAGS="-mno-pic-data-is-text-relative -fno-section-anchors" fi -export KCFLAGS="-I$DATADIR/patch -ffunction-sections -fdata-sections \ +export KCFLAGS="-I$DATADIR/patch -ffunction-sections -fdata-sections -fno-reorder-functions \ $ARCH_KCFLAGS $DEBUG_KCFLAGS" -- Gitee