* [PATCH v3 1/1] sandbox: eliminate unused functions from binaries
@ 2023-10-24 6:30 Heinrich Schuchardt
2023-10-24 18:03 ` Simon Glass
2023-10-24 18:03 ` Tom Rini
0 siblings, 2 replies; 4+ messages in thread
From: Heinrich Schuchardt @ 2023-10-24 6:30 UTC (permalink / raw)
To: Simon Glass; +Cc: Tom Rini, u-boot, Heinrich Schuchardt
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>
---
v3:
avoid duplicate -Wl,--gc-sections
only use KEEP for unreferenced symbols
v2:
mark _u_boot_sandbox_getopt sections as KEEP()
---
arch/sandbox/config.mk | 4 ++--
arch/sandbox/cpu/u-boot.lds | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/sandbox/config.mk b/arch/sandbox/config.mk
index 2d184c5f65..1d50991f8d 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
@@ -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,%) \
diff --git a/arch/sandbox/cpu/u-boot.lds b/arch/sandbox/cpu/u-boot.lds
index ba8dee50c7..52f13af374 100644
--- a/arch/sandbox/cpu/u-boot.lds
+++ b/arch/sandbox/cpu/u-boot.lds
@@ -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)
}
--
2.40.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3 1/1] sandbox: eliminate unused functions from binaries
2023-10-24 6:30 [PATCH v3 1/1] sandbox: eliminate unused functions from binaries Heinrich Schuchardt
@ 2023-10-24 18:03 ` Simon Glass
2023-10-24 18:03 ` Tom Rini
1 sibling, 0 replies; 4+ messages in thread
From: Simon Glass @ 2023-10-24 18:03 UTC (permalink / raw)
To: Heinrich Schuchardt; +Cc: Tom Rini, u-boot
Hi Heinrich,
On Mon, 23 Oct 2023 at 23:31, Heinrich Schuchardt
<heinrich.schuchardt@canonical.com> 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@canonical.com>
> ---
> v3:
> avoid duplicate -Wl,--gc-sections
> only use KEEP for unreferenced symbols
> v2:
> mark _u_boot_sandbox_getopt sections as KEEP()
> ---
> arch/sandbox/config.mk | 4 ++--
> arch/sandbox/cpu/u-boot.lds | 2 +-
> 2 files changed, 3 insertions(+), 3 deletions(-)
I would still rather not do this, I am OK with trying it so long as we
can revert it if it causes problems.
>
> diff --git a/arch/sandbox/config.mk b/arch/sandbox/config.mk
> index 2d184c5f65..1d50991f8d 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
>
> @@ -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,%) \
> diff --git a/arch/sandbox/cpu/u-boot.lds b/arch/sandbox/cpu/u-boot.lds
> index ba8dee50c7..52f13af374 100644
> --- a/arch/sandbox/cpu/u-boot.lds
> +++ b/arch/sandbox/cpu/u-boot.lds
> @@ -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)
> }
>
> --
> 2.40.1
>
Regards,
Simon
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3 1/1] sandbox: eliminate unused functions from binaries
2023-10-24 6:30 [PATCH v3 1/1] sandbox: eliminate unused functions from binaries Heinrich Schuchardt
2023-10-24 18:03 ` Simon Glass
@ 2023-10-24 18:03 ` Tom Rini
2023-11-02 22:49 ` Simon Glass
1 sibling, 1 reply; 4+ messages in thread
From: Tom Rini @ 2023-10-24 18:03 UTC (permalink / raw)
To: Heinrich Schuchardt; +Cc: Simon Glass, u-boot
[-- Attachment #1: Type: text/plain, Size: 477 bytes --]
On Tue, Oct 24, 2023 at 08:30:47AM +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@canonical.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
--
Tom
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3 1/1] sandbox: eliminate unused functions from binaries
2023-10-24 18:03 ` Tom Rini
@ 2023-11-02 22:49 ` Simon Glass
0 siblings, 0 replies; 4+ messages in thread
From: Simon Glass @ 2023-11-02 22:49 UTC (permalink / raw)
To: Tom Rini; +Cc: Simon Glass, u-boot, Heinrich Schuchardt
On Tue, Oct 24, 2023 at 08:30:47AM +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@canonical.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
--
Tom
Applied to u-boot-dm, thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-11-02 22:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-24 6:30 [PATCH v3 1/1] sandbox: eliminate unused functions from binaries Heinrich Schuchardt
2023-10-24 18:03 ` Simon Glass
2023-10-24 18:03 ` Tom Rini
2023-11-02 22:49 ` Simon Glass
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox