https://bugs.winehq.org/show_bug.cgi?id=49138
Bug ID: 49138 Summary: winegcc: argc and argv arguments of main() get corrupted Product: Wine Version: 5.7 Hardware: x86-64 OS: Linux Status: UNCONFIRMED Severity: normal Priority: P2 Component: tools Assignee: wine-bugs@winehq.org Reporter: mail@robbertvanderhelm.nl Distribution: ---
I first came across this issue with winelib compilation in Wine 5.7 while I was working on yabridge, a Wine VST bridge. The issue still persists on the latest commit in the Wine repository as I'm writing this (commit bf1abba, with the release of Wine 5.8). I'm not exactly sure what is going on, but the issue can be reproduced as follows:
#include <iostream>
int main(int argc, char* argv[]) { std::cout << "argc = " << argc << std::endl; std::cout << "argv[0] = " << argv[0] << std::endl; }
If you compile the above (or the C-equivalent) with `wineg++ test.cpp -o test` and run test.exe, then at least on my system it will always print 70624 as the value of argc and some uninitialized looking data for argv[0]. This happens regardless of whether the program receives any command line arguments or not.
Winelib applications compiled with the toolchain that comes with Wine 5.6 can be run without problems under Wine 5.7 or 5.8. The winelib compilation issue with Wine 5.7+ exists on Ubuntu 18.04, Ubuntu 20.04, Arch Linux and Manjaro, both when using the distro provided packages and when building Wine from source.
https://bugs.winehq.org/show_bug.cgi?id=49138
Zebediah Figura z.figura12@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |z.figura12@gmail.com
--- Comment #1 from Zebediah Figura z.figura12@gmail.com --- The calling convention doesn't match anymore, and needs to be explicitly specified by appending __cdecl. See ed6a5e97e0. It seems undesirable that this is necessary...
https://bugs.winehq.org/show_bug.cgi?id=49138
--- Comment #2 from Robbert van der Helm mail@robbertvanderhelm.nl --- Adding an explicit calling convention does indeed solve the issue for both yabridge and the example I posted here! I experimented a bit with the WinMain entry point function before with no success but somehow I never though of explicitly specifying the __cdecl calling convention on my regular main() function. Did the default calling convention change somewhere between Wine 5.6 and Wine 5.7?
https://bugs.winehq.org/show_bug.cgi?id=49138
--- Comment #3 from Robbert van der Helm mail@robbertvanderhelm.nl --- Now that Wine 6.0 no longer requires __cdecl for Winelib binaries and the behaviour is back to what it was before Wine 5.7, maybe this ticket can be closed now.