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.

RedHat GCC and *HUGE* code size... Solved

I have a test program for the FR5969 LaunchPad.

With the TI compiler in debug mode (no optimisation), it generates 3348 bytes of program and about 16 of data.

With the GCC compiler in debug with no extra parameters (other than setting the processor type to msp430x and including driverlib in the include path), the code size is... 29514 code and 756 data.

Is there something obvious I've missed?

The same code from both compilers works fine. In both cases I cleaned the project before doing the build.

EDIT: as an aside, I did "release" builds of the same code under both TI & RedHat - there was almost no difference in code size at all. Do the optimisers actually do anything meaningful?

Upping the TI compiler optimisation to "4" (whole program optimisation) reduced the code down to 2266 bytes - a real improvement. I couldn't get the RedHat compiler to improve much at all...

EDIT: With GNU debug mode, selecting "Remove unused sections" in the linker options reduced  code to 19206 and data to 688 - an improvement, but still extraordinarily poor.

  • Answered my own question.

    By default, the GCC compiler and linker will include everything, hence the massive size.

    You need to do two things in the compiler and one in the linker. Doing the following reduced my debug code size to 3650 bytes and data to 6 bytes with 954 bytes of RAM - very comparable with TI's own compiler (3320 & 16 with 1075 of RAM).

    Under Build->GNU Compiler->Optimization select:

    • Place each function into its own section (-ffunction-sections)
    • Place data items into their own section (-fdata-sections)

    Under Build->GNU Linker->Basic select:

    • Remove unused sections (--gc-sections)

    Doing this places all code and data in its own sections, then the linker can work out which are referenced and then only include those needed.

    Doing the above results in a MASSIVE improvement in code & data sizes (especially if using driverlib etc.) when using the RedHat compiler and should be essential settings for any project.

    Hope this helps others who want to try the RedHat compiler.

  • The effect you observed is the same as putting every function into its own source file and compile it separately. This is often used for libraries.
    However, it prevents global optimization. So it’s better to only have code you need than removing code you don’t need (it reduces compiling times too :) )

    Also, this might lead to problems with ISRs, as ISRs are usually only referenced by the interrupt vector table entry, but if this entry and the ISR are in their own discardable segment, and nobody references them, then the linker might throw them away. (things like this can already happen when coding in assembly, when the ISR is in its own source file)

    So using this feature (which I already do since mspgcc 3.2.3) requires some care. That’s probably why it isn’t active on default.

**Attention** This is a public forum