ANDROID: add support for ThinLTO

This change adds support for ThinLTO, which greatly improves build times
over full LTO while retaining most of the performance benefits:

  https://clang.llvm.org/docs/ThinLTO.html

Bug: 145210207
Change-Id: I8bfc19028266077be2bc1fb5c2bc001b599d3214
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
This commit is contained in:
Sami Tolvanen
2019-08-01 12:45:43 -07:00
committed by Alistair Delva
parent 7e0ea2a79c
commit a15c6ebb17
2 changed files with 21 additions and 3 deletions

View File

@ -813,10 +813,16 @@ LDFLAGS_vmlinux += --gc-sections
endif endif
ifdef CONFIG_LTO_CLANG 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 # allow disabling only clang LTO where needed
DISABLE_LTO_CLANG := -fno-lto -fvisibility=default DISABLE_LTO_CLANG := -fno-lto
export DISABLE_LTO_CLANG export DISABLE_LTO_CLANG
endif endif
@ -829,7 +835,7 @@ export LTO_CFLAGS DISABLE_LTO
endif endif
ifdef CONFIG_CFI_CLANG 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 DISABLE_CFI_CLANG := -fno-sanitize=cfi
ifdef CONFIG_MODULES ifdef CONFIG_MODULES
cfi-clang-flags += -fsanitize-cfi-cross-dso cfi-clang-flags += -fsanitize-cfi-cross-dso

View File

@ -486,6 +486,18 @@ config ARCH_SUPPORTS_LTO_CLANG
- compiling inline assembly with clang's integrated assembler, - compiling inline assembly with clang's integrated assembler,
- and linking with LLD. - 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 choice
prompt "Link-Time Optimization (LTO) (EXPERIMENTAL)" prompt "Link-Time Optimization (LTO) (EXPERIMENTAL)"
default LTO_NONE default LTO_NONE