# HG changeset patch # User adf88@interia.pl # Date 1500961694 -7200 # Tue Jul 25 07:48:14 2017 +0200 # Branch trunk # Node ID c760233b90f1e394a4ef8a9d13b58e5f8eecbda7 # Parent 096954668ebcc43ef2c7ccdfb7c7d42a472df1cc Fix unresolved 'WinMain' and '_safe_esp' symbols when linking with LTO on MinGW. diff -r 096954668ebc -r c760233b90f1 src/os/windows/crashlog_win.cpp --- a/src/os/windows/crashlog_win.cpp Thu Jul 13 17:45:38 2017 +0000 +++ b/src/os/windows/crashlog_win.cpp Tue Jul 25 07:48:14 2017 +0200 @@ -487,8 +487,11 @@ /** * Stack pointer for use when 'starting' the crash handler. * Not static as gcc's inline assembly needs it that way. + * + * Mark it as 'used' to prevent optimizing out by LTO. + * This was happening e.g. on MinGW-w64 5.0.2 with GCC 7.0.1. */ -void *_safe_esp = NULL; +void *_safe_esp GCC_USED = NULL; static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep) { diff -r 096954668ebc -r c760233b90f1 src/os/windows/win32.cpp --- a/src/os/windows/win32.cpp Thu Jul 13 17:45:38 2017 +0000 +++ b/src/os/windows/win32.cpp Tue Jul 25 07:48:14 2017 +0200 @@ -426,10 +426,12 @@ } } +/* Mark WinMain as "used" to prevent optimizong out by LTO. + * This was happening e.g. on MinGW-w64 4.0.6 with GCC 6.2.0. */ #if defined(WINCE) -int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) +int GCC_USED APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) #else -int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) +int GCC_USED APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) #endif { int argc; diff -r 096954668ebc -r c760233b90f1 src/stdafx.h --- a/src/stdafx.h Thu Jul 13 17:45:38 2017 +0000 +++ b/src/stdafx.h Tue Jul 25 07:48:14 2017 +0200 @@ -148,6 +148,7 @@ #define CDECL #define __int64 long long #define GCC_PACK __attribute__((packed)) + #define GCC_USED __attribute__ ((used)) /* Warn about functions using 'printf' format syntax. First argument determines which parameter * is the format string, second argument is start of values passed to printf. */ #define WARN_FORMAT(string, args) __attribute__ ((format (printf, string, args))) @@ -162,6 +163,7 @@ #define NORETURN #define CDECL #define GCC_PACK + #define GCC_USED #define WARN_FORMAT(string, args) #define FINAL #include @@ -232,6 +234,7 @@ #endif #define GCC_PACK + #define GCC_USED #define WARN_FORMAT(string, args) #define FINAL sealed