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 GCC -flto and optimization levels

Hi!

I'm trying to use the link-time optimization (-flto) feature of gcc but it does not work properly if any of the optimization levels (-O1, -O2, or -O3) is also selected.

What I can see if -Ox is set, all of my ISRs are discarded. Is this the expected behaviour or am I possibly doing something wrong?

I am using 

msp430-elf-gcc (GCC) 4.9.1 20140707 (prerelease (msp430-14r1-364)) (GNUPro 14r1)
(Based on: GCC 4.8 GDB 7.7 Binutils 2.24 Newlib 2.1)

update:

when compiling with -fno-use-linker-plugin, the problem disappears.

Thanks!

  • The interrupt handler is not actually called from within the program, so it appears to be unused.

    Interrupt handlers need not only the interrupt(x) function attribute, but also used.
    (This should be changed in the __interrupt macro in <iomacros.h>.)

  • Well, this works, but it doesn't seem to be a good idea to edit headers supplied by the toolchain.
    An other problem I discovered is that compiling with -flto also discards functions which are only referenced through a pointer (i.e the symbol is not directly called).
    As a general advice, considering these problems, is it worth bothering with link-time optimization?
  • I meant that TI should change this. Alternatively, #undef/re-#define it.

    I cannot reproduce the indirect-function problem:

    void a(void) { }
    void b(void) { }
    
    int main(int argc, char *argv[])
    {
    	void (*f)(void);
    
    	f = argc ? a : b;
    	for (;;)
    		f();
    }

**Attention** This is a public forum