From b5cb300eb4c71f59e38f7a2123cf81d02469946f Mon Sep 17 00:00:00 2001 From: Stephen Cheng Date: Thu, 2 Apr 2026 13:38:10 +0800 Subject: [PATCH] kpatch: support eu-readelf as alternative to GNU readelf The kpatch script is used to load live patches on production systems that may be stripped down, with binutils (which provides readelf) not installed while elfutils (which provides eu-readelf) is available. Add a get_module_section_string() helper that auto-detects the available tool at startup and uses the appropriate invocation for each. Other readelf usages in the build tooling (kpatch-build, lookup.c, test infrastructure) are left unchanged, as a compiler toolchain including binutils can reasonably be expected in a build environment. Signed-off-by: Stephen Cheng --- kpatch/kpatch | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/kpatch/kpatch b/kpatch/kpatch index 4eff2161..d75bd068 100755 --- a/kpatch/kpatch +++ b/kpatch/kpatch @@ -25,6 +25,15 @@ INSTALLDIR=/var/lib/kpatch SCRIPTDIR="$(readlink -f "$(dirname "$(type -p "$0")")")" +if command -v readelf >/dev/null 2>&1; then + get_module_section_string() { + readelf -p "$2" "$1" | grep '\[.*\]' | awk '{print $3}' + } +else + get_module_section_string() { + eu-readelf --string-dump="$2" "$1" | awk 'NF>=3 && /^\s*\[/ {print $3; exit}' + } +fi VERSION="0.9.11" POST_ENABLE_WAIT=15 # seconds POST_SIGNAL_WAIT=60 # seconds @@ -135,7 +144,7 @@ core_loaded () { } get_module_name () { - readelf -p .gnu.linkonce.this_module "$1" | grep '\[.*\]' | awk '{print $3}' + get_module_section_string "$1" .gnu.linkonce.this_module } init_sysfs_var() { @@ -159,7 +168,7 @@ verify_module_checksum () { modname="$(get_module_name "$1")" [[ -z "$modname" ]] && return 1 - checksum="$(readelf -p .kpatch.checksum "$1" 2>&1 | grep '\[.*\]' | awk '{print $3}')" + checksum="$(get_module_section_string "$1" .kpatch.checksum 2>/dev/null)" # Fail checksum match only if both exist and diverge if [[ -n "$checksum" ]] && [[ -e "$SYSFS/${modname}/checksum" ]] ; then