mirror of
https://github.com/dynup/kpatch
synced 2025-04-17 20:45:23 +00:00
commit
270d783947
@ -37,7 +37,6 @@
|
||||
BASE="$PWD"
|
||||
SCRIPTDIR="$(readlink -f "$(dirname "$(type -p "$0")")")"
|
||||
ARCH="$(uname -m)"
|
||||
ARCHVERSION="$(uname -r)"
|
||||
CPUS="$(getconf _NPROCESSORS_ONLN)"
|
||||
CACHEDIR="${CACHEDIR:-$HOME/.kpatch}"
|
||||
SRCDIR="$CACHEDIR/src"
|
||||
@ -174,6 +173,7 @@ find_core_symvers() {
|
||||
gcc_version_from_file() {
|
||||
readelf -p .comment "$1" | grep -o 'GCC:.*'
|
||||
}
|
||||
|
||||
gcc_version_check() {
|
||||
local c="$TEMPDIR/test.c" o="$TEMPDIR/test.o"
|
||||
local out gccver kgccver
|
||||
@ -207,26 +207,26 @@ gcc_version_check() {
|
||||
|
||||
find_special_section_data_ppc64le() {
|
||||
SPECIAL_VARS="$(readelf -wi "$VMLINUX" |
|
||||
gawk --non-decimal-data '
|
||||
BEGIN { f = b = e = 0 }
|
||||
gawk --non-decimal-data '
|
||||
BEGIN { f = b = e = 0 }
|
||||
|
||||
# Set state if name matches
|
||||
f == 0 && /DW_AT_name.* fixup_entry[[:space:]]*$/ {f = 1; next}
|
||||
b == 0 && /DW_AT_name.* bug_entry[[:space:]]*$/ {b = 1; next}
|
||||
e == 0 && /DW_AT_name.* exception_table_entry[[:space:]]*$/ {e = 1; next}
|
||||
# Set state if name matches
|
||||
f == 0 && /DW_AT_name.* fixup_entry[[:space:]]*$/ {f = 1; next}
|
||||
b == 0 && /DW_AT_name.* bug_entry[[:space:]]*$/ {b = 1; next}
|
||||
e == 0 && /DW_AT_name.* exception_table_entry[[:space:]]*$/ {e = 1; next}
|
||||
|
||||
# Reset state unless this abbrev describes the struct size
|
||||
f == 1 && !/DW_AT_byte_size/ { f = 0; next }
|
||||
b == 1 && !/DW_AT_byte_size/ { b = 0; next }
|
||||
e == 1 && !/DW_AT_byte_size/ { e = 0; next }
|
||||
# Reset state unless this abbrev describes the struct size
|
||||
f == 1 && !/DW_AT_byte_size/ { f = 0; next }
|
||||
b == 1 && !/DW_AT_byte_size/ { b = 0; next }
|
||||
e == 1 && !/DW_AT_byte_size/ { e = 0; next }
|
||||
|
||||
# Now that we know the size, stop parsing for it
|
||||
f == 1 {printf("export FIXUP_STRUCT_SIZE=%d\n", $4); a = 2}
|
||||
b == 1 {printf("export BUG_STRUCT_SIZE=%d\n", $4); b = 2}
|
||||
e == 1 {printf("export EX_STRUCT_SIZE=%d\n", $4); e = 2}
|
||||
# Now that we know the size, stop parsing for it
|
||||
f == 1 {printf("export FIXUP_STRUCT_SIZE=%d\n", $4); a = 2}
|
||||
b == 1 {printf("export BUG_STRUCT_SIZE=%d\n", $4); b = 2}
|
||||
e == 1 {printf("export EX_STRUCT_SIZE=%d\n", $4); e = 2}
|
||||
|
||||
# Bail out once we have everything
|
||||
f == 2 && b == 2 && e == 2 {exit}')"
|
||||
# Bail out once we have everything
|
||||
f == 2 && b == 2 && e == 2 {exit}')"
|
||||
|
||||
[[ -n "$SPECIAL_VARS" ]] && eval "$SPECIAL_VARS"
|
||||
|
||||
@ -245,29 +245,29 @@ find_special_section_data() {
|
||||
|
||||
[[ "$CONFIG_PARAVIRT" -eq 0 ]] && AWK_OPTIONS="-vskip_p=1"
|
||||
SPECIAL_VARS="$(readelf -wi "$VMLINUX" |
|
||||
gawk --non-decimal-data $AWK_OPTIONS '
|
||||
BEGIN { a = b = p = e = 0 }
|
||||
gawk --non-decimal-data $AWK_OPTIONS '
|
||||
BEGIN { a = b = p = e = 0 }
|
||||
|
||||
# Set state if name matches
|
||||
a == 0 && /DW_AT_name.* alt_instr[[:space:]]*$/ {a = 1; next}
|
||||
b == 0 && /DW_AT_name.* bug_entry[[:space:]]*$/ {b = 1; next}
|
||||
p == 0 && /DW_AT_name.* paravirt_patch_site[[:space:]]*$/ {p = 1; next}
|
||||
e == 0 && /DW_AT_name.* exception_table_entry[[:space:]]*$/ {e = 1; next}
|
||||
# Set state if name matches
|
||||
a == 0 && /DW_AT_name.* alt_instr[[:space:]]*$/ {a = 1; next}
|
||||
b == 0 && /DW_AT_name.* bug_entry[[:space:]]*$/ {b = 1; next}
|
||||
p == 0 && /DW_AT_name.* paravirt_patch_site[[:space:]]*$/ {p = 1; next}
|
||||
e == 0 && /DW_AT_name.* exception_table_entry[[:space:]]*$/ {e = 1; next}
|
||||
|
||||
# Reset state unless this abbrev describes the struct size
|
||||
a == 1 && !/DW_AT_byte_size/ { a = 0; next }
|
||||
b == 1 && !/DW_AT_byte_size/ { b = 0; next }
|
||||
p == 1 && !/DW_AT_byte_size/ { p = 0; next }
|
||||
e == 1 && !/DW_AT_byte_size/ { e = 0; next }
|
||||
# Reset state unless this abbrev describes the struct size
|
||||
a == 1 && !/DW_AT_byte_size/ { a = 0; next }
|
||||
b == 1 && !/DW_AT_byte_size/ { b = 0; next }
|
||||
p == 1 && !/DW_AT_byte_size/ { p = 0; next }
|
||||
e == 1 && !/DW_AT_byte_size/ { e = 0; next }
|
||||
|
||||
# Now that we know the size, stop parsing for it
|
||||
a == 1 {printf("export ALT_STRUCT_SIZE=%d\n", $4); a = 2}
|
||||
b == 1 {printf("export BUG_STRUCT_SIZE=%d\n", $4); b = 2}
|
||||
p == 1 {printf("export PARA_STRUCT_SIZE=%d\n", $4); p = 2}
|
||||
e == 1 {printf("export EX_STRUCT_SIZE=%d\n", $4); e = 2}
|
||||
# Now that we know the size, stop parsing for it
|
||||
a == 1 {printf("export ALT_STRUCT_SIZE=%d\n", $4); a = 2}
|
||||
b == 1 {printf("export BUG_STRUCT_SIZE=%d\n", $4); b = 2}
|
||||
p == 1 {printf("export PARA_STRUCT_SIZE=%d\n", $4); p = 2}
|
||||
e == 1 {printf("export EX_STRUCT_SIZE=%d\n", $4); e = 2}
|
||||
|
||||
# Bail out once we have everything
|
||||
a == 2 && b == 2 && (p == 2 || skip_p) && e == 2 {exit}')"
|
||||
# Bail out once we have everything
|
||||
a == 2 && b == 2 && (p == 2 || skip_p) && e == 2 {exit}')"
|
||||
|
||||
[[ -n "$SPECIAL_VARS" ]] && eval "$SPECIAL_VARS"
|
||||
|
||||
@ -353,22 +353,24 @@ module_name_string() {
|
||||
|
||||
usage() {
|
||||
echo "usage: $(basename "$0") [options] <patch1 ... patchN>" >&2
|
||||
echo " patchN Input patchfile(s)" >&2
|
||||
echo " -h, --help Show this help message" >&2
|
||||
echo " -r, --sourcerpm Specify kernel source RPM" >&2
|
||||
echo " -s, --sourcedir Specify kernel source directory" >&2
|
||||
echo " -c, --config Specify kernel config file" >&2
|
||||
echo " -v, --vmlinux Specify original vmlinux" >&2
|
||||
echo " -j, --jobs Specify the number of make jobs" >&2
|
||||
echo " -t, --target Specify custom kernel build targets" >&2
|
||||
echo " -o, --output Specify output folder" >&2
|
||||
echo " -d, --debug Keep scratch files in /tmp" >&2
|
||||
echo " patchN Input patchfile(s)" >&2
|
||||
echo " -h, --help Show this help message" >&2
|
||||
echo " -a, --archversion Specify the kernel arch version" >&2
|
||||
echo " -r, --sourcerpm Specify kernel source RPM" >&2
|
||||
echo " -s, --sourcedir Specify kernel source directory" >&2
|
||||
echo " -c, --config Specify kernel config file" >&2
|
||||
echo " -v, --vmlinux Specify original vmlinux" >&2
|
||||
echo " -j, --jobs Specify the number of make jobs" >&2
|
||||
echo " -t, --target Specify custom kernel build targets" >&2
|
||||
echo " -n, --name Specify the name of the kpatch module" >&2
|
||||
echo " -o, --output Specify output folder" >&2
|
||||
echo " -d, --debug Keep scratch files in /tmp" >&2
|
||||
echo " --skip-cleanup Skip post-build cleanup" >&2
|
||||
echo " --skip-gcc-check Skip gcc version matching check" >&2
|
||||
echo " (not recommended)" >&2
|
||||
}
|
||||
|
||||
options="$(getopt -o hr:s:c:v:j:t:n:o:d -l "help,sourcerpm:,sourcedir:,config:,vmlinux:,jobs:,target:,name:,output:,debug,skip-gcc-check,skip-cleanup" -- "$@")" || die "getopt failed"
|
||||
options="$(getopt -o ha:r:s:c:v:j:t:n:o:d -l "help,archversion:,sourcerpm:,sourcedir:,config:,vmlinux:,jobs:,target:,name:,output:,debug,skip-gcc-check,skip-cleanup" -- "$@")" || die "getopt failed"
|
||||
|
||||
eval set -- "$options"
|
||||
|
||||
@ -378,13 +380,14 @@ while [[ $# -gt 0 ]]; do
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
-a|--archversion)
|
||||
ARCHVERSION="$2"
|
||||
shift
|
||||
;;
|
||||
-r|--sourcerpm)
|
||||
[[ ! -f "$2" ]] && die "source rpm '$2' not found"
|
||||
SRCRPM="$(readlink -f "$2")"
|
||||
shift
|
||||
rpmname="$(basename "$SRCRPM")"
|
||||
ARCHVERSION="${rpmname%.src.rpm}.$(uname -m)"
|
||||
ARCHVERSION="${ARCHVERSION#kernel-}"
|
||||
;;
|
||||
-s|--sourcedir)
|
||||
[[ ! -d "$2" ]] && die "source dir '$2' not found"
|
||||
@ -447,21 +450,42 @@ if [[ ${#PATCH_LIST[@]} -eq 0 ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -n "$ARCHVERSION" ]] && [[ -n "$VMLINUX" ]]; then
|
||||
warn "--archversion is incompatible with --vmlinux"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -n "$SRCRPM" ]]; then
|
||||
if [[ -n "$ARCHVERSION" ]]; then
|
||||
warn "--archversion is incompatible with --sourcerpm"
|
||||
exit 1
|
||||
fi
|
||||
rpmname="$(basename "$SRCRPM")"
|
||||
ARCHVERSION="${rpmname%.src.rpm}.$(uname -m)"
|
||||
ARCHVERSION="${ARCHVERSION#kernel-}"
|
||||
fi
|
||||
|
||||
# ensure cachedir and tempdir are setup properly and cleaned
|
||||
mkdir -p "$TEMPDIR" || die "Couldn't create $TEMPDIR"
|
||||
rm -rf "${TEMPDIR:?}"/*
|
||||
rm -f "$LOGFILE"
|
||||
|
||||
if [[ -n "$USERSRCDIR" ]]; then
|
||||
if [[ -n "$ARCHVERSION" ]]; then
|
||||
warn "--archversion is incompatible with --sourcedir"
|
||||
exit 1
|
||||
fi
|
||||
SRCDIR="$USERSRCDIR"
|
||||
|
||||
[[ -z "$VMLINUX" ]] && VMLINUX="$SRCDIR"/vmlinux
|
||||
[[ ! -e "$VMLINUX" ]] && die "can't find vmlinux"
|
||||
|
||||
# Extract the target kernel version from vmlinux in this case.
|
||||
ARCHVERSION="$(strings "$VMLINUX" | grep -e "^Linux version" | awk '{ print($3); }')"
|
||||
ARCHVERSION="$(strings "$VMLINUX" | grep -m 1 -e "^Linux version" | awk '{ print($3); }')"
|
||||
fi
|
||||
|
||||
[[ -z "$ARCHVERSION" ]] && ARCHVERSION="$(uname -r)"
|
||||
|
||||
[[ "$SKIPCLEANUP" -eq 0 ]] && trap cleanup EXIT INT TERM HUP
|
||||
|
||||
KVER="${ARCHVERSION%%-*}"
|
||||
@ -488,7 +512,7 @@ elif [[ "$DISTRO" = ubuntu ]] || [[ "$DISTRO" = debian ]]; then
|
||||
if [[ "$DISTRO" = ubuntu ]]; then
|
||||
[[ -e "$VMLINUX" ]] || die "linux-image-$ARCHVERSION-dbgsym not installed"
|
||||
|
||||
elif [[ "$DISTRO" = debian ]]; then
|
||||
elif [[ "$DISTRO" = debian ]]; then
|
||||
[[ -e "$VMLINUX" ]] || die "linux-image-$ARCHVERSION-dbg not installed"
|
||||
fi
|
||||
|
||||
@ -662,8 +686,8 @@ CROSS_COMPILE="$TOOLSDIR/kpatch-gcc " \
|
||||
KBUILD_MODPOST_WARN=1 \
|
||||
make "-j$CPUS" $TARGETS >> "$LOGFILE" 2>&1 || die
|
||||
[[ "${PIPESTATUS[0]}" -eq 0 ]] || die
|
||||
grep -q "undefined reference" "$LOGFILE" | grep -qv kpatch_shadow && die
|
||||
grep -q "undefined!" "$LOGFILE" |grep -qv kpatch_shadow && die
|
||||
grep "undefined reference" "$LOGFILE" | grep -qv kpatch_shadow && die
|
||||
grep "undefined!" "$LOGFILE" | grep -qv kpatch_shadow && die
|
||||
|
||||
if [[ ! -e "$TEMPDIR/changed_objs" ]]; then
|
||||
die "no changed objects found"
|
||||
@ -763,8 +787,6 @@ if "$KPATCH_MODULE"; then
|
||||
fi
|
||||
|
||||
echo "Building patch module: $MODNAME.ko"
|
||||
cd "$SRCDIR" || die
|
||||
make prepare >> "$LOGFILE" 2>&1 || die
|
||||
|
||||
if [[ ! -z "$UBUNTU_KERNEL" ]]; then
|
||||
# UBUNTU: add UTS_UBUNTU_RELEASE_ABI to utsrelease.h after regenerating it
|
||||
|
@ -6,7 +6,7 @@ TOOLCHAINCMD="$1"
|
||||
shift
|
||||
|
||||
if [[ -z "$KPATCH_GCC_TEMPDIR" ]]; then
|
||||
exec "$TOOLCHAINCMD" "$@"
|
||||
exec "$TOOLCHAINCMD" "$@"
|
||||
fi
|
||||
|
||||
declare -a args=("$@")
|
||||
|
Loading…
Reference in New Issue
Block a user