[PATCH v2 1/1] sandbox: eliminate unused functions from binaries

Tom Rini trini at konsulko.com
Mon Oct 23 19:02:58 CEST 2023


On Mon, Oct 23, 2023 at 01:37:27AM +0200, Heinrich Schuchardt wrote:
> The sandbox should closely mimic other architectures.
> 
> Place each function or data in a separate section and let the linker
> eliminate unused ones. This will reduce the binary size.
> 
> In the linker script mark that u_boot_sandbox_getopt are to be kept.
> 
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
> ---
> v2:
> 	mark _u_boot_sandbox_getopt secitons a KEEP()
> ---
>  arch/sandbox/config.mk      | 4 +++-
>  arch/sandbox/cpu/u-boot.lds | 6 +++---
>  2 files changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/sandbox/config.mk b/arch/sandbox/config.mk
> index 2d184c5f65..c02f0229c2 100644
> --- a/arch/sandbox/config.mk
> +++ b/arch/sandbox/config.mk
> @@ -2,7 +2,7 @@
>  # Copyright (c) 2011 The Chromium OS Authors.
>  
>  PLATFORM_CPPFLAGS += -D__SANDBOX__ -U_FORTIFY_SOURCE
> -PLATFORM_CPPFLAGS += -fPIC
> +PLATFORM_CPPFLAGS += -fPIC -ffunction-sections -fdata-sections
>  PLATFORM_LIBS += -lrt
>  SDL_CONFIG ?= sdl2-config
>  
> @@ -26,6 +26,7 @@ cmd_u-boot__ = $(CC) -o $@ -Wl,-T u-boot.lds $(u-boot-init) \
>  	$(KBUILD_LDFLAGS:%=-Wl,%) \
>  	$(SANITIZERS) \
>  	$(LTO_FINAL_LDFLAGS) \
> +	-Wl,--gc-section \
>  	-Wl,--whole-archive \
>  		$(u-boot-main) \
>  		$(u-boot-keep-syms-lto) \
> @@ -37,6 +38,7 @@ cmd_u-boot-spl = (cd $(obj) && $(CC) -o $(SPL_BIN) -Wl,-T u-boot-spl.lds \
>  	$(SANITIZERS) \
>  	$(LTO_FINAL_LDFLAGS) \
>  	$(patsubst $(obj)/%,%,$(u-boot-spl-init)) \
> +	-Wl,--gc-section \
>  	-Wl,--whole-archive \
>  		$(patsubst $(obj)/%,%,$(u-boot-spl-main)) \
>  		$(patsubst $(obj)/%,%,$(u-boot-spl-platdata)) \

There's already a call to --gc-sections for u-boot-spl on sandbox (in
the last line of the link command).  We should probably move the main
u-boot call there too, for consistency.

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20231023/447f2193/attachment.sig>


More information about the U-Boot mailing list