From 026f9cf24f3c9d30c47c42bac622a64338caf596 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 5 Mar 2014 16:59:40 +0900 Subject: [PATCH] kbuild: improve Kbuild speed Kbuild brought about many advantages for us but a significant performance regression was reported by Simon Glass. After some discussions and analysis, it turned out its main cause is in $(call cc-option,...). Historically, U-Boot parses all config.mk (arch/*/config.mk and board/*/config.mk) every time descending into subdirectories. That means cc-options are evaluated over and over again. $(call cc-option,...) is useful but costly. So we want to evaluate them only in ./Makefile and spl/Makefile and export compiler flags. This commit changes the build system as follows: - Modify scripts/Makefile.build to not include config.mk Instead, add $(PLATFORM_CPPFLAGS) to asflags-y, ccflags-y, cppflags-y. - Export many variables Going forward, Kbuild will not parse config.mk files when it descends into subdirectories. If we want to set variables in config.mk and use them in subdirectories, they must be exported. This is the list of variables to get exported: PLATFORM_CPPFLAGS CPUDIR BOARDDIR OBJCOPYFLAGS LDFLAGS LDFLAGS_FINAL (used in nand_spl/board/*/*/Makefile) CONFIG_STANDALONE_LOAD_ADDR (used in examples/standalone/Makefile) SYM_PREFIX (used in examples/standalone/Makefile) RELFLAGS (used in examples/standalone/Makefile) - Delete CPPFLAGS This variable has been replaced with PLATFORM_CPPFLAGS - Copy gcclibdir from example/standalone/Makefile to arch/sparc/config.mk The reference in CONFIG_STANDALONE_LOAD_ADDR must be resolved before it is exported. Signed-off-by: Masahiro Yamada Reported-by: Simon Glass Acked-by: Simon Glass Tested-by: Simon Glass [on Sandbox] Tested-by: Stephen Warren [on Tegra] --- Makefile | 7 ++++--- arch/blackfin/config.mk | 1 + arch/sparc/config.mk | 2 ++ config.mk | 28 ++++++++++++++++++++-------- examples/standalone/Makefile | 5 ++--- scripts/Makefile.build | 10 +++++----- scripts/Makefile.lib | 7 +++---- spl/Makefile | 15 +++++++-------- 8 files changed, 44 insertions(+), 31 deletions(-) diff --git a/Makefile b/Makefile index 4e61ae914c..c03a1b4ac7 100644 --- a/Makefile +++ b/Makefile @@ -358,13 +358,13 @@ UBOOTRELEASE = $(shell cat include/config/uboot.release 2> /dev/null) UBOOTVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION) export VERSION PATCHLEVEL SUBLEVEL UBOOTRELEASE UBOOTVERSION -export ARCH CPU BOARD VENDOR SOC +export ARCH CPU BOARD VENDOR SOC CPUDIR BOARDDIR export CONFIG_SHELL HOSTCC HOSTCFLAGS HOSTLDFLAGS CROSS_COMPILE AS LD CC export CPP AR NM LDR STRIP OBJCOPY OBJDUMP export MAKE AWK export DTC CHECK CHECKFLAGS -export KBUILD_CPPFLAGS NOSTDINC_FLAGS UBOOTINCLUDE +export KBUILD_CPPFLAGS NOSTDINC_FLAGS UBOOTINCLUDE OBJCOPYFLAGS LDFLAGS export KBUILD_CFLAGS KBUILD_AFLAGS # When compiling out-of-tree modules, put MODVERDIR in the module @@ -567,7 +567,8 @@ NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include) CHECKFLAGS += $(NOSTDINC_FLAGS) # FIX ME -cpp_flags := $(KBUILD_CPPFLAGS) $(CPPFLAGS) $(UBOOTINCLUDE) $(NOSTDINC_FLAGS) +cpp_flags := $(KBUILD_CPPFLAGS) $(PLATFORM_CPPFLAGS) $(UBOOTINCLUDE) \ + $(NOSTDINC_FLAGS) c_flags := $(KBUILD_CFLAGS) $(cpp_flags) ######################################################################### diff --git a/arch/blackfin/config.mk b/arch/blackfin/config.mk index adc97125b5..fcaa44f1d6 100644 --- a/arch/blackfin/config.mk +++ b/arch/blackfin/config.mk @@ -43,6 +43,7 @@ CREATE_LDR_ENV = endif SYM_PREFIX = _ +export SYM_PREFIX LDR_FLAGS-y := LDR_FLAGS-$(CONFIG_BFIN_BOOTROM_USES_EVT1) += -J diff --git a/arch/sparc/config.mk b/arch/sparc/config.mk index 6dbf20f537..be59f58190 100644 --- a/arch/sparc/config.mk +++ b/arch/sparc/config.mk @@ -9,6 +9,8 @@ ifeq ($(CROSS_COMPILE),) CROSS_COMPILE := sparc-elf- endif +gcclibdir := $(shell dirname `$(CC) -print-libgcc-file-name`) + CONFIG_STANDALONE_LOAD_ADDR ?= 0x00000000 -L $(gcclibdir) \ -T $(srctree)/examples/standalone/sparc.lds diff --git a/config.mk b/config.mk index af25c115cc..4657577f9d 100644 --- a/config.mk +++ b/config.mk @@ -6,11 +6,18 @@ # ######################################################################### -# clean the slate ... -PLATFORM_RELFLAGS = -PLATFORM_CPPFLAGS = -PLATFORM_LDFLAGS = - +# This file is included from ./Makefile and spl/Makefile. +# Clean the state to avoid the same flags added twice. +# +# (Tegra needs different flags for SPL. +# That's the reason why this file must be included from spl/Makefile too. +# If we did not have Tegra SoCs, build system would be much simpler...) +PLATFORM_RELFLAGS := +PLATFORM_CPPFLAGS := +PLATFORM_LDFLAGS := +LDFLAGS := +LDFLAGS_FINAL := +OBJCOPYFLAGS := ######################################################################### # Some architecture config.mk files need to know what CPUDIR is set to, @@ -41,12 +48,17 @@ endif ######################################################################### -RELFLAGS= $(PLATFORM_RELFLAGS) +RELFLAGS := $(PLATFORM_RELFLAGS) OBJCOPYFLAGS += --gap-fill=0xff -CPPFLAGS = $(RELFLAGS) -CPPFLAGS += -pipe $(PLATFORM_CPPFLAGS) +PLATFORM_CPPFLAGS += $(RELFLAGS) +PLATFORM_CPPFLAGS += -pipe LDFLAGS += $(PLATFORM_LDFLAGS) LDFLAGS_FINAL += -Bstatic + +export PLATFORM_CPPFLAGS +export RELFLAGS +export LDFLAGS_FINAL +export CONFIG_STANDALONE_LOAD_ADDR diff --git a/examples/standalone/Makefile b/examples/standalone/Makefile index 5b227cd898..7e0e5b71b6 100644 --- a/examples/standalone/Makefile +++ b/examples/standalone/Makefile @@ -44,9 +44,8 @@ gcclibdir := $(shell dirname `$(CC) -print-libgcc-file-name`) # relocatable executable. The relocation data is not needed, and # also causes the entry point of the standalone application to be # inconsistent. -ifeq ($(ARCH),powerpc) -# FIX ME -CPPFLAGS := $(filter-out $(RELFLAGS), $(CPPFLAGS)) +ifeq ($(CONFIG_PPC),y) +PLATFORM_CPPFLAGS := $(filter-out $(RELFLAGS),$(PLATFORM_CPPFLAGS)) endif # We don't want gcc reordering functions if possible. This ensures that an diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 59361f4d7a..36346fd161 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -55,11 +55,6 @@ endif include scripts/Kbuild.include -# Added for U-Boot -# We must include config.mk after Kbuild.include -# so that some config.mk can use cc-option. -include config.mk - # For backward compatibility check that these variables do not change save-cflags := $(CFLAGS) @@ -68,6 +63,11 @@ kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src)) kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile) include $(kbuild-file) +# Added for U-Boot +asflags-y += $(PLATFORM_CPPFLAGS) +ccflags-y += $(PLATFORM_CPPFLAGS) +cppflags-y += $(PLATFORM_CPPFLAGS) + # If the save-* variables changed error out ifeq ($(KBUILD_NOPEDANTIC),) ifneq ("$(save-cflags)","$(CFLAGS)") diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 02b17b1057..d568fde2cc 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -101,13 +101,12 @@ basename_flags = -D"KBUILD_BASENAME=KBUILD_STR($(call name-fix,$(basetarget)))" modname_flags = $(if $(filter 1,$(words $(modname))),\ -D"KBUILD_MODNAME=KBUILD_STR($(call name-fix,$(modname)))") -# U-Boot also uses $(CPPFLAGS) -orig_c_flags = $(KBUILD_CPPFLAGS) $(CPPFLAGS) $(KBUILD_CFLAGS) $(KBUILD_SUBDIR_CCFLAGS) \ +orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(KBUILD_SUBDIR_CCFLAGS) \ $(ccflags-y) $(CFLAGS_$(basetarget).o) _c_flags = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags)) -_a_flags = $(KBUILD_CPPFLAGS) $(CPPFLAGS) $(KBUILD_AFLAGS) $(KBUILD_SUBDIR_ASFLAGS) \ +_a_flags = $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(KBUILD_SUBDIR_ASFLAGS) \ $(asflags-y) $(AFLAGS_$(basetarget).o) -_cpp_flags = $(KBUILD_CPPFLAGS) $(CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F)) +_cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F)) # # Enable gcov profiling flags for a file, directory or for all files depending diff --git a/spl/Makefile b/spl/Makefile index e1a0601a02..bb3d3495e4 100644 --- a/spl/Makefile +++ b/spl/Makefile @@ -29,10 +29,6 @@ ifeq ($(CONFIG_TPL_BUILD),y) KBUILD_CPPFLAGS += -DCONFIG_TPL_BUILD endif -# Enable garbage collection of un-used sections for SPL -KBUILD_CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS_FINAL += --gc-sections - ifeq ($(CONFIG_TPL_BUILD),y) export CONFIG_TPL_BUILD SPL_BIN := u-boot-tpl @@ -50,8 +46,14 @@ endif include $(TOPDIR)/config.mk +# Enable garbage collection of un-used sections for SPL +KBUILD_CFLAGS += -ffunction-sections -fdata-sections +LDFLAGS_FINAL += --gc-sections + # FIX ME -c_flags := $(KBUILD_CFLAGS) $(KBUILD_CPPFLAGS) $(CPPFLAGS) $(UBOOTINCLUDE) $(NOSTDINC_FLAGS) +cpp_flags := $(KBUILD_CPPFLAGS) $(PLATFORM_CPPFLAGS) $(UBOOTINCLUDE) \ + $(NOSTDINC_FLAGS) +c_flags := $(KBUILD_CFLAGS) $(cpp_flags) # Auto-generate the spl-autoconf.mk file (which is included by all makefiles for SPL) quiet_cmd_autoconf = GEN $@ @@ -228,9 +230,6 @@ PHONY += $(u-boot-spl-dirs) $(u-boot-spl-dirs): $(Q)$(MAKE) $(build)=$@ -# FIX ME -cpp_flags := $(KBUILD_CPPFLAGS) $(CPPFLAGS) $(UBOOTINCLUDE) $(NOSTDINC_FLAGS) - quiet_cmd_cpp_lds = LDS $@ cmd_cpp_lds = $(CPP) $(cpp_flags) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ \ -x assembler-with-cpp -P -o $@ $< -- 2.25.1