decreasing executable size with gcc options
Posted: Mon Dec 28, 2009 4:01 pm
Hi,
Since .elf contents are loaded in memory on Nintendo DS and that we face big memory limitations (specially when including graphics & sound in the .elf file), I propose a modification of the Makefile template (if there's one) or at least suggest some fine option which allow to reduce code size:
compiler options: add -ffunction-sections -fdata-sections => put each data & function in a separate section
link option: add -Wl,--gc-sections => garbage collect unreferenced sections => removes all your unused code, but also compiler generated code & data which is finally unused. It means that even if all of your routines are used, it still saves ROM.
On my project, I could reduce the .elf file from 800k to 700k only with that (that's also some options we are using at work for an embedded application to save a lot of ROM).
bye
Since .elf contents are loaded in memory on Nintendo DS and that we face big memory limitations (specially when including graphics & sound in the .elf file), I propose a modification of the Makefile template (if there's one) or at least suggest some fine option which allow to reduce code size:
compiler options: add -ffunction-sections -fdata-sections => put each data & function in a separate section
link option: add -Wl,--gc-sections => garbage collect unreferenced sections => removes all your unused code, but also compiler generated code & data which is finally unused. It means that even if all of your routines are used, it still saves ROM.
On my project, I could reduce the .elf file from 800k to 700k only with that (that's also some options we are using at work for an embedded application to save a lot of ROM).
bye