[RFC PATCH u-boot 01/12] build: use thin archives instead of incremental linking

Bin Meng bmeng.cn at gmail.com
Thu Mar 4 11:57:11 CET 2021


Hi Marek,

On Wed, Mar 3, 2021 at 12:13 PM Marek Behún <marek.behun at nic.cz> wrote:
>
> Using thin archives instead of incremental linking
> - saves disk space
> - works better with dead code elimination
> - prepares for potential LTO

The commit message is a little bit confusing. This commit actually
does 2 things: don't do incremental linking (using --whole-archive),
and use thin archive (passing T to ar). I believe they are for
different purposes, so we cannot say "using thin archives instead of
incremental linking".

>
> Linux does this for some time now, do this also in U-Boot.
>
> Signed-off-by: Marek Behún <marek.behun at nic.cz>
> ---
>  Makefile               | 2 +-
>  arch/sandbox/config.mk | 6 +++---
>  scripts/Makefile.build | 5 ++---
>  scripts/Makefile.spl   | 7 +++----
>  4 files changed, 9 insertions(+), 11 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index 6cdd3677eb..33d0b80de8 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1750,7 +1750,7 @@ ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(ARCH)/Makefile.postlink)
>  quiet_cmd_u-boot__ ?= LD      $@
>        cmd_u-boot__ ?= $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_u-boot) -o $@ \
>        -T u-boot.lds $(u-boot-init)                             \
> -      --start-group $(u-boot-main) --end-group                 \
> +      --whole-archive $(u-boot-main) --no-whole-archive        \
>        $(PLATFORM_LIBS) -Map u-boot.map;                        \
>        $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
>
> diff --git a/arch/sandbox/config.mk b/arch/sandbox/config.mk
> index 189e9c2b0c..ebbb094744 100644
> --- a/arch/sandbox/config.mk
> +++ b/arch/sandbox/config.mk
> @@ -17,13 +17,13 @@ PLATFORM_CPPFLAGS += $(shell $(SDL_CONFIG) --cflags)
>  endif
>
>  cmd_u-boot__ = $(CC) -o $@ -Wl,-T u-boot.lds $(u-boot-init) \
> -       -Wl,--start-group $(u-boot-main) -Wl,--end-group \
> +       -Wl,--whole-archive $(u-boot-main) -Wl,--no-whole-archive \
>         $(PLATFORM_LIBS) -Wl,-Map -Wl,u-boot.map
>
>  cmd_u-boot-spl = (cd $(obj) && $(CC) -o $(SPL_BIN) -Wl,-T u-boot-spl.lds \
>         $(patsubst $(obj)/%,%,$(u-boot-spl-init)) \
> -       -Wl,--start-group $(patsubst $(obj)/%,%,$(u-boot-spl-main)) \
> -       $(patsubst $(obj)/%,%,$(u-boot-spl-platdata)) -Wl,--end-group \
> +       -Wl,--whole-archive $(patsubst $(obj)/%,%,$(u-boot-spl-main)) -Wl,--no-whole-archive \
> +       -Wl,--start-group $(patsubst $(obj)/%,%,$(u-boot-spl-platdata)) -Wl,--end-group \

u-boot-spl-platdata is still within --start-group, --end-group, is
this intentional?

>         $(PLATFORM_LIBS) -Wl,-Map -Wl,u-boot-spl.map -Wl,--gc-sections)
>
>  CONFIG_ARCH_DEVICE_TREE := sandbox
> diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> index 705a886cb9..3659d0af1b 100644
> --- a/scripts/Makefile.build
> +++ b/scripts/Makefile.build
> @@ -331,11 +331,10 @@ $(sort $(subdir-obj-y)): $(subdir-ym) ;
>  # Rule to compile a set of .o files into one .o file
>  #
>  ifdef builtin-target
> -quiet_cmd_link_o_target = LD      $@
> +quiet_cmd_link_o_target = AR      $@
>  # If the list of objects to link is empty, just create an empty built-in.o
>  cmd_link_o_target = $(if $(strip $(obj-y)),\
> -                     $(LD) $(ld_flags) -r -o $@ $(filter $(obj-y), $^) \
> -                     $(cmd_secanalysis),\
> +                     rm -f $@; $(AR) cDPrsT $@ $(filter $(obj-y), $^), \

Is P required to make everything work?

>                       rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) $@)
>
>  $(builtin-target): $(obj-y) FORCE
> diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl
> index ea4e045769..f9faf804de 100644
> --- a/scripts/Makefile.spl
> +++ b/scripts/Makefile.spl
> @@ -421,10 +421,9 @@ $(obj)/$(SPL_BIN).sym: $(obj)/$(SPL_BIN) FORCE
>  # May be overridden by arch/$(ARCH)/config.mk
>  quiet_cmd_u-boot-spl ?= LD      $@
>        cmd_u-boot-spl ?= (cd $(obj) && $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_$(@F)) \
> -                      $(patsubst $(obj)/%,%,$(u-boot-spl-init)) --start-group \
> -                      $(patsubst $(obj)/%,%,$(u-boot-spl-main))  \
> -                      $(patsubst $(obj)/%,%,$(u-boot-spl-platdata)) \
> -                      --end-group \
> +                      $(patsubst $(obj)/%,%,$(u-boot-spl-init)) \
> +                      --whole-archive $(patsubst $(obj)/%,%,$(u-boot-spl-main)) --no-whole-archive \
> +                      --start-group $(patsubst $(obj)/%,%,$(u-boot-spl-platdata)) --end-group \
>                        $(PLATFORM_LIBS) -Map $(SPL_BIN).map -o $(SPL_BIN))
>
>  $(obj)/$(SPL_BIN): $(u-boot-spl-platdata) $(u-boot-spl-init) \
> --

Regards,
Bin


More information about the U-Boot mailing list