From 99876597c26977fdc64b2af13c122238288305cd Mon Sep 17 00:00:00 2001 From: Sami Tolvanen Date: Tue, 23 Feb 2021 13:59:52 -0800 Subject: [PATCH] kbuild: lto: force rebuilds when switching CONFIG_LTO When doing non-clean builds and switching between CONFIG_LTO=n and CONFIG_LTO=y, the build system (correctly) didn't notice that assembly and LTO-excluded C object files were rewritten in place by objtool (to add the .orc_unwind* sections), since their build command lines were the same between CONFIG_LTO=y and CONFIG_LTO=n. The objtool step would fail: vmlinux.o: warning: objtool: file already has .orc_unwind section, skipping make: *** [Makefile:1194: vmlinux] Error 255 Avoid this by making sure the build will see a difference between an LTO and non-LTO build (by including "-fno-lto" in KBUILD_*FLAGS). This will get ignored when CC_FLAGS_LTO is present, and will not be included at all when CONFIG_LTO=n. Change-Id: I7b6a3221d0972ad13db0d138c66f3789eec60062 Signed-off-by: Sami Tolvanen Signed-off-by: Kees Cook --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ae8a938c7300..57c191c6d753 100644 --- a/Makefile +++ b/Makefile @@ -964,7 +964,8 @@ endif ifdef CONFIG_LTO CC_FLAGS_LTO := $(CC_FLAGS_LTO_CLANG) -KBUILD_CFLAGS += $(CC_FLAGS_LTO) +KBUILD_CFLAGS += -fno-lto $(CC_FLAGS_LTO) +KBUILD_AFLAGS += -fno-lto export CC_FLAGS_LTO endif