diff --git a/Makefile b/Makefile index 166aa5625f5a..f5cfa8acefb4 100644 --- a/Makefile +++ b/Makefile @@ -813,10 +813,16 @@ LDFLAGS_vmlinux += --gc-sections endif ifdef CONFIG_LTO_CLANG -lto-clang-flags := -flto -fvisibility=hidden +ifdef CONFIG_THINLTO +lto-clang-flags := -flto=thin +KBUILD_LDFLAGS += --thinlto-cache-dir=.thinlto-cache +else +lto-clang-flags := -flto +endif +lto-clang-flags += -fvisibility=default $(call cc-option, -fsplit-lto-unit) # allow disabling only clang LTO where needed -DISABLE_LTO_CLANG := -fno-lto -fvisibility=default +DISABLE_LTO_CLANG := -fno-lto export DISABLE_LTO_CLANG endif @@ -829,7 +835,7 @@ export LTO_CFLAGS DISABLE_LTO endif ifdef CONFIG_CFI_CLANG -cfi-clang-flags += -fsanitize=cfi $(call cc-option, -fsplit-lto-unit) +cfi-clang-flags += -fsanitize=cfi DISABLE_CFI_CLANG := -fno-sanitize=cfi ifdef CONFIG_MODULES cfi-clang-flags += -fsanitize-cfi-cross-dso diff --git a/arch/Kconfig b/arch/Kconfig index 0a183cde58c7..e6b996cc1ae8 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -486,6 +486,18 @@ config ARCH_SUPPORTS_LTO_CLANG - compiling inline assembly with clang's integrated assembler, - and linking with LLD. +config ARCH_SUPPORTS_THINLTO + bool + help + An architecture should select this if it supports clang's ThinLTO. + +config THINLTO + bool "Use clang ThinLTO (EXPERIMENTAL)" + depends on LTO_CLANG && ARCH_SUPPORTS_THINLTO + default y + help + Use ThinLTO to speed up Link Time Optimization. + choice prompt "Link-Time Optimization (LTO) (EXPERIMENTAL)" default LTO_NONE