AR# 21533

|

12.1 EDK - How do I reduce the size of the executable program (".elf" file)?

描述

I have written a ".c" file in EDK. When using LibGen to generate the executable program file, the ".elf" file is larger than the Block Memory size, and an error occurs:

"ERROR:MDT - Elf file Counter/executable.elf does not reside completely within BRAM memory of processor ppc405_0."

How do I reduce the size of the executable program (.elf file)?

解决方案

The main method to achieve this is to optimize your code using the proper library, and to modify the linker script.

For example, if you use xil_printf, this uses fewer resources than standard printf. For more information, refer to the document, oslib_rm.pdf, in "%EDK_install_directory%/doc".

Also, you can use "-ffunction-sections -Wl,--gc-sections" as command line options to GCC; this accomplishes the following:

-ffunction-sections: puts every function into a separate section during compilation
-Wl,-gc-sections: the linker removes unused sections

As a result, unused functions are discarded.

You might need to adapt or write your own linker script, because the compiler will invent section names of the form ".text*" as a result of "-ffunction-sections". For example:

.text : { *(.text*) }

instead of:

.text : { *(.text) }

Additionally, an outside chip memory is a another way to work around this problem.

NOTE: The -g switch increases the size of the ELF by including the debug section, but this debug section is discarded when the executable is loaded into the embedded system.

NOTE: The "-ffunction-sections -Wl,--gc-sections" switches do not work properly with mb-gcc. See (Xilinx Answer 37426).
AR# 21533
日期 08/16/2010
状态 Active
Type 综合文章
Tools
People Also Viewed