GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
avr

AVR: Make -mno-call-main work with -flto.

The -mno-call-main option now works correctly with -flto by using --defsym to avoid multiple definitions of __call_main.

The -mno-call-main option, which prevents the AVR toolchain from automatically calling the main function, was not working correctly with link-time optimization (LTO). This commit fixes the issue by using --defsym __call_main=0 in the linker spec, which avoids multiple definitions of the __call_main symbol when linking with LTO.

In Details

The avr_no_call_main_p variable was previously set in cc1[plus] and used in lto1, causing issues with LTO. The fix involves using --defsym in the linker spec to define __call_main=0, avoiding multiple definitions during LTO. The avr_insert_attributes function now adds the used attribute to main when -mno-call-main is specified.

For Context

The AVR toolchain is used to compile code for AVR microcontrollers. The -mno-call-main option is used to prevent the toolchain from automatically calling the main function, which is useful in certain embedded environments. Link-time optimization (LTO) is a technique that optimizes the code at link time, potentially improving performance. This commit ensures that these two features work together correctly.

Filed Under: avrltolinkeroptimization