Skip to contentSkip to conversation

ppc4xx: Use gc-sections to reduce image size

RFC PATCH New Stefan Roese 2 participants 2 messages Sep 23, 2010 – Sep 24, 2010 PowerPC

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 ppc4xx: Use gc-sections to reduce image size

This patch enables gc-sections for PPC4xx. This is done to generate smaller U-Boot images. For this the linker script also needs some tweaking:

- For example change *(text) to *(text*)
- Add KEEP to some of the symbols, especially "resetvec"

This patch is tested on the following boards and reduces the image size by the these values:

Canyonlands: 11,642
Katmai:       9,170
Kilauea:     10,742
Sequoia:     11,398

Additionally this patch integrates a bit of cleanup to the PPC4xx default linker script.

Please note that this patch only enables gc-sections for PPC4xx. Other PowerPC's may enable it as well but also need to change the linker scripts accordingly. I didn't do this in this patch since I can't test all those platforms/boards.

Once all PowerPC platforms have gc-sections enabled, the changes to arch/powerpc/cpu/ppc4xx/config.mk should be moved to arch/powerpc/config.mk

---
 arch/powerpc/cpu/ppc4xx/config.mk  |    6 ++++
 arch/powerpc/cpu/ppc4xx/u-boot.lds |   53 +++++++-----------------------------
 2 files changed, 16 insertions(+), 43 deletions(-)
arch/powerpc/cpu/ppc4xx/config.mk +6 -0
index 5bda710..b0d346a 100644
@@ -33,5 +33,11 @@ else
 PLATFORM_CPPFLAGS += -Wa,-m405 -mcpu=405
 endif
 
+# Enable gc-sections to enable generation of smaller images.
+# Please note that the linker scripts may need some tweaking with this
+# change as well.
+PLATFORM_LDFLAGS += --gc-sections
+PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections
+
 # Use default linker script.  Board port can override in board/*/config.mk
 LDSCRIPT := $(SRCTREE)/arch/powerpc/cpu/ppc4xx/u-boot.lds
arch/powerpc/cpu/ppc4xx/u-boot.lds +10 -43

100 lines not on this page · raw message

Signature · 1 line
1.7.3
#1 lore raw

RFC PATCH 1/1 ppc4xx: Use gc-sections to reduce image size

Hi Stefan,

Quoted 7 lines

This patch enables gc-sections for PPC4xx. This is done to generate smaller U-Boot images. For this the linker script also needs some tweaking:

- For example change *(text) to *(text*)
- Add KEEP to some of the symbols, especially "resetvec"

Quoted 7 lines

This patch is tested on the following boards and reduces the image size by the these values:

Canyonlands: 11,642
Katmai:       9,170
Kilauea:     10,742
Sequoia:     11,398

Interesting.

Just for whoever is interested - I wondered how to find out what is actually unused to find pointers to unused crufty code.

Actually this is pretty easy by adding "--print-gc-sections" to the PLATFORM_LDFLAGS:

-----8<-----

arch/powerpc/cpu/ppc4xx/config.mk +1 -1
index b0d346a..f1e15c9 100644
@@ -36,7 +36,7 @@ endif
 # Enable gc-sections to enable generation of smaller images.
 # Please note that the linker scripts may need some tweaking with this
 # change as well.
-PLATFORM_LDFLAGS += --gc-sections
+PLATFORM_LDFLAGS += --gc-sections --print-gc-sections
 PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections
 
 # Use default linker script.  Board port can override in board/*/config.mk

-----8<-----

Using this, the linker prints lots of message slike this:

ppc_4xxFP-ld: Removing unused section '.data' in file 'arch/powerpc/cpu/ppc4xx/start.o'
ppc_4xxFP-ld: Removing unused section '.bss' in file 'arch/powerpc/cpu/ppc4xx/start.o'
ppc_4xxFP-ld: Removing unused section '.text' in file 'board/amcc/sequoia/init.o'
ppc_4xxFP-ld: Removing unused section '.data' in file 'board/amcc/sequoia/init.o'
ppc_4xxFP-ld: Removing unused section '.bss' in file 'board/amcc/sequoia/init.o'
ppc_4xxFP-ld: Removing unused section '.text' in file 'arch/powerpc/cpu/ppc4xx/resetvec.o'
ppc_4xxFP-ld: Removing unused section '.data' in file 'arch/powerpc/cpu/ppc4xx/resetvec.o'
ppc_4xxFP-ld: Removing unused section '.bss' in file 'arch/powerpc/cpu/ppc4xx/resetvec.o'

I believe they can be gladly ignored, because the "generic" segments are now empty thanks to the "-ffunction-sections -fdata-sections" directives. What is really interesting are messages like this:

ppc_4xxFP-ld: Removing unused section '.text.gpio_read_out_bit' in file 'arch/powerpc/cpu/ppc4xx/libppc4xx.a(gpio.o)'
ppc_4xxFP-ld: Removing unused section '.text.gpio_read_in_bit' in file 'arch/powerpc/cpu/ppc4xx/libppc4xx.a(gpio.o)'
ppc_4xxFP-ld: Removing unused section '.text.gpio_config' in file 'arch/powerpc/cpu/ppc4xx/libppc4xx.a(gpio.o)'
ppc_4xxFP-ld: Removing unused section '.text.gpio_write_bit' in file 'arch/powerpc/cpu/ppc4xx/libppc4xx.a(gpio.o)'

They essentially show the functions that are not used in this link run.

Cheers
Detlev

Signature · 6 lines
There are three kinds of people in the world; those who can count and
those who can't.
--
DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: [email protected]