Skip to content

Commit b5cb300

Browse files
author
Stephen Cheng
committed
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 <stephen.cheng@citrix.com>
1 parent 7085e9d commit b5cb300

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

kpatch/kpatch

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@
2525

2626
INSTALLDIR=/var/lib/kpatch
2727
SCRIPTDIR="$(readlink -f "$(dirname "$(type -p "$0")")")"
28+
if command -v readelf >/dev/null 2>&1; then
29+
get_module_section_string() {
30+
readelf -p "$2" "$1" | grep '\[.*\]' | awk '{print $3}'
31+
}
32+
else
33+
get_module_section_string() {
34+
eu-readelf --string-dump="$2" "$1" | awk 'NF>=3 && /^\s*\[/ {print $3; exit}'
35+
}
36+
fi
2837
VERSION="0.9.11"
2938
POST_ENABLE_WAIT=15 # seconds
3039
POST_SIGNAL_WAIT=60 # seconds
@@ -135,7 +144,7 @@ core_loaded () {
135144
}
136145

137146
get_module_name () {
138-
readelf -p .gnu.linkonce.this_module "$1" | grep '\[.*\]' | awk '{print $3}'
147+
get_module_section_string "$1" .gnu.linkonce.this_module
139148
}
140149

141150
init_sysfs_var() {
@@ -159,7 +168,7 @@ verify_module_checksum () {
159168
modname="$(get_module_name "$1")"
160169
[[ -z "$modname" ]] && return 1
161170

162-
checksum="$(readelf -p .kpatch.checksum "$1" 2>&1 | grep '\[.*\]' | awk '{print $3}')"
171+
checksum="$(get_module_section_string "$1" .kpatch.checksum 2>/dev/null)"
163172

164173
# Fail checksum match only if both exist and diverge
165174
if [[ -n "$checksum" ]] && [[ -e "$SYSFS/${modname}/checksum" ]] ; then

0 commit comments

Comments
 (0)