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.

MSP430-elf-gcc -Os -fwhole-program bug

Hello,

Compiling using msp430-elf-gcc with flags -Os -fwhole-program (trying to minimize total code size) then loading in msp430-elf-gdb fails to load interrupt vectors (behavior observed is every interrupt causes a reset).  Seems like a bug?  Or is there a better way to minimize code size?

Verified with multiple compilations of multiple programs with varying numbers of interrupt vectors.

Apologies if this is in the wrong forum and there a separate forum for msp430-gcc.

Adam

  • The gcc manual says:

    -fwhole-program
    Assume that the current compilation unit represents the whole program being compiled. All public functions and variables with the exception of main and those merged by attribute externally_visible become static functions and in effect are optimized more aggressively by interprocedural optimizers.

    Apparently, the compiler notices that the interrupt handlers are not called by your program, so they must be superfluous.

    Try adding the externally_visible attribute to the interrupt functions.

    Alternatively, consider using -flto instead of -fwhole-program (this option also works with multiple source files).

  • You are correct. I was blinded by the goal of reducing my code size and didn't realize I had inadvertently removed my interrupt handlers. /duh

    I have been trying to get the same code size reduction achieved by IAR Embedded Workbench using high optimization balanced for speed vs size (includes common subexpression elimination, loop unrolling, function inlining, code motion, and type-based alias analysis). IAR can reduce one of my programs to just under 4 KB, while the smallest I've been able to achieve with msp430-elf-gcc is 5.5 KB. I've tried -Os, -flto, -fwhole-program, and the MSP430 specific -minrt and -msmall. The smallest I can get is 5.5 KB. Any suggestions?

**Attention** This is a public forum