-
Notifications
You must be signed in to change notification settings - Fork 482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Investigation into the mingw-w64 AVX AND AVX2 misalignment bug. #1209
Comments
Is the MSYS2 project still maintained? |
Yes, it's a rolling distribution with new package builds coming out all of the time. |
Yet the MSYS2 project seems to be frozen since the end of 2016. For instance, when will be the AVX and AVX2 code on Windows 64 Bit issue be resolved? |
@RoyiAvital you can get more recent setup here https://sourceforge.net/projects/msys2/files/Base/ |
What issue are you talking about? Please provide a link. You can compile software that uses AVX and AVX2 quite happily using our compilers. Our prebuilt binaries cannot in general use AVX and AVX2 because our end-user's machines may not support those CPU features and that would result in crashes due to illegal instructions. This is exactly the same thing that every software distribution must contend with and we are no worse. Having said that some of the better written software out there (such as OpenBLAS) that we provide pre-built packages for implement runtime CPU detection and dispatch and this software will take good advantage of AVX and AVX2 when the machine supports it. In many general purpose C and C++ library cases AVX and AVX2 do not provide much very speed-up anyway. These features work best when dealing with things like heavy matrix computation and also with hand-crafted assembly language (or at least compiler intrinsics). |
@mingwandroid , I'm talking about code of the user. not libraries supplied with MinGW64 or MSYS2. References:
What I'm asking is 2 things:
|
This is clearly a GCC issue and not an MSYS2 issue, so you should ask GCC or mingw-w64 about that. We patch a few things in GCC but do not tend to fix things that are this low-level. Is it really so difficult to determine the correct place to report issues to? |
And you are asking questions that you should try to determine the answers to yourself, reproduction cases would be useful for someone with time to look into this. |
Here is the simplest code to reproduce it: https://stackoverflow.com/questions/30926241 I'm sorry to post here. |
Thank you. But this example does not work out of the box according to the comments. You should modify it and paste it here instead of expecting others to do this work for you.
As I already explained, I do not think anyone from MSYS2 will have the time to look into this and we do not tend to fix such low level bugs in mingw-w64/GCC which is where this bug is located. .. and that's OK because it's a mingw-w64/GCC bug. |
This seems to be a code which creates the issue:
Compiling with |
FWIW, all of this is very much unrelated to the original issue, while this thread now is hijacked for a completely different matter. As mentioned in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54412, clang and MSVC don't seem to have the same issue. An adjusted version of the example code,
If compiled with GCC:
This doesn't align the pointer where the argument is stored, and writes into it with With clang:
This overallocates stack space in order to be able to align it, and then writes into it with an aligned write. If not using SEH, by adding
This is what MSVC produces:
This both aligns the pointer, and uses unaligned stores to write it onto the stack However, this only seems to be an issue when passing such variables by value. Local variables seem to be properly aligned even with GCC:
Here the local variable is properly aligned. |
@mstorsjo , The question is, how can it be fixed? Thank You. |
The GCC bug report that I linked is the relevant one. |
Do you have account there to link to your analysis (Which states only variables transferred by value are an issue)? It seems one must have a special granted account to post there which I don't have. Thank You. |
I've retitled the bug since it went completely tangential immediately (2nd and 4th comment). |
I'm not sure if I have a GCC bugzilla account - anyone more affected by the issue than me can take it forward, I just gave the issue a brief look from the clang perspective. |
Could you tell how did you compile the above (Clang and GCC)? Thank You. |
@RoyiAvital it you look at the beginning of each snippet you can see used command. |
@mati865 , On a side note (for my own knowledge) I wanted to ask what other option Clang has for it |
The environment used in the examples does not matter as it doesn't include anything or link anything - the command line contains everything needed. I tested with a recent clang svn version (the latest from about a day ago), but I'm pretty sure at least the last couple releases should behave the same. There's no |
OK. Just to add information, I think this comment is important - https://stackoverflow.com/questions/30928265/mingw64-is-incapable-of-32-byte-stack-alignment-required-for-avx-on-windows-x64?noredirect=1#comment86499640_30928265. |
Sorry for digging up this old thread, but hey I bumped into it!
It's no longer important now. My own tests plus 54412 seems to suggest that it happens on all SEH-enabled versions of GCC, which is everything after something like 4.8.9.
The GCC people are (understandably) looking to do a proper fix to make the compiler actually understand how alignments work, but they seem a bit stuck. |
I have hacked together a very ugly patch that basically makes every place that generates aligned load/stores use unaligned instructions instead. I remember seeing someone say on Nehalem and newer the peanlty is very small or something. 0001-Force-use-unaligned-insns-as-49001-workaround.patch.txt I will try to send it to makepkg to build and test it if possible, but in case I burn out before then you all know what to try. Heck, I still owe Alex & the cygwin people a cmdline parser... A more graceful way to do the workaround may be changing |
Hi all! I have a feeling that GCC 11.2.0 has this issue fixed. At least I cannot reproduce the crash in a trivial test. I have managed to compile packages. If you would like to test them, please fetch here: https://yadi.sk/d/rL4Lo6HFkAojPA I will upload the sources of the script a bit later today (I had to change the patchset and have a problem with updating checksums) UPD: Here is a commit that makes it possible to compile GCC 11.2.0 for MinGW64: I'm not sure I know how MSYS handles multiple compilers at the same time, so I'm a bit of scared to propose a PR for that :) |
I don't think it fixes the issue -- https://gcc.gnu.org/bugzilla/attachment.cgi?id=28103 from bug 54412 still segfaults. PS: Hmm, any idea why the MSYS2 GNU |
Hm... then it is just a coincidence that my local test passes :( |
Hello.
Please upgrade the following setups from msys2 home page:
This will prevent beginners from thinking that the project was left in 2016.
Thank you!
The text was updated successfully, but these errors were encountered: