Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions kpatch-build/kpatch-build
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ gcc_version_check() {
# gcc --version varies between distributions therefore extract version
# by compiling a test file and compare it to vmlinux's version.
echo 'void main(void) {}' > "$c"
out="$(gcc -c -pg -ffunction-sections -o "$o" "$c" 2>&1)"
out="$("${KPATCH_CROSS_COMPILE}"gcc -c -pg -ffunction-sections -o "$o" "$c" 2>&1)"
gccver="$(gcc_version_from_file "$o")"
kgccver="$(gcc_version_from_file "$target")"

Expand Down Expand Up @@ -532,6 +532,9 @@ usage() {
echo " -d, --debug Enable 'xtrace' and keep scratch files" >&2
echo " in <CACHEDIR>/tmp" >&2
echo " (can be specified multiple times)" >&2
echo " --cross-compile Specify the prefix used for all executables" >&2
echo " used during compilation" >&2
echo " --distro Override distro name" >&2
echo " -e, --oot-module Enable patching out-of-tree module," >&2
echo " specify current version of module" >&2
echo " -R, --non-replace Disable replace patch (replace is on by default)" >&2
Expand All @@ -540,7 +543,7 @@ usage() {
echo " (not recommended)" >&2
}

options="$(getopt -o ha:r:s:c:v:j:t:n:o:de:R -l "help,archversion:,sourcerpm:,sourcedir:,config:,vmlinux:,jobs:,target:,name:,output:,oot-module:,debug,skip-gcc-check,skip-compiler-check,skip-cleanup,non-replace" -- "$@")" || die "getopt failed"
options="$(getopt -o ha:r:s:c:v:j:t:n:o:de:R -l "help,archversion:,sourcerpm:,sourcedir:,config:,vmlinux:,jobs:,target:,name:,output:,debug,cross-compile:,distro:,skip-gcc-check,skip-compiler-check,skip-cleanup,oot-module:,non-replace" -- "$@")" || die "getopt failed"

eval set -- "$options"

Expand Down Expand Up @@ -598,6 +601,14 @@ while [[ $# -gt 0 ]]; do
echo "DEBUG mode enabled"
fi
;;
--cross-compile)
KPATCH_CROSS_COMPILE="$2"
shift
;;
--distro)
DISTRO="$2"
shift
;;
-e|--oot-module)
[[ ! -f "$2" ]] && die "out-of-tree module '$2' not found"
OOT_MODULE="$(readlink -f "$2")"
Expand Down Expand Up @@ -695,7 +706,7 @@ fi
# Don't check external file.
# shellcheck disable=SC1090
[[ -f "$RELEASE_FILE" ]] && source "$RELEASE_FILE"
DISTRO="$ID"
DISTRO="${DISTRO:-${ID}}"
if [[ "$DISTRO" = fedora ]] || [[ "$DISTRO" = rhel ]] || [[ "$DISTRO" = ol ]] || [[ "$DISTRO" = centos ]] || [[ "$DISTRO" = openEuler ]]; then
[[ -z "$VMLINUX" ]] && VMLINUX="/usr/lib/debug/lib/modules/$ARCHVERSION/vmlinux"
[[ -e "$VMLINUX" ]] || die "kernel-debuginfo-$ARCHVERSION not installed"
Expand Down Expand Up @@ -928,6 +939,8 @@ if [[ $DEBUG -ge 4 ]]; then
export KPATCH_GCC_DEBUG=1
fi

export KPATCH_CROSS_COMPILE

echo "Building original source"
[[ -n "$OOT_MODULE" ]] || ./scripts/setlocalversion --save-scmversion || die
unset KPATCH_GCC_TEMPDIR
Expand Down Expand Up @@ -1166,6 +1179,7 @@ done
KPATCH_BUILD="$KPATCH_BUILD" KPATCH_NAME="$MODNAME" \
KBUILD_EXTRA_SYMBOLS="$KBUILD_EXTRA_SYMBOLS" \
KPATCH_LDFLAGS="$KPATCH_LDFLAGS" \
CROSS_COMPILE="$KPATCH_CROSS_COMPILE" \
make "${MAKEVARS[@]}" 2>&1 | logger || die

if [[ "$USE_KLP" -eq 1 ]]; then
Expand Down
4 changes: 2 additions & 2 deletions kpatch-build/kpatch-cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ TOOLCHAINCMD="$1"
shift

if [[ -z "$KPATCH_GCC_TEMPDIR" ]]; then
exec "$TOOLCHAINCMD" "$@"
exec "${KPATCH_CROSS_COMPILE}""${TOOLCHAINCMD}" "$@"
fi

declare -a args=("$@")
Expand Down Expand Up @@ -85,4 +85,4 @@ elif [[ "$TOOLCHAINCMD" =~ ^(.*-)?ld || "$TOOLCHAINCMD" =~ ^(.*-)?ld.lld ]] ; th
done
fi

exec "$TOOLCHAINCMD" "${args[@]}"
exec "${KPATCH_CROSS_COMPILE}""${TOOLCHAINCMD}" "${args[@]}"