Arthur Heymans has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/84003?usp=email )
Change subject: Add initial LTO support ......................................................................
Add initial LTO support
This will not succeed in compiling on all target and compiler combinations but at least gets the ball rolling.
Change-Id: Ieb9204777fd349542744a8946e2207731c37969c Signed-off-by: Arthur Heymans arthur@aheymans.xyz --- M Makefile.mk M src/Kconfig 2 files changed, 18 insertions(+), 3 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/03/84003/1
diff --git a/Makefile.mk b/Makefile.mk index 9efef49..ba300dc 100644 --- a/Makefile.mk +++ b/Makefile.mk @@ -373,7 +373,7 @@ cbfs-files-processor-struct= \ $(eval $(2): $(1) $(obj)/build.h $(obj)/fmap_config.h $(KCONFIG_AUTOHEADER); \ printf " CC+STRIP $(1)\n"; \ - $(CC_ramstage) -MMD $(CPPFLAGS_ramstage) $(CFLAGS_ramstage) --param asan-globals=0 $$(ramstage-c-ccopts) -include $(KCONFIG_AUTOHEADER) -MT $(2) -o $(2).tmp -c $(1) && \ + $(CC_ramstage) -MMD $(CPPFLAGS_ramstage) $(CFLAGS_ramstage) -fno-lto --param asan-globals=0 $$(ramstage-c-ccopts) -include $(KCONFIG_AUTOHEADER) -MT $(2) -o $(2).tmp -c $(1) && \ $(OBJCOPY_ramstage) -O binary --only-section='.*data*' --only-section='.*bss*' \ --set-section-flags .*bss*=alloc,contents,load $(2).tmp $(2); \ rm -f $(2).tmp) \ @@ -547,6 +547,10 @@ endif endif
+ifeq ($(CONFIG_LTO),y) +CFLAGS_common += -flto +endif + ADAFLAGS_common += -gnatp ADAFLAGS_common += -Wuninitialized ADAFLAGS_common += -Wall @@ -1316,11 +1320,15 @@
define link_stage # $1 stage name - +ifeq ($(CONFIG_LTO),y) +$$(objcbfs)/$(1).debug: $$$$($(1)-libs) $$$$($(1)-objs) + @printf " LINK $$(subst $$(obj)/,,$$(@))\n" + $$(CC_$(1)) $$(CPPFLAGS_$(1)) -nostdlib -nostartfiles $$(LDFLAGS_$(1):%=-Wl,%) -o $$@ -L$$(obj) $$(COMPILER_RT_FLAGS_$(1):%=-Wl,%) -Wl,--whole-archive -Wl,--start-group $$(filter-out %.ld,$$($(1)-objs)) $$($(1)-libs) -Wl,--no-whole-archive $$(COMPILER_RT_$(1)) -Wl,--end-group -T $(call src-to-obj,$(1),$(CONFIG_MEMLAYOUT_LD_FILE)) +else $$(objcbfs)/$(1).debug: $$$$($(1)-libs) $$$$($(1)-objs) @printf " LINK $$(subst $$(obj)/,,$$(@))\n" $$(LD_$(1)) $$(LDFLAGS_$(1)) -o $$@ -L$$(obj) $$(COMPILER_RT_FLAGS_$(1)) --whole-archive --start-group $$(filter-out %.ld,$$($(1)-objs)) $$($(1)-libs) --no-whole-archive $$(COMPILER_RT_$(1)) --end-group -T $(call src-to-obj,$(1),$(CONFIG_MEMLAYOUT_LD_FILE)) - +endif endef
ifeq ($(CONFIG_SEPARATE_ROMSTAGE),y) diff --git a/src/Kconfig b/src/Kconfig index b6dc67f..b796c97 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -116,6 +116,13 @@
For details see https://ccache.samba.org.
+config LTO + bool "Use link time optimization (LTO) (experimantal)" + default n + help + Compile with link time optimization. This can often decrease the + final binary size, but may increase compilation time. + config IWYU bool "Test platform with include-what-you-use" help