From a15c6ebb17967c304d6fc0eae0f57c77ee1f9536 Mon Sep 17 00:00:00 2001 From: Sami Tolvanen Date: Thu, 1 Aug 2019 12:45:43 -0700 Subject: [PATCH] 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 --- Makefile | 12 +++++++++--- arch/Kconfig | 12 ++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) 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