From 497649b03d28e429690b1b3c0eb6f1cde620ef7d Mon Sep 17 00:00:00 2001 From: Song Liu Date: Tue, 28 Jan 2025 17:13:31 -0800 Subject: [PATCH 118/118] kpatch-build: lto: sed logic for --lto-obj-path in newer kernel In newer kernel, the thinlto-cache-dir line is removed from Makefile. Therefore, we cannot use it to add theh --lto-obj-path option. Use a different sed logic for newer kernel. Signed-off-by: Song Liu --- kpatch-build/kpatch-build | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build index c284d77..a14fd48 100755 --- a/kpatch-build/kpatch-build +++ b/kpatch-build/kpatch-build @@ -1244,7 +1244,13 @@ if [[ -n "$CONFIG_LTO_CLANG" ]]; then # update Makefile so that ld.lld generate vmlinux.o.thinlto.o* files for vmlinux.o backup_kernel_file "Makefile" - sed -i "s/--thinlto-cache-dir=\$(extmod_prefix).thinlto-cache/--lto-obj-path=vmlinux.o.thinlto.o/g" "$KERNEL_SRCDIR"/Makefile + # For older kernel (<=v6.9.4), replace the --thinlto-cache-dir line with --lto-obj-path=... + # For newer kernel (>=v6.9.5), add the --lto-obj-path=... line after CONFIG_LTO_CLANG_THIN + if grep -q thinlto-cache-dir "$KERNEL_SRCDIR"/Makefile ; then + sed -i "s/--thinlto-cache-dir=\$(extmod_prefix).thinlto-cache/--lto-obj-path=vmlinux.o.thinlto.o/g" "$KERNEL_SRCDIR"/Makefile + else + sed -i "/CONFIG_LTO_CLANG_THIN/a KBUILD_LDFLAGS += --lto-obj-path=vmlinux.o.thinlto.o" "$KERNEL_SRCDIR"/Makefile + fi # update scripts/Makefile.build so that ld.lld generate XX.o.thinlto.o* files for modules backup_kernel_file "scripts/Makefile.build" -- 2.48.1