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.

Compiler: Functions not called included in binary for C2000 but not for MSP430

Other Parts Discussed in Thread: MOTORWARE

Tool/software: TI C/C++ Compiler

I am developing applications in C2000 and MSP430 and have noticed a significant difference in the way the compiler/linker works. In the MSP430 if a function is not called from main or an ISR then it is not included in the binary, as expected. However when compiling a C2000 application ALL the functions (and globals) defined in any .c files are included the final program, resulting in a huge binary.

I have tried Compiler 16.9.1, 16.9.3 and 17.3.0 with no difference. In all cases when I add a dummy function to the main .c file like:

void opt_test ( void)
{
    int bla = 0;

    if (bla++)
    return;
}

then the size of .text increases and opt_test is mentioned in the .map file. I am compiling using -O3 (I cannot use -O4 due to MotorWare limitations on F28027) and -mf 5 (optimise for size).

EDIT: I used the optimisation assisant to test various optimisation settings for -mf and all options produced the same binary size, maybe this points to the issue? Various -O settings do affect the binary size as expected though.

Best regards,

Giannis

  • I did some digging and found that this was due to the C2000 compiler defaulting to placing all functions of a .c file in a single section, so functions cannot be linked individually. This can be overiden with the --gen_func_subsections / -mo compiler option, found in the Runtime Model Options under Advanced Compiler Options in CCS. Similarly for structs and arrays there is the --gen_data_subsections option.

    For MSP430 these settings default to on, for C2000 to off. After setting both to On for the C2000 the Flash and RAM usage decreased significantly.

  • I confirm that using --gen_func_subsections is the best way to handle this situation.  Thanks for sharing the details of your experience.  I'm sure others will benefit.

    Thanks and regards,

    -George