One way to achieve this is to remove the unused data and functions.
There are many 'library' functions provided in common source files. 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.
To identify the unused data and functions, it will be easy if each function or data is created with separate section ( .text.fun1, .text.fun2). Compilers does not create separate sections for each function and data (.text and .data) by default. So, i started looking into the compiler flags and find below. I am using clang compiler and RISC-V GNU Compiler Toolchain.
test.c |
Compiler provides to below flags to achieve this.
1. -fno-function-sections (default)
This flag create single section functions/data.
2. -ffunction-sections
This flag creates separate sections for each function.
3. -fdata-sections
This flag creates separate sections for each data
x is of section .data.x and y is of section .data.y
4. --gc-sections & -print-gc-sections
Comments
Post a Comment