2019-08-15 01:06:23 +09:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
|
# ===========================================================================
|
|
|
|
|
# Module final link
|
|
|
|
|
# ===========================================================================
|
|
|
|
|
|
|
|
|
|
PHONY := __modfinal
|
|
|
|
|
__modfinal:
|
|
|
|
|
|
FROMLIST: kbuild: add support for Clang LTO
This change adds build system support for Clang's Link Time
Optimization (LTO). With -flto, instead of ELF object files, Clang
produces LLVM bitcode, which is compiled into native code at link
time, allowing the final binary to be optimized globally. For more
details, see:
https://llvm.org/docs/LinkTimeOptimization.html
The Kconfig option CONFIG_LTO_CLANG is implemented as a choice,
which defaults to LTO being disabled. To use LTO, the architecture
must select ARCH_SUPPORTS_LTO_CLANG and support:
- compiling with Clang,
- compiling all assembly code with Clang's integrated assembler,
- and linking with LLD.
While using CONFIG_LTO_CLANG_FULL results in the best runtime
performance, the compilation is not scalable in time or
memory. CONFIG_LTO_CLANG_THIN enables ThinLTO, which allows
parallel optimization and faster incremental builds. ThinLTO is
used by default if the architecture also selects
ARCH_SUPPORTS_LTO_CLANG_THIN:
https://clang.llvm.org/docs/ThinLTO.html
To enable LTO, LLVM tools must be used to handle bitcode files, by
passing LLVM=1 and LLVM_IAS=1 options to make:
$ make LLVM=1 LLVM_IAS=1 defconfig
$ scripts/config -e LTO_CLANG_THIN
$ make LLVM=1 LLVM_IAS=1
To prepare for LTO support with other compilers, common parts are
gated behind the CONFIG_LTO option, and LTO can be disabled for
specific files by filtering out CC_FLAGS_LTO.
Bug: 145210207
Change-Id: I85eb4523ea787e4f9884e12ed6301f876d0d888e
Link: https://lore.kernel.org/lkml/20201211184633.3213045-1-samitolvanen@google.com/
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
2020-03-06 14:14:03 -08:00
|
|
|
include $(objtree)/include/config/auto.conf
|
2019-08-15 01:06:23 +09:00
|
|
|
include $(srctree)/scripts/Kbuild.include
|
|
|
|
|
|
2020-04-13 16:10:13 -07:00
|
|
|
# for c_flags and objtool_args
|
2019-08-15 01:06:23 +09:00
|
|
|
include $(srctree)/scripts/Makefile.lib
|
|
|
|
|
|
|
|
|
|
# find all modules listed in modules.order
|
|
|
|
|
modules := $(sort $(shell cat $(MODORDER)))
|
|
|
|
|
|
|
|
|
|
__modfinal: $(modules)
|
|
|
|
|
@:
|
|
|
|
|
|
2019-08-19 17:58:43 +09:00
|
|
|
# modname and part-of-module are set to make c_flags define proper module flags
|
2019-08-15 01:06:23 +09:00
|
|
|
modname = $(notdir $(@:.mod.o=))
|
2019-08-19 17:58:43 +09:00
|
|
|
part-of-module = y
|
2019-08-15 01:06:23 +09:00
|
|
|
|
|
|
|
|
quiet_cmd_cc_o_c = CC [M] $@
|
2019-04-25 16:09:05 -07:00
|
|
|
cmd_cc_o_c = \
|
|
|
|
|
$(CC) $(filter-out $(CC_FLAGS_CFI) $(CC_FLAGS_FTRACE), \
|
|
|
|
|
$(c_flags)) -c -o $@ $<
|
2019-08-15 01:06:23 +09:00
|
|
|
|
|
|
|
|
%.mod.o: %.mod.c FORCE
|
|
|
|
|
$(call if_changed_dep,cc_o_c)
|
|
|
|
|
|
|
|
|
|
ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink)
|
|
|
|
|
|
FROMLIST: kbuild: add support for Clang LTO
This change adds build system support for Clang's Link Time
Optimization (LTO). With -flto, instead of ELF object files, Clang
produces LLVM bitcode, which is compiled into native code at link
time, allowing the final binary to be optimized globally. For more
details, see:
https://llvm.org/docs/LinkTimeOptimization.html
The Kconfig option CONFIG_LTO_CLANG is implemented as a choice,
which defaults to LTO being disabled. To use LTO, the architecture
must select ARCH_SUPPORTS_LTO_CLANG and support:
- compiling with Clang,
- compiling all assembly code with Clang's integrated assembler,
- and linking with LLD.
While using CONFIG_LTO_CLANG_FULL results in the best runtime
performance, the compilation is not scalable in time or
memory. CONFIG_LTO_CLANG_THIN enables ThinLTO, which allows
parallel optimization and faster incremental builds. ThinLTO is
used by default if the architecture also selects
ARCH_SUPPORTS_LTO_CLANG_THIN:
https://clang.llvm.org/docs/ThinLTO.html
To enable LTO, LLVM tools must be used to handle bitcode files, by
passing LLVM=1 and LLVM_IAS=1 options to make:
$ make LLVM=1 LLVM_IAS=1 defconfig
$ scripts/config -e LTO_CLANG_THIN
$ make LLVM=1 LLVM_IAS=1
To prepare for LTO support with other compilers, common parts are
gated behind the CONFIG_LTO option, and LTO can be disabled for
specific files by filtering out CC_FLAGS_LTO.
Bug: 145210207
Change-Id: I85eb4523ea787e4f9884e12ed6301f876d0d888e
Link: https://lore.kernel.org/lkml/20201211184633.3213045-1-samitolvanen@google.com/
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
2020-03-06 14:14:03 -08:00
|
|
|
ifdef CONFIG_LTO_CLANG
|
|
|
|
|
# With CONFIG_LTO_CLANG, reuse the object file we compiled for modpost to
|
|
|
|
|
# avoid a second slow LTO link
|
|
|
|
|
prelink-ext := .lto
|
2020-04-13 16:10:13 -07:00
|
|
|
|
|
|
|
|
# ELF processing was skipped earlier because we didn't have native code,
|
|
|
|
|
# so let's now process the prelinked binary before we link the module.
|
|
|
|
|
|
|
|
|
|
ifdef CONFIG_STACK_VALIDATION
|
|
|
|
|
ifneq ($(SKIP_STACK_VALIDATION),1)
|
|
|
|
|
cmd_ld_ko_o += \
|
|
|
|
|
$(objtree)/tools/objtool/objtool $(objtool_args) \
|
|
|
|
|
$(@:.ko=$(prelink-ext).o);
|
|
|
|
|
|
|
|
|
|
endif # SKIP_STACK_VALIDATION
|
|
|
|
|
endif # CONFIG_STACK_VALIDATION
|
|
|
|
|
|
|
|
|
|
endif # CONFIG_LTO_CLANG
|
FROMLIST: kbuild: add support for Clang LTO
This change adds build system support for Clang's Link Time
Optimization (LTO). With -flto, instead of ELF object files, Clang
produces LLVM bitcode, which is compiled into native code at link
time, allowing the final binary to be optimized globally. For more
details, see:
https://llvm.org/docs/LinkTimeOptimization.html
The Kconfig option CONFIG_LTO_CLANG is implemented as a choice,
which defaults to LTO being disabled. To use LTO, the architecture
must select ARCH_SUPPORTS_LTO_CLANG and support:
- compiling with Clang,
- compiling all assembly code with Clang's integrated assembler,
- and linking with LLD.
While using CONFIG_LTO_CLANG_FULL results in the best runtime
performance, the compilation is not scalable in time or
memory. CONFIG_LTO_CLANG_THIN enables ThinLTO, which allows
parallel optimization and faster incremental builds. ThinLTO is
used by default if the architecture also selects
ARCH_SUPPORTS_LTO_CLANG_THIN:
https://clang.llvm.org/docs/ThinLTO.html
To enable LTO, LLVM tools must be used to handle bitcode files, by
passing LLVM=1 and LLVM_IAS=1 options to make:
$ make LLVM=1 LLVM_IAS=1 defconfig
$ scripts/config -e LTO_CLANG_THIN
$ make LLVM=1 LLVM_IAS=1
To prepare for LTO support with other compilers, common parts are
gated behind the CONFIG_LTO option, and LTO can be disabled for
specific files by filtering out CC_FLAGS_LTO.
Bug: 145210207
Change-Id: I85eb4523ea787e4f9884e12ed6301f876d0d888e
Link: https://lore.kernel.org/lkml/20201211184633.3213045-1-samitolvanen@google.com/
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
2020-03-06 14:14:03 -08:00
|
|
|
|
2019-08-15 01:06:23 +09:00
|
|
|
quiet_cmd_ld_ko_o = LD [M] $@
|
2020-04-13 16:10:13 -07:00
|
|
|
cmd_ld_ko_o += \
|
2019-08-15 01:06:23 +09:00
|
|
|
$(LD) -r $(KBUILD_LDFLAGS) \
|
|
|
|
|
$(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \
|
2020-09-08 13:27:08 +09:00
|
|
|
-T scripts/module.lds -o $@ $(filter %.o, $^); \
|
2019-08-15 01:06:23 +09:00
|
|
|
$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
|
|
|
|
|
|
2021-04-26 17:13:46 -07:00
|
|
|
ifdef CONFIG_CFI_CLANG
|
|
|
|
|
# LLVM can drops jump table symbols from the final binary. Add them
|
|
|
|
|
# back to make stack traces and other symbol output readable.
|
|
|
|
|
cmd_ld_ko_o += ; \
|
|
|
|
|
$(srctree)/scripts/generate_cfi_kallsyms.pl --module \
|
|
|
|
|
$@ > $(@:.ko=.lds); \
|
|
|
|
|
if [ -s $(@:.ko=.lds) ]; then \
|
|
|
|
|
$(LD) -r $(KBUILD_LDFLAGS) \
|
|
|
|
|
$(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \
|
|
|
|
|
-T $(@:.ko=.lds) \
|
|
|
|
|
-o $(@:.ko=.tmp.ko) $@; \
|
|
|
|
|
mv -f $(@:.ko=.tmp.ko) $@; \
|
|
|
|
|
else \
|
|
|
|
|
rm -f $(@:.ko=.lds); \
|
|
|
|
|
fi
|
|
|
|
|
endif
|
|
|
|
|
|
FROMLIST: kbuild: add support for Clang LTO
This change adds build system support for Clang's Link Time
Optimization (LTO). With -flto, instead of ELF object files, Clang
produces LLVM bitcode, which is compiled into native code at link
time, allowing the final binary to be optimized globally. For more
details, see:
https://llvm.org/docs/LinkTimeOptimization.html
The Kconfig option CONFIG_LTO_CLANG is implemented as a choice,
which defaults to LTO being disabled. To use LTO, the architecture
must select ARCH_SUPPORTS_LTO_CLANG and support:
- compiling with Clang,
- compiling all assembly code with Clang's integrated assembler,
- and linking with LLD.
While using CONFIG_LTO_CLANG_FULL results in the best runtime
performance, the compilation is not scalable in time or
memory. CONFIG_LTO_CLANG_THIN enables ThinLTO, which allows
parallel optimization and faster incremental builds. ThinLTO is
used by default if the architecture also selects
ARCH_SUPPORTS_LTO_CLANG_THIN:
https://clang.llvm.org/docs/ThinLTO.html
To enable LTO, LLVM tools must be used to handle bitcode files, by
passing LLVM=1 and LLVM_IAS=1 options to make:
$ make LLVM=1 LLVM_IAS=1 defconfig
$ scripts/config -e LTO_CLANG_THIN
$ make LLVM=1 LLVM_IAS=1
To prepare for LTO support with other compilers, common parts are
gated behind the CONFIG_LTO option, and LTO can be disabled for
specific files by filtering out CC_FLAGS_LTO.
Bug: 145210207
Change-Id: I85eb4523ea787e4f9884e12ed6301f876d0d888e
Link: https://lore.kernel.org/lkml/20201211184633.3213045-1-samitolvanen@google.com/
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
2020-03-06 14:14:03 -08:00
|
|
|
$(modules): %.ko: %$(prelink-ext).o %.mod.o scripts/module.lds FORCE
|
2019-08-15 01:06:23 +09:00
|
|
|
+$(call if_changed,ld_ko_o)
|
|
|
|
|
|
|
|
|
|
targets += $(modules) $(modules:.ko=.mod.o)
|
|
|
|
|
|
|
|
|
|
# Add FORCE to the prequisites of a target to force it to be always rebuilt.
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
PHONY += FORCE
|
|
|
|
|
FORCE:
|
|
|
|
|
|
|
|
|
|
# Read all saved command lines and dependencies for the $(targets) we
|
|
|
|
|
# may be building above, using $(if_changed{,_dep}). As an
|
|
|
|
|
# optimization, we don't need to read them if the target does not
|
|
|
|
|
# exist, we will rebuild anyway in that case.
|
|
|
|
|
|
|
|
|
|
existing-targets := $(wildcard $(sort $(targets)))
|
|
|
|
|
|
|
|
|
|
-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
|
|
|
|
|
|
|
|
|
|
.PHONY: $(PHONY)
|