https://bugs.winehq.org/show_bug.cgi?id=40502
Bug ID: 40502 Summary: Global objects constructors fail when invoking standard libs Product: Wine Version: 1.8.1 Hardware: x86 OS: Linux Status: UNCONFIRMED Severity: major Priority: P2 Component: winelib Assignee: wine-bugs@winehq.org Reporter: mirko.ortensi@gmail.com Distribution: ---
I managed to recompile and link my win32 application but at execution time, it crashes because of a segmentation fault where memset (or the bare printf("HELLO")) is invoked in the global object constructor (any call to standard C library is enough to trigger the crash).
The global object is built in the stack, then it seems that at launch time my object constructor is called before C Standard Library is ready. Now, as a workaround I can declare a pointer to global object and instantiate it in the main (tested, it works)...though...this is something I'd like to avoid to keep the code as original as possible. Removing the global objects, everything works like a charm.
As far as I understand, global object constructors are called after Wine infrastructure is ready to go, though I have doubts now regarding C Standard Library. (Please check 8.3.3. Starting a Winelib process https://www.winehq.org/docs/winedev-guide/x3172)
This code reproduces the error:
#include <stdio.h>
class Printer { public: Printer(){printf("HI\n");} };
Printer p;
int main(void) { return 0; }
The issue is reproduced by this code linking to msvcrt: wineg++ -mno-cygwin issue.cpp -o issue
Linking to system libs, this code does not reproduce the issue. wineg++ issue.cpp -o issue
Now, in my code (pretty big software I am porting to Linux) I still need to isolate root cause, issue is reproduced even linking against system libraries (not Wine's msvcrt, then). Anyway, I think there's a bug somewhere when linking to msvcrt even in this silly piece of code.