This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Avoid linking unused (dead) functions into the final hex file

Other Parts Discussed in Thread: MSP430F5438

Hi,

First, I am using cl430 v3.0.1 on a MSP430F5438 MCU.

We are currently low in space and realize that we are actually linking all library functions into our final executable. From the documentation, I've modified our project to generate the list of dead functions (--gen_func_subsections when compiling and then --generate_dead_funcs_list at linking).

From the dead_funcs.xml, I conclude that I could save 8536 bytes in the final executable by avoiding compiling unused functions (sum of all <size> tags). I then tried what the guide proposes, recompile and link using --use_dead_funcs_list.

I did that and what I observe is:

  • No .hex code reduction in the output
  • From generated .asm files, I see that unused functions are actually moved in a subsection of .text, for example:
  • .sect ".text" becomes .sect ".text:MyUnusedFunctionName"
  • Using nm430 on the objects files, I see that addresses are lower (as expected) and:
  • 00000000 t .text:MyUnusedFunctionName
  • 00000000 T text:MyUnusedFunctionName
  • The binary diff between the actual objects files are different, too.
I was expected to see a diminution of the overall code size after linking. Are my expectations wrong? Is it because I am using an old compiler release? Is there any way to reduce the output hex file avoiding the #ifdef on the functions names found into the dead_funcs.xml file?
Thanks,
Pierre-Etienne Messier
  • Normally, the linker puts eiter all or none of the code in one compilation unit (.c file) in to the binary.
    If you want code linked individually, dependent on whether it is used or not, you need to put it into separate .c files. (that's how libraries are built).

    MSPGCC has an option to put each function into its own segment, so it appears as if individually compiled. Then the linker should be able to drop unused ones. But since they still are in the same compilationm unit, it is necessary (in MSPGCC) to tell the linker to actually do it. Maybe it's the same with your setup: you'll need to tell not only the compiler to use individual segment names, btu also tell the linker to assume that different segment names also mean independent code parts. Else the linker will still keep everything in one compilation unit (independently of the segment name) and only the grouping changes.

    Another suggestion: did you clean the project? Often, changing an option does not really cause a full recompile, as the source code wasn't touched.

**Attention** This is a public forum