ARM-software / tf-issues

Issue tracking for the ARM Trusted Firmware project
37 stars 16 forks source link

Use GCC --gc-sections to eliminate unused code and data from Firmware binaries #80

Closed danh-arm closed 10 years ago

danh-arm commented 10 years ago

There are many 'library' functions provided in common source files for Trusted Firmware BL images. All code and data is currently linked into every executable, and most of the images do not use most of the functions. Significant SRAM could be saved if only the required code and data are included.

Use the GCC -ffunction-sections and LD --gc-sections directives to automatically only include used code and data for C sources. This will require linker scripts updated to include the new input sections.

Add macro support to easily do the same for every helper function in the assembler sources, and modify existing assembler to allocate separate sections per function.

All root entry-points must be identified (to avoid being eliminated) and care must be taken with "fall through" semantics in assembler source code.

This requires the 2013.10 Linaro release of the GCC 4.8 AArch64 toolchain or later.

An earlier proof-of-concept suggested that this could save a combined total of 8-12KB of code in each BL image.

jenswi-linaro commented 10 years ago

I've tried this approach in the past and noticed one drawback. The compiler wasn't able to optimize the "surviving" code as well when each function was put in a separate section. Perhaps it has improved with a more recent GCC.

athoelke commented 10 years ago

I've got a prototype patch for this (so have assigned it to me for now) - this reduces the total RAM usage of the FVP software by 24KB - and BL3-1 by 12KB.