[PATCH] microblaze: Enable GCC garbage collector for full U-Boot

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] microblaze: Enable GCC garbage collector for full U-Boot

Michal Simek-3
GCC's garbage collector works for Microblaze for quite a long time but none
has enabled it.
The same change has be done for example by commit fac4790491f6 ("arc:
Eliminate unused code and data with GCC's garbage collector").

Before:
   text   data    bss    dec    hex filename
 588760  33592  39192 661544  a1828 u-boot

After:
   text   data    bss    dec    hex filename
 504504  32164  38608 575276  8c72c u-boot

Which saves almost 15% of memory footprint.

Also group symbols/functions to proper section.

Reported-by: Tom Rini <[hidden email]>
Signed-off-by: Michal Simek <[hidden email]>
---

 arch/microblaze/config.mk      | 3 +++
 arch/microblaze/cpu/u-boot.lds | 6 +++---
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/microblaze/config.mk b/arch/microblaze/config.mk
index 96c39b1278b1..de5b97e719cc 100644
--- a/arch/microblaze/config.mk
+++ b/arch/microblaze/config.mk
@@ -9,6 +9,9 @@
 CONFIG_STANDALONE_LOAD_ADDR ?= 0x80F00000
 
 PLATFORM_CPPFLAGS += -ffixed-r31 -D__microblaze__
+PLATFORM_CPPFLAGS += -fdata-sections -ffunction-sections
+
+LDFLAGS_FINAL += --gc-sections
 
 ifeq ($(CONFIG_SPL_BUILD),)
 PLATFORM_CPPFLAGS += -fPIC
diff --git a/arch/microblaze/cpu/u-boot.lds b/arch/microblaze/cpu/u-boot.lds
index 928264334989..5dc09dbad2df 100644
--- a/arch/microblaze/cpu/u-boot.lds
+++ b/arch/microblaze/cpu/u-boot.lds
@@ -14,7 +14,7 @@ SECTIONS
  {
  __text_start = .;
  arch/microblaze/cpu/start.o (.text)
- *(.text)
+ *(.text*)
  __text_end = .;
  }
 
@@ -28,7 +28,7 @@ SECTIONS
  .data ALIGN(0x4):
  {
  __data_start = .;
- *(.data)
+ *(.data*)
  __data_end = .;
  }
 
@@ -51,7 +51,7 @@ SECTIONS
  __bss_start = .;
  *(.sbss)
  *(.scommon)
- *(.bss)
+ *(.bss*)
  *(COMMON)
  . = ALIGN(4);
  __bss_end = .;
--
2.29.2

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] microblaze: Enable GCC garbage collector for full U-Boot

Michal Simek-4
st 4. 11. 2020 v 14:55 odesílatel Michal Simek <[hidden email]> napsal:

>
> GCC's garbage collector works for Microblaze for quite a long time but none
> has enabled it.
> The same change has be done for example by commit fac4790491f6 ("arc:
> Eliminate unused code and data with GCC's garbage collector").
>
> Before:
>    text    data     bss     dec     hex filename
>  588760   33592   39192  661544   a1828 u-boot
>
> After:
>    text    data     bss     dec     hex filename
>  504504   32164   38608  575276   8c72c u-boot
>
> Which saves almost 15% of memory footprint.
>
> Also group symbols/functions to proper section.
>
> Reported-by: Tom Rini <[hidden email]>
> Signed-off-by: Michal Simek <[hidden email]>
> ---
>
>  arch/microblaze/config.mk      | 3 +++
>  arch/microblaze/cpu/u-boot.lds | 6 +++---
>  2 files changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/arch/microblaze/config.mk b/arch/microblaze/config.mk
> index 96c39b1278b1..de5b97e719cc 100644
> --- a/arch/microblaze/config.mk
> +++ b/arch/microblaze/config.mk
> @@ -9,6 +9,9 @@
>  CONFIG_STANDALONE_LOAD_ADDR ?= 0x80F00000
>
>  PLATFORM_CPPFLAGS += -ffixed-r31 -D__microblaze__
> +PLATFORM_CPPFLAGS += -fdata-sections -ffunction-sections
> +
> +LDFLAGS_FINAL += --gc-sections
>
>  ifeq ($(CONFIG_SPL_BUILD),)
>  PLATFORM_CPPFLAGS += -fPIC
> diff --git a/arch/microblaze/cpu/u-boot.lds b/arch/microblaze/cpu/u-boot.lds
> index 928264334989..5dc09dbad2df 100644
> --- a/arch/microblaze/cpu/u-boot.lds
> +++ b/arch/microblaze/cpu/u-boot.lds
> @@ -14,7 +14,7 @@ SECTIONS
>         {
>                 __text_start = .;
>                 arch/microblaze/cpu/start.o (.text)
> -               *(.text)
> +               *(.text*)
>                 __text_end = .;
>         }
>
> @@ -28,7 +28,7 @@ SECTIONS
>         .data ALIGN(0x4):
>         {
>                 __data_start = .;
> -               *(.data)
> +               *(.data*)
>                 __data_end = .;
>         }
>
> @@ -51,7 +51,7 @@ SECTIONS
>                 __bss_start = .;
>                 *(.sbss)
>                 *(.scommon)
> -               *(.bss)
> +               *(.bss*)
>                 *(COMMON)
>                 . = ALIGN(4);
>                 __bss_end = .;
> --
> 2.29.2
>

Applied.
M

--
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Xilinx Microblaze
Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs
U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP/Versal SoCs