Files
Centos-kernel-stream-10/scripts/livepatch/fix-patch-lines
T
Joe Lawrence fdbffebeb7 livepatch/klp-build: Introduce klp-build script for generating livepatch modules
JIRA: https://issues.redhat.com/browse/RHEL-114916

commit 24ebfcd65a871df4555b98c49c9ed9a92f146113
Author: Josh Poimboeuf <jpoimboe@kernel.org>
Date:   Wed Sep 17 09:04:08 2025 -0700

    livepatch/klp-build: Introduce klp-build script for generating livepatch modules

    Add a klp-build script which automates the generation of a livepatch
    module from a source .patch file by performing the following steps:

      - Builds an original kernel with -function-sections and
        -fdata-sections, plus objtool function checksumming.

      - Applies the .patch file and rebuilds the kernel using the same
        options.

      - Runs 'objtool klp diff' to detect changed functions and generate
        intermediate binary diff objects.

      - Builds a kernel module which links the diff objects with some
        livepatch module init code (scripts/livepatch/init.c).

      - Finalizes the livepatch module (aka work around linker wreckage)
        using 'objtool klp post-link'.

    Acked-by: Petr Mladek <pmladek@suse.com>
    Tested-by: Joe Lawrence <joe.lawrence@redhat.com>
    Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2026-01-07 12:55:02 -05:00

80 lines
1.4 KiB
Awk
Executable File

#!/usr/bin/awk -f
# SPDX-License-Identifier: GPL-2.0
#
# Use #line directives to preserve original __LINE__ numbers across patches to
# avoid unwanted compilation changes.
BEGIN {
in_hunk = 0
skip = 0
}
/^--- / {
skip = $2 !~ /\.(c|h)$/
print
next
}
/^@@/ {
if (skip) {
print
next
}
in_hunk = 1
# @@ -1,3 +1,4 @@:
# 1: line number in old file
# 3: how many lines the hunk covers in old file
# 1: line number in new file
# 4: how many lines the hunk covers in new file
match($0, /^@@ -([0-9]+)(,([0-9]+))? \+([0-9]+)(,([0-9]+))? @@/, m)
# Set 'cur' to the old file's line number at the start of the hunk. It
# gets incremented for every context line and every line removal, so
# that it always represents the old file's current line number.
cur = m[1]
# last = last line number of current hunk
last = cur + (m[3] ? m[3] : 1) - 1
need_line_directive = 0
print
next
}
{
if (skip || !in_hunk || $0 ~ /^\\ No newline at end of file/) {
print
next
}
# change line
if ($0 ~ /^[+-]/) {
# inject #line after this group of changes
need_line_directive = 1
if ($0 ~ /^-/)
cur++
print
next
}
# If this is the first context line after a group of changes, inject
# the #line directive to force the compiler to correct the line
# numbering to match the original file.
if (need_line_directive) {
print "+#line " cur
need_line_directive = 0
}
if (cur == last)
in_hunk = 0
cur++
print
}