The klp-build script overrides the kernel's setlocalversion script to
freeze the version string.  This prevents the build system from appending
"+" or "-dirty" suffixes between original and patched kernel builds.

However, a version mismatch may still occur when running successive
klp-build commands using the short-circuit option (-S 2):

- Initial Run (-T): The real setlocalversion runs once.  It is then
  replaced by a fixed-string copy.  On exit, the original script is
  restored.
- Subsequent Runs (-S 2): The tree contains the original setlocalversion
  script again.  When set_kernelversion() is called, it may generate a
  different version string because the tree state has changed (e.g.,
  include/config/auto.conf now exists).  This causes patched kernel
  builds to use a version string that differs from the original.

Fix this by restoring the saved override when SHORT_CIRCUIT >= 2.  This
ensures that subsequent patched builds reuse the localversion from the
initial klp-build run.

Signed-off-by: Joe Lawrence <[email protected]>
---
 scripts/livepatch/klp-build | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/scripts/livepatch/klp-build b/scripts/livepatch/klp-build
index 60c7635e65c1..6d3adadfc394 100755
--- a/scripts/livepatch/klp-build
+++ b/scripts/livepatch/klp-build
@@ -291,17 +291,26 @@ set_module_name() {
 
 # Hardcode the value printed by the localversion script to prevent patch
 # application from appending it with '+' due to a dirty working tree.
+# When short-circuiting at step 2 or later, restore the saved override from
+# a prior run instead of recomputing (avoids version mismatch with orig 
objects).
 set_kernelversion() {
        local file="$SRC/scripts/setlocalversion"
        local localversion
 
        stash_file "$file"
+       if (( SHORT_CIRCUIT >= 2 )); then
+               [[ ! -f "$TMP_DIR/setlocalversion.override" ]] && \
+                       die "previous setlocalversion.override not found"
+               cp -f "$TMP_DIR/setlocalversion.override" 
"$SRC/scripts/setlocalversion"
+               return 0
+       fi
 
        localversion="$(cd "$SRC" && make --no-print-directory kernelversion)"
        localversion="$(cd "$SRC" && KERNELVERSION="$localversion" 
./scripts/setlocalversion)"
        [[ -z "$localversion" ]] && die "setlocalversion failed"
 
        sed -i "2i echo $localversion; exit 0" scripts/setlocalversion
+       cp -f "$SRC/scripts/setlocalversion" "$TMP_DIR/setlocalversion.override"
 }
 
 get_patch_input_files() {
-- 
2.53.0


Reply via email to