Skip to contentSkip to conversation

kbuild: prevent CC_FLAGS_LTO self-bloating on recursive rebuilds

PATCH In review Alexander Lobakin 2 participants 2 messages Jan 21, 2021 – Jan 22, 2021 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kbuild: prevent CC_FLAGS_LTO self-bloating on recursive rebuilds

CC_FLAGS_LTO gets initialized only via +=, never with := or =. When building with CONFIG_TRIM_UNUSED_KSYMS, Kbuild may perform several kernel rebuilds to satisfy symbol dependencies. In this case, value of CC_FLAGS_LTO is concatenated each time, which triggers a full rebuild.
Initialize it with := to fix this.

Fixes dc5723b02e52 ("kbuild: add support for Clang LTO")
---
 Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Makefile +2 -2
index 668909e7a460..2233951666f7 100644
@@ -895,10 +895,10 @@ endif
 
 ifdef CONFIG_LTO_CLANG
 ifdef CONFIG_LTO_CLANG_THIN
-CC_FLAGS_LTO	+= -flto=thin -fsplit-lto-unit
+CC_FLAGS_LTO	:= -flto=thin -fsplit-lto-unit
 KBUILD_LDFLAGS	+= --thinlto-cache-dir=$(extmod-prefix).thinlto-cache
 else
-CC_FLAGS_LTO	+= -flto
+CC_FLAGS_LTO	:= -flto
 endif
 CC_FLAGS_LTO	+= -fvisibility=hidden
 
Signature · 1 line
2.30.0
#1 lore raw
Quoted 9 lines · Alexander Lobakin

CC_FLAGS_LTO gets initialized only via +=, never with := or =. When building with CONFIG_TRIM_UNUSED_KSYMS, Kbuild may perform several kernel rebuilds to satisfy symbol dependencies. In this case, value of CC_FLAGS_LTO is concatenated each time, which triggers a full rebuild.
Initialize it with := to fix this.

Fixes dc5723b02e52 ("kbuild: add support for Clang LTO")

Ah-ha, good catch; thanks!

I'll get this into the tree.

-Kees

Quoted 25 lines
---
 Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Makefile +2 -2
index 668909e7a460..2233951666f7 100644
@@ -895,10 +895,10 @@ endif
 
 ifdef CONFIG_LTO_CLANG
 ifdef CONFIG_LTO_CLANG_THIN
-CC_FLAGS_LTO	+= -flto=thin -fsplit-lto-unit
+CC_FLAGS_LTO	:= -flto=thin -fsplit-lto-unit
 KBUILD_LDFLAGS	+= --thinlto-cache-dir=$(extmod-prefix).thinlto-cache
 else
-CC_FLAGS_LTO	+= -flto
+CC_FLAGS_LTO	:= -flto
 endif
 CC_FLAGS_LTO	+= -fvisibility=hidden
 
Signature · 1 line
2.30.0
Signature · 1 line
Kees Cook