]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
sandbox: eliminate unused functions from binaries
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Tue, 24 Oct 2023 06:30:47 +0000 (08:30 +0200)
committerTom Rini <trini@konsulko.com>
Fri, 3 Nov 2023 02:38:01 +0000 (22:38 -0400)
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@canonical.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
arch/sandbox/config.mk
arch/sandbox/cpu/u-boot.lds

index 2d184c5f652a21712f1c5a4d90230d8955fde8de..1d50991f8d24d3b815e0ffdd1301a8405254ef50 100644 (file)
@@ -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
 
@@ -30,7 +30,7 @@ cmd_u-boot__ = $(CC) -o $@ -Wl,-T u-boot.lds $(u-boot-init) \
                $(u-boot-main) \
                $(u-boot-keep-syms-lto) \
        -Wl,--no-whole-archive \
-       $(PLATFORM_LIBS) -Wl,-Map -Wl,u-boot.map
+       $(PLATFORM_LIBS) -Wl,-Map -Wl,u-boot.map -Wl,--gc-sections
 
 cmd_u-boot-spl = (cd $(obj) && $(CC) -o $(SPL_BIN) -Wl,-T u-boot-spl.lds \
        $(KBUILD_LDFLAGS:%=-Wl,%) \
index ba8dee50c7bd627cc0dc5d2fbf22f87831628fbc..52f13af3742f6b1dd7ba44f8b972ae5ced334abc 100644 (file)
@@ -15,7 +15,7 @@ SECTIONS
 
        _u_boot_sandbox_getopt : {
                *(_u_boot_sandbox_getopt_start)
-               *(_u_boot_sandbox_getopt)
+               KEEP(*(_u_boot_sandbox_getopt))
                *(_u_boot_sandbox_getopt_end)
        }