TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Zig: Drop MinGW-w64

105 pointsby goranmoominover 3 years ago

9 comments

iopqover 3 years ago
Rust on Windows used to run on Mingw, but has since moved on<p>It made it a lot easier in many ways to just compile a thing and have it work without thinking about mingw and interfacing C from mingw
jbkover 3 years ago
That’s the opposite of our experience on VLC and Firefox was sharing our opinion: mingw-w64 people are skilled, nice and very clever and think about all use cases.<p>This is how we are able to support configurations that even MS does not support…<p>Also, a contrario from what this threads seems to say, the Windows SDK headers are faaaar from being open source compatible
评论 #29616193 未加载
评论 #29618966 未加载
评论 #29615873 未加载
anonymfusover 3 years ago
Hmm...<p><a href="https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;cpp&#x2F;build&#x2F;x64-calling-convention" rel="nofollow">https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;cpp&#x2F;build&#x2F;x64-calling-conve...</a><p><i>&gt; Return values</i><p><i>&gt; A scalar return value that can fit into 64 bits, including the __m64 type, is returned through RAX. Non-scalar types including floats, doubles, and vector types such as __m128, __m128i, __m128d are returned in XMM0. The state of unused bits in the value returned in RAX or XMM0 is undefined.</i><p><i>&gt; User-defined types can be returned by value from global functions and static member functions. To return a user-defined type by value in RAX, it must have a length of 1, 2, 4, 8, 16, 32, or 64 bits. It must also have no user-defined constructor, destructor, or copy assignment operator. It can have no private or protected non-static data members, and no non-static data members of reference type. It can&#x27;t have base classes or virtual functions. And, it can only have data members that also meet these requirements. (This definition is essentially the same as a C++03 POD type. Because the definition has changed in the C++11 standard, we don&#x27;t recommend using std::is_pod for this test.) Otherwise, the caller must allocate memory for the return value and pass a pointer to it as the first argument. The remaining arguments are then shifted one argument to the right. The same pointer must be returned by the callee in RAX.</i><p>Isn&#x27;t this what <a href="https:&#x2F;&#x2F;github.com&#x2F;ziglang&#x2F;zig&#x2F;issues&#x2F;9998#issuecomment-997088467" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ziglang&#x2F;zig&#x2F;issues&#x2F;9998#issuecomment-9970...</a> claims to be undocumented?
评论 #29614231 未加载
评论 #29613682 未加载
bla3over 3 years ago
Windows uses its own calling convention. I&#x27;m sure COM win32 headers have no shortage or atrocities, but this post here is just saying that GCC doesn&#x27;t implement the Windows calling convention for struct returns, while clang does.
cyber_kinetistover 3 years ago
My last experience with MinGW-w64 was when I was trying to compile my C++ simulation code in Windows and finding out that AVX instructions were not working because the compiler had misalignment-related bugs. (The issue is still open in <a href="https:&#x2F;&#x2F;github.com&#x2F;msys2&#x2F;MSYS2-packages&#x2F;issues&#x2F;1209" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;msys2&#x2F;MSYS2-packages&#x2F;issues&#x2F;1209</a>)<p>MinGW&#x2F;MSYS certainly had appeal to former Linux devs who didn&#x27;t want to touch the horrors of MSVC, but Zig (with its included Clang compiler&#x2F;runtime) might end up being a better solution for people trying to compile C&#x2F;C++ code on Windows in a stable manner.
评论 #29615833 未加载
olvy0over 3 years ago
As someone who has to deal from time to time with code that is a mix of old COM components and newer mingw dependencies I found this discussion fascinating.<p>I learned to avoid most issues by wrapping everything at the boundaries with a pure C api&#x2F;abi, and not letting exceptions propagate at all, instead catching them and returning an error code.<p>I wonder why zig can&#x27;t do the same but I guess they want calls to directx etc to match what&#x27;s documented instead of going through c like contortions.
jmullover 3 years ago
It’s interesting to see the process at work.
chasilover 3 years ago
I know that Clang runs on Windows, as PuTTY&#x27;s &quot;about&quot; dialog credits it.<p>Does this offer a reasonable replacement for MinGW?<p><a href="https:&#x2F;&#x2F;wetmelon.github.io&#x2F;clang-on-windows.html" rel="nofollow">https:&#x2F;&#x2F;wetmelon.github.io&#x2F;clang-on-windows.html</a>
评论 #29616457 未加载
jchwover 3 years ago
I think the MinGW project is very useful, but I simply do not recommend using it.<p>My experience with it was trying to debug why a friend’s build was working on Windows and not Wine. I figured it out: it’s because MinGW implements something called pseudo relocations, which implement symbol-relative relocations inside the entrypoint of your executable. It’s needed because when compiling, you don’t know if an unresolved symbol will be external or not, so it gets compiled as if it’s not. But when linking, and you finally know that the symbol is external, it’s too late to change the code to refer to an import table indirection.<p>On ELF platforms, relocations can refer to symbols in other libraries during runtime linking. So external symbols can be treated very similarly to internal ones, just with linking done at runtime instead of compile-time.<p>On Windows, you have to use `__declspec(dllimport)` or some such to inform the compiler that the symbol <i>will</i> be external. It can then generate code for referring to the IAT.<p>MinGW wanted to support compiling UNIXy software that didn’t use this attribute, so it does not require it. Instead… the ELF-style pseudo-relocations are used. So at the entrypoint, your MinGW program or DLL loops through a table of pointers inside machine code, looks up their real address in the IAT, and performs fixups. It will even temporarily change the protection of the relevant pages to be writable. Check to see if your MinGW program has unexpected imports to kernel32.VirtualProtect! (IIRC this can also happen if you trigger executable stack by using GCC trampolines, another reason to not use GCC…)<p>(edit: Please read the replies below, but according to MinGW developers, this only happens in some edge cases; ordinarily, thunks will be used, which do not have this problem. In addition, MinGW binaries will always link to VritualProtect, because the pseudo-reloc code exists whether or not you use them. I never noticed it before, so that&#x27;s interesting.)<p>There’s only one problem: this is extremely failure-prone. For example, if you are on AMD64, the typical CALL instruction contains a 32-bit RIP-relative offset. But in a 64-bit process space, two modules can happily be more than 2^32 bytes away in memory. I assume ELF platforms have a linker that’s aware of this, since the linker knows about these special relocations, and thus has to ensure the binaries are in range… but I don’t know much about ELF linking, so don’t take that as fact.<p>So why does this break on Wine and not Windows? Well, as far as I can tell, it doesn’t break on Windows because for some reason ASLR never puts any of the modules too far away. I haven’t figured out why. Wine doesn’t implement ASLR and loads modules at their preferred addresses as long as it’s available, and those addresses wind up being too far away. The pseudo reloc code does not output any errors when the address overflows; would probably be worth a pull request, but I am still puzzling with why Windows doesn’t ever seem to cause the problem.<p>Unless I am missing something crucial, it’s possible that a large amount of Windows x64 binaries compiled with MinGW work almost entirely by accident, and maybe not even every time.<p>Most symbols like this are function calls, so a significantly safer approach would be for MinGW to generate a thunk for those, and then just fail at linking when encountering a data import that isn’t decorated. Unfortunately, I don’t make the calls. :P<p>I don’t mean to disparage any specific persons. I just generally recommend against MinGW even in the face of the fact that it is virtually the only free software option to compile Windows binaries.
评论 #29617793 未加载
评论 #29617647 未加载