-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
SSE2 jpeg decoding segfaults in mingw 32 bit builds #81
Comments
I haven't looked at your project, since I'm not set up for mingw, but: Isn't mingw a gcc? GCC is supposed to have SIMD disabled since this version: 5c121a9 Can you try sticking #error's in around that code and see what path is being compiled? Also, I assume your machine supports SSE2 and yet you are getting this crash in 32-bit? For the other person watching this repo: Fabian, it doesn't seem like this is the gcc sse-enabled thing, if his machine does support SSE (and the call stack shows he's gonna into the SSE branch of the code post-CPU-detection, if I'm not mistaken). Any idea? |
I would need to know what the actual exception and actual instruction -Fabian On Mon, Feb 16, 2015 at 7:43 PM, Sean Barrett notifications@github.com
|
(also the GCC SSE2 detection logic is broken, that stuff needs to happen On Mon, Feb 16, 2015 at 8:13 PM, Fabian Giesen rygorous@gmail.com wrote:
|
Yep, there's already a separate bug report for that. |
Sean:
Hope this helps, let me know if i can provide more useful information. |
We can't be 100% sure without seeing the assembly to know for sure which instruction is failing what's going on or how to work around it. Since we can't force people to set compiler flags, unless there's a pragma to enable it in code, unless we find a workaround we'll just have to disable it in mingw entirely. But it seems pretty compiler-broken if that stack-alignment problem only happens with mingw and not with gcc (e.g. compiling gcc -msse2 32-bit on Linux). Also, you said you also tried "-msse -msse2", but does that mean this happened without setting those flags? In that case I'm not sure why the SSE2 #define is happening. |
Well, reading https://gcc.gnu.org/bugzilla/show_bug.cgi?id=40838 it sounds like -mstackrealign is the fix for this in gcc 4.5 for Linux but it's not on by default so it should just potentially fail in gcc for Linux as well, but only if being called by code that wasn't compiled by gcc (or something) because they declared the Linux ABI as always having 16-byte aligned stack. So I guess in practice it works in Linux because of that (mostly), and it's going to fail in mingw (without -mstackrealign) since it probably doesn't enforce a 16-byte-aligned stack since it's running on Windows. I guess from this: http://www.peterstock.co.uk/games/mingw_sse/ then maybe putting "attribute((force_align_arg_pointer))" on all the topmost function (or just all the SSE functions) is the mingw workaround. |
I haven't seen the disassembly, so it's hard to be sure, but I've seen a Basically, newer GCCs (>=4.5) by default assume (and maintain) 16-byte MinGW code calling other code compiled with MinGW always works, since ESP Essentially, MinGW is intentionally non-conforming to the Windows ABI, in a Either way, this isn't even a MinGW problem per se. It will work if you -Fabian On Mon, Feb 16, 2015 at 11:21 PM, Sean Barrett notifications@github.com
|
It's a compiler interop problem that will ALWAYS happen with mingw & vc++ (or without compiler interop, just with callbacks?) when you put stb_image into a mingw-compiled library, though. So I don't know if that's "a very specific use case". Being able to drop stb_image.h into code that gets compiled as a library seems a reasonable use case to me. That library always breaking if compiled with mingw seems worth fixing. (I agree it's still mingw's bug, though.) |
Don't know, honestly. I just have the nagging feeling that even if you add You already need to change the compiler flags to get SSE2 on MinGW in the -Fabian On Tue, Feb 17, 2015 at 12:01 AM, Sean Barrett notifications@github.com
|
Yeah, unfortunately header file libs inherit their compiler flags from the source file, so it doesn't make sense to tell people they need to add another flag so it won't crash. So disabling may still be the best. (And add a flag to force it on if you know what you're doing.) |
That pull request has an attempted fix. That said, I don't have a working MinGW setup either so it's untested. SpartanJ, can you try this and check whether it fixes the problem? Note that this patch changes stb_image to default to no SSE2 on MinGW 32-bit. You can re-enable SSE2 on MinGW using a #define (see the patch for details), but this is only safe if you also add "-mstackrealign" to your build. Does this work for you? |
rygorous i'll test this after work, but i can see one problem in the patch:
This it will also disable SIMD for x64 builds, since STBI_X86_TARGET includes x86_64, that's not necessary as far as we know. I'll try the Qt solution, using
I've tried both, and it's the same. The SSE2 #define is happening because it's predefined by most of the compilers i tried, look, this is GCC and Clang on Linux:
The same flags are predefined in MingW on Windows, but they are not defined in MingW on Linux ( the cross compiler, Thanks for your help! |
x64 always has SSE2 on, and your default CC on Linux is likely to be I thought MINGW32 was 32-bit specific, since there's also MINGW64. -Fabian
|
You're right, with -m32 it does not output
It seems that |
I tried forcing the align with |
This is fixed in a different way in 2.03; search for mingw in the file. |
This commit also disables SSE2 for 64 bits builds and it's not necessary. We should check only for 32bits. |
Posted 2.04 which attempts to fix this. Let me know. |
Closing this to make my issues list more readable. Reopen if there's a problem. |
Hi Sean!
I received a bug report on one of my libraries that relies on stb_image to do the image decoding. It took me a while to understand what was happening since i couldn't reproduce it, until the user mentioned that it was building for 32bits with mingw32 ( and i was building 64 bit builds ).
It seems that the jpeg SSE2 decoder is failing strangely, since if i build with VC works just fine.
.
Here's an image of the callstack when fails:
Here's a project to test the issue.
I've also tested to cross-compile the project from linux and it also happens. I must say that i know nothing about SSE2 so i really can't help much with the bug. And AFAIK it's a 32bit mingw only problem, no problems so far in 32 or 64 bit builds in linux, and if i remember correctly, no problems in os x neither.
Edit:
I tried compiling with "-msse -msse2" enabled but didn't help.
Regards
The text was updated successfully, but these errors were encountered: