On Sun, 20 Jul 2025, Pali Rohár wrote:

On Thursday 17 July 2025 22:08:41 Pali Rohár wrote:
When mingw-w64 is compiled with LTO support (-flto and -ffat-lto-objects in
CFLAGS and LDFLAGS) then compiling any application with -Ofast fails.

Calling "gcc -flto -Ofast" throws fatal error:

    `___main' referenced in section `.text.startup' of 
/tmp/ccXtREge.ltrans0.ltrans.o: defined in discarded section `.text' of 
lib32_libmingw32_a-gccmain.o (symbol from plugin)
    collect2: error: ld returned 1 exit status

With -O2 or other level there is no error at all.

I have no idea what is triggering this issue. But for example on gcc-8 I
was able to trigger it also with -O2 on the small example which I sent for
PATCH 2/2 (to trigger it just remove __attribute__((used)) from __main.c
file).

But I have not been able to trigger this issue with -O2 on the mingw-w64
source code with gcc-8. I was able only with -Ofast param.

So looks like that -O2 is just enabling some optimization which can
sometimes trigger it and -Ofast has higher chance to trigger it.

I was not able to reproduce it with gcc-14 and ld-2.44.

Even if it isn't consistently reproducible, I think this makes sense to add the attribute here - this is an ABI symbol that is referenced by generated code, which may not be easily understood by LTO.

Will push this patch - leaving the one about main() signature as a separate issue as it seems like it's unsolveable in the general case.

// Martin

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to