Kbuild: 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> Signed-off-by: mydongistiny <jaysonedson@gmail.com> Signed-off-by: DennySPB <dennyspb@gmail.com>
This commit is contained in:
parent
9c537aaffc
commit
76290c95e6
4 changed files with 26 additions and 13 deletions
17
Makefile
17
Makefile
|
@ -694,14 +694,12 @@ ifneq ($(ld-name),lld)
|
|||
LDFINAL_vmlinux := $(LD)
|
||||
LD := $(LDGOLD)
|
||||
KBUILD_LDFLAGS += -plugin LLVMgold.so
|
||||
KBUILD_LDFLAGS += -plugin-opt=-function-sections
|
||||
KBUILD_LDFLAGS += -plugin-opt=-data-sections
|
||||
endif
|
||||
# use llvm-ar for building symbol tables from IR files, and llvm-dis instead
|
||||
# use llvm-ar for building symbol tables from IR files, and llvm-nm 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
|
||||
|
@ -752,7 +750,12 @@ 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
|
||||
else
|
||||
lto-clang-flags := -flto
|
||||
endif
|
||||
lto-clang-flags += -fvisibility=default $(call cc-option, -fsplit-lto-unit)
|
||||
|
||||
# Limit inlining across translation units to reduce binary size
|
||||
LD_FLAGS_LTO_CLANG := -mllvm -import-instr-limit=5
|
||||
|
@ -763,7 +766,7 @@ KBUILD_LDFLAGS_MODULE += $(LD_FLAGS_LTO_CLANG)
|
|||
KBUILD_LDFLAGS_MODULE += -T $(srctree)/scripts/module-lto.lds
|
||||
|
||||
# allow disabling only clang LTO where needed
|
||||
DISABLE_LTO_CLANG := -fno-lto -fvisibility=default
|
||||
DISABLE_LTO_CLANG := -fno-lto
|
||||
export DISABLE_LTO_CLANG
|
||||
endif
|
||||
|
||||
|
|
12
arch/Kconfig
12
arch/Kconfig
|
@ -503,6 +503,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
|
||||
|
|
|
@ -218,7 +218,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; \
|
||||
|
@ -570,7 +570,7 @@ cmd_export_list = \
|
|||
$(filter_export_list) \
|
||||
>>$(ksyms-lds); \
|
||||
else \
|
||||
$(LLVM_DIS) -o=- $$o | \
|
||||
$(LLVM_NM) $$o | \
|
||||
$(filter_export_list) \
|
||||
>>$(ksyms-lds); \
|
||||
fi; \
|
||||
|
|
|
@ -138,10 +138,8 @@ ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink)
|
|||
quiet_cmd_ld_ko_o = LD [M] $@
|
||||
|
||||
ifdef CONFIG_LTO_CLANG
|
||||
bad_ld_flags = -plugin-opt=-function-sections -plugin-opt=-data-sections
|
||||
filtered_ldflags = $(filter-out $(bad_ld_flags),$(LDFLAGS))
|
||||
cmd_ld_ko_o = \
|
||||
$(LD) -r $(filtered_ld_flags) \
|
||||
$(LD) -r $(KBUILD_LDFLAGS) \
|
||||
$(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \
|
||||
$(shell [ -s $(@:.ko=.o.symversions) ] && \
|
||||
echo -T $(@:.ko=.o.symversions)) \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue