Commit 026f9cf24f3c9d30c47c42bac622a64338caf596

Authored by Masahiro Yamada
Committed by Tom Rini
1 parent a0a15b441c

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 <yamada.m@jp.panasonic.com>
Reported-by: Simon Glass <sjg@chromium.org>
Acked-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org> [on Sandbox]
Tested-by: Stephen Warren <swarren@nvidia.com> [on Tegra]

Showing 8 changed files with 44 additions and 31 deletions Side-by-side Diff

... ... @@ -358,13 +358,13 @@
358 358 UBOOTVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
359 359  
360 360 export VERSION PATCHLEVEL SUBLEVEL UBOOTRELEASE UBOOTVERSION
361   -export ARCH CPU BOARD VENDOR SOC
  361 +export ARCH CPU BOARD VENDOR SOC CPUDIR BOARDDIR
362 362 export CONFIG_SHELL HOSTCC HOSTCFLAGS HOSTLDFLAGS CROSS_COMPILE AS LD CC
363 363 export CPP AR NM LDR STRIP OBJCOPY OBJDUMP
364 364 export MAKE AWK
365 365 export DTC CHECK CHECKFLAGS
366 366  
367   -export KBUILD_CPPFLAGS NOSTDINC_FLAGS UBOOTINCLUDE
  367 +export KBUILD_CPPFLAGS NOSTDINC_FLAGS UBOOTINCLUDE OBJCOPYFLAGS LDFLAGS
368 368 export KBUILD_CFLAGS KBUILD_AFLAGS
369 369  
370 370 # When compiling out-of-tree modules, put MODVERDIR in the module
... ... @@ -567,7 +567,8 @@
567 567 CHECKFLAGS += $(NOSTDINC_FLAGS)
568 568  
569 569 # FIX ME
570   -cpp_flags := $(KBUILD_CPPFLAGS) $(CPPFLAGS) $(UBOOTINCLUDE) $(NOSTDINC_FLAGS)
  570 +cpp_flags := $(KBUILD_CPPFLAGS) $(PLATFORM_CPPFLAGS) $(UBOOTINCLUDE) \
  571 + $(NOSTDINC_FLAGS)
571 572 c_flags := $(KBUILD_CFLAGS) $(cpp_flags)
572 573  
573 574 #########################################################################
arch/blackfin/config.mk
... ... @@ -43,6 +43,7 @@
43 43 endif
44 44  
45 45 SYM_PREFIX = _
  46 +export SYM_PREFIX
46 47  
47 48 LDR_FLAGS-y :=
48 49 LDR_FLAGS-$(CONFIG_BFIN_BOOTROM_USES_EVT1) += -J
arch/sparc/config.mk
... ... @@ -9,6 +9,8 @@
9 9 CROSS_COMPILE := sparc-elf-
10 10 endif
11 11  
  12 +gcclibdir := $(shell dirname `$(CC) -print-libgcc-file-name`)
  13 +
12 14 CONFIG_STANDALONE_LOAD_ADDR ?= 0x00000000 -L $(gcclibdir) \
13 15 -T $(srctree)/examples/standalone/sparc.lds
14 16  
... ... @@ -6,11 +6,18 @@
6 6 #
7 7 #########################################################################
8 8  
9   -# clean the slate ...
10   -PLATFORM_RELFLAGS =
11   -PLATFORM_CPPFLAGS =
12   -PLATFORM_LDFLAGS =
13   -
  9 +# This file is included from ./Makefile and spl/Makefile.
  10 +# Clean the state to avoid the same flags added twice.
  11 +#
  12 +# (Tegra needs different flags for SPL.
  13 +# That's the reason why this file must be included from spl/Makefile too.
  14 +# If we did not have Tegra SoCs, build system would be much simpler...)
  15 +PLATFORM_RELFLAGS :=
  16 +PLATFORM_CPPFLAGS :=
  17 +PLATFORM_LDFLAGS :=
  18 +LDFLAGS :=
  19 +LDFLAGS_FINAL :=
  20 +OBJCOPYFLAGS :=
14 21 #########################################################################
15 22  
16 23 # Some architecture config.mk files need to know what CPUDIR is set to,
17 24  
18 25  
... ... @@ -41,13 +48,18 @@
41 48  
42 49 #########################################################################
43 50  
44   -RELFLAGS= $(PLATFORM_RELFLAGS)
  51 +RELFLAGS := $(PLATFORM_RELFLAGS)
45 52  
46 53 OBJCOPYFLAGS += --gap-fill=0xff
47 54  
48   -CPPFLAGS = $(RELFLAGS)
49   -CPPFLAGS += -pipe $(PLATFORM_CPPFLAGS)
  55 +PLATFORM_CPPFLAGS += $(RELFLAGS)
  56 +PLATFORM_CPPFLAGS += -pipe
50 57  
51 58 LDFLAGS += $(PLATFORM_LDFLAGS)
52 59 LDFLAGS_FINAL += -Bstatic
  60 +
  61 +export PLATFORM_CPPFLAGS
  62 +export RELFLAGS
  63 +export LDFLAGS_FINAL
  64 +export CONFIG_STANDALONE_LOAD_ADDR
examples/standalone/Makefile
... ... @@ -44,9 +44,8 @@
44 44 # relocatable executable. The relocation data is not needed, and
45 45 # also causes the entry point of the standalone application to be
46 46 # inconsistent.
47   -ifeq ($(ARCH),powerpc)
48   -# FIX ME
49   -CPPFLAGS := $(filter-out $(RELFLAGS), $(CPPFLAGS))
  47 +ifeq ($(CONFIG_PPC),y)
  48 +PLATFORM_CPPFLAGS := $(filter-out $(RELFLAGS),$(PLATFORM_CPPFLAGS))
50 49 endif
51 50  
52 51 # We don't want gcc reordering functions if possible. This ensures that an
scripts/Makefile.build
... ... @@ -55,11 +55,6 @@
55 55  
56 56 include scripts/Kbuild.include
57 57  
58   -# Added for U-Boot
59   -# We must include config.mk after Kbuild.include
60   -# so that some config.mk can use cc-option.
61   -include config.mk
62   -
63 58 # For backward compatibility check that these variables do not change
64 59 save-cflags := $(CFLAGS)
65 60  
... ... @@ -67,6 +62,11 @@
67 62 kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
68 63 kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile)
69 64 include $(kbuild-file)
  65 +
  66 +# Added for U-Boot
  67 +asflags-y += $(PLATFORM_CPPFLAGS)
  68 +ccflags-y += $(PLATFORM_CPPFLAGS)
  69 +cppflags-y += $(PLATFORM_CPPFLAGS)
70 70  
71 71 # If the save-* variables changed error out
72 72 ifeq ($(KBUILD_NOPEDANTIC),)
scripts/Makefile.lib
... ... @@ -101,13 +101,12 @@
101 101 modname_flags = $(if $(filter 1,$(words $(modname))),\
102 102 -D"KBUILD_MODNAME=KBUILD_STR($(call name-fix,$(modname)))")
103 103  
104   -# U-Boot also uses $(CPPFLAGS)
105   -orig_c_flags = $(KBUILD_CPPFLAGS) $(CPPFLAGS) $(KBUILD_CFLAGS) $(KBUILD_SUBDIR_CCFLAGS) \
  104 +orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(KBUILD_SUBDIR_CCFLAGS) \
106 105 $(ccflags-y) $(CFLAGS_$(basetarget).o)
107 106 _c_flags = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags))
108   -_a_flags = $(KBUILD_CPPFLAGS) $(CPPFLAGS) $(KBUILD_AFLAGS) $(KBUILD_SUBDIR_ASFLAGS) \
  107 +_a_flags = $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(KBUILD_SUBDIR_ASFLAGS) \
109 108 $(asflags-y) $(AFLAGS_$(basetarget).o)
110   -_cpp_flags = $(KBUILD_CPPFLAGS) $(CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F))
  109 +_cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F))
111 110  
112 111 #
113 112 # Enable gcov profiling flags for a file, directory or for all files depending
... ... @@ -29,10 +29,6 @@
29 29 KBUILD_CPPFLAGS += -DCONFIG_TPL_BUILD
30 30 endif
31 31  
32   -# Enable garbage collection of un-used sections for SPL
33   -KBUILD_CFLAGS += -ffunction-sections -fdata-sections
34   -LDFLAGS_FINAL += --gc-sections
35   -
36 32 ifeq ($(CONFIG_TPL_BUILD),y)
37 33 export CONFIG_TPL_BUILD
38 34 SPL_BIN := u-boot-tpl
39 35  
... ... @@ -50,8 +46,14 @@
50 46  
51 47 include $(TOPDIR)/config.mk
52 48  
  49 +# Enable garbage collection of un-used sections for SPL
  50 +KBUILD_CFLAGS += -ffunction-sections -fdata-sections
  51 +LDFLAGS_FINAL += --gc-sections
  52 +
53 53 # FIX ME
54   -c_flags := $(KBUILD_CFLAGS) $(KBUILD_CPPFLAGS) $(CPPFLAGS) $(UBOOTINCLUDE) $(NOSTDINC_FLAGS)
  54 +cpp_flags := $(KBUILD_CPPFLAGS) $(PLATFORM_CPPFLAGS) $(UBOOTINCLUDE) \
  55 + $(NOSTDINC_FLAGS)
  56 +c_flags := $(KBUILD_CFLAGS) $(cpp_flags)
55 57  
56 58 # Auto-generate the spl-autoconf.mk file (which is included by all makefiles for SPL)
57 59 quiet_cmd_autoconf = GEN $@
... ... @@ -227,9 +229,6 @@
227 229 PHONY += $(u-boot-spl-dirs)
228 230 $(u-boot-spl-dirs):
229 231 $(Q)$(MAKE) $(build)=$@
230   -
231   -# FIX ME
232   -cpp_flags := $(KBUILD_CPPFLAGS) $(CPPFLAGS) $(UBOOTINCLUDE) $(NOSTDINC_FLAGS)
233 232  
234 233 quiet_cmd_cpp_lds = LDS $@
235 234 cmd_cpp_lds = $(CPP) $(cpp_flags) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ \