Prechádzať zdrojové kódy

Fix optiboot link failure with GCC 15 / newer binutils

Linking failed with "relocation target address is odd" against
exit in call_main.o. GCC 15 added -mno-call-main for exactly this
case: main is placed directly in .init9 (optiboot never returns
from it), so the libc __call_main/exit startup sequence doesn't
apply and isn't safely relocatable here. Reproduced identically on
unmodified upstream optiboot HEAD, so this is a toolchain
incompatibility, not something already fixed upstream.

Detect support via a compile probe rather than grepping
--help=target output, since GCC only lists the -mcall-main
(default) spelling there, not the -mno- form, so a grep-based check
would false-negative even on a GCC that accepts the flag. Falls
back to unmodified behavior on toolchains that reject it.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
k4be 1 týždeň pred
rodič
commit
b0aa218bdb
1 zmenil súbory, kde vykonal 8 pridanie a 0 odobranie
  1. 8 0
      optiboot/Makefile

+ 8 - 0
optiboot/Makefile

@@ -138,6 +138,14 @@ STK500-2 = $(STK500) -d$(MCU_TARGET) -ms -q -lCF -LCF -cUSB -I200kHz -s -wt
 OBJ        = $(PROGRAM).o
 OPTIMIZE = -Os -fno-split-wide-types -mrelax
 
+# GCC 15+ needs -mno-call-main, otherwise linking fails against newer
+# binutils: main is placed directly in .init9 (optiboot never returns from
+# it), so the libc __call_main/exit startup sequence this flag suppresses
+# is neither needed nor safely relocatable here.
+ifeq ($(shell echo 'int main(void){return 0;}' | $(GCCROOT)avr-gcc -mmcu=atmega328p -mno-call-main -x c -c -o /dev/null - 2>/dev/null; echo $$?),0)
+OPTIMIZE += -mno-call-main
+endif
+
 DEFS       = 
 
 CC         = $(GCCROOT)avr-gcc