On 5/9/25 4:17 PM, Josh Poimboeuf wrote: > 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'. > > Signed-off-by: Josh Poimboeuf <jpoim...@kernel.org> > --- > scripts/livepatch/klp-build | 697 ++++++++++++++++++++++++++++++++++++ > ... > +get_patch_files() { > + local patch="$1" > + > + grep0 -E '^(--- |\+\+\+ )' "$patch" \ > + | gawk '{print $2}' \
If we split the rest of this line on the tab character and print the first part of $2: gawk '{ split($2, a, "\t"); print a[1] }' then it can additionally handle patches generated by `diff -Nupr` with a timepstamp ("--- <filepath>\t<timestamp>"). > +# Refresh the patch hunk headers, specifically the line numbers and counts. > +refresh_patch() { > + local patch="$1" > + local tmpdir="$PATCH_TMP_DIR" > + local files=() > + > + rm -rf "$tmpdir" > + mkdir -p "$tmpdir/a" > + mkdir -p "$tmpdir/b" > + > + # Find all source files affected by the patch > + grep0 -E '^(--- |\+\+\+ )[^ /]+' "$patch" | > + sed -E 's/(--- |\+\+\+ )[^ /]+\///' | > + sort | uniq | mapfile -t files > + Should just call `get_patch_files() here? -- Joe