crt: Fix LTO -Ofast compilation
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)).
Signed-off-by: Martin Storsjö <martin@martin.st>
diff --git a/mingw-w64-crt/crt/gccmain.c b/mingw-w64-crt/crt/gccmain.c
index fc0e350..13ef04f 100644
--- a/mingw-w64-crt/crt/gccmain.c
+++ b/mingw-w64-crt/crt/gccmain.c
@@ -49,6 +49,7 @@
static int initialized = 0;
+__attribute__((used)) /* required for gcc -flto -Ofast */
void
__main (void)
{