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>
tirimbino
Sami Tolvanen 5 years ago
parent 6fdd67bc4d
commit 6d6127fd19
  1. 16
      Makefile
  2. 12
      arch/Kconfig
  3. 4
      scripts/Makefile.build

@ -663,8 +663,8 @@ endif
# use llvm-ar for building symbol tables from IR files, and llvm-dis instead
# of objdump for processing symbol versions and exports
LLVM_AR := llvm-ar
LLVM_DIS := llvm-dis
export LLVM_AR LLVM_DIS
LLVM_NM := llvm-nm
export LLVM_AR LLVM_NM
endif
# The arch Makefile can set ARCH_{CPP,A,C}FLAGS to override the default
@ -831,10 +831,16 @@ KBUILD_CFLAGS += $(call cc-option,-fdata-sections,)
endif
ifdef CONFIG_LTO_CLANG
lto-clang-flags := -flto -fvisibility=hidden
ifdef CONFIG_THINLTO
lto-clang-flags := -flto=thin
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
@ -851,7 +857,7 @@ export LDFINAL_vmlinux LDFLAGS_FINAL_vmlinux
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

@ -622,6 +622,18 @@ config ARCH_SUPPORTS_LTO_CLANG
- compiling inline assembly with clang's integrated assembler,
- and linking with either lld or GNU gold w/ LLVMgold.
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

@ -220,7 +220,7 @@ cmd_modversions_c = \
> $(@D)/$(@F).symversions; \
fi; \
else \
if $(LLVM_DIS) -o=- $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \
if $(LLVM_NM) $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \
$(call cmd_gensymtypes_c,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \
> $(@D)/$(@F).symversions; \
fi; \
@ -594,7 +594,7 @@ cmd_export_list = \
$(filter_export_list) \
>>$(ksyms-lds); \
else \
$(LLVM_DIS) -o=- $$o | \
$(LLVM_NM) $$o | \
$(filter_export_list) \
>>$(ksyms-lds); \
fi; \

Loading…
Cancel
Save