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.
It looks like that function __main from file mingw-w64-crt/crt/gccmain.c is
somehow automatically discarded by gcc / ld LTO compiler when using -Ofast.
Fix this problem by manually adding __attribute__((used)).
---
mingw-w64-crt/crt/gccmain.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/mingw-w64-crt/crt/gccmain.c b/mingw-w64-crt/crt/gccmain.c
index fc0e35003cd1..13ef04fdba20 100644
--- a/mingw-w64-crt/crt/gccmain.c
+++ b/mingw-w64-crt/crt/gccmain.c
@@ -49,6 +49,7 @@ __do_global_ctors (void)
static int initialized = 0;
+__attribute__((used)) /* required for gcc -flto -Ofast */
void
__main (void)
{
--
2.20.1
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public