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-OPENSOURCE: Compiler Option '-minrt' and unnecessary Function Prologue of 'main()'

Part Number: MSP430-GCC-OPENSOURCE

Hello,

When I compile with option '-minrt' and '-Os', gcc generates unnecessary function prologue for 'main():'

; start of prologue
 PUSH R10  ;
.LCFI2:
 PUSH R9  ;
.LCFI3:
 ; end of prologue

Since no runtime routine code is needed, PUSH R9 and R10 wastes 4 bytes of flash!

(mspdebug) dis main
main:
    0c360: 0a 12                     PUSH    R10
    0c362: 09 12                     PUSH    R9

  • This prologue is generated only if the code main() is so complex that it actually needs to use R9 and R10.

    Anyway, the -minrt option does not affect the code generator; it only tells the linker to select a different piece of startup code.

    The only way to get rid of this prologue would be __attribute__((naked)), but then you would not be able to use local variables.
  • Thank you for your reply. I tried '__attribute__((naked))' , no more ‘PUSH’ instructions anymore! My program still worked with local variables. I assume that PUSH R9 and R10 is a stub when you don't need runtime.

**Attention** This is a public forum