-
Notifications
You must be signed in to change notification settings - Fork 179
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
Code always built with -msse4.1 leads to crashes on older CPUs #493
Comments
Actually, the Can you please try if the problem is solved by disabling link-time optimization (add |
https://github.com/BtbN/FFmpeg-Builds/blob/master/scripts.d/50-vvenc.sh that's the build script. The file in question that specifically causes the SIGILL crash is aforementioned Buffer.cpp, and in there the static initializer g_pelBufOP. |
Hmm, very interesting. The static initializer for The Buffer.cpp file is compiled without |
I didn't actually check which extension the instruction(pinsrq) belongs to. It's indeed SSE4.1 and not anything AVX. I tried setting some compiler attributes on the static initializer, in an attempt to stop the compiler from emitting any advanced instructions, but with no success. |
Ok, now it all makes sense. We never thought anybody would use such an old CPU to encode VVC, so we took SSE4.1 as given. But it's clearly a problem if these instructions are in the static initializers. A quick workaround could be to add the function attribute
This would need to be done for all static initialization code, but if it stops crashing in A long term fix could be getting rid of all the static initialization, but I think that needs some more work. |
I can't test/debug at the moment, since I'm at work. Will do later tonight. |
I've managed to get past the Buffer.cpp initializer, but it does not work properly with the Rom.cpp one sadly. |
I've given up on trying to stop gcc from emitting sse instructions. |
I guess we also add the |
SSE4.1 is not mandated by amd64/x86_64, only SSE2 is. I also don't think it's neccesary to remove it. Requiring SSE4.1 or x86-64-v2 is super fair. Shall I PR the Patch that gets rid of static initializers? It solves the issue, though is not very pretty yet and will likely need a few iterations. |
Could we test this with a VM as described? |
Since vvenc seems to always set various CPU feature compiler options unconditionally (only checking if the compiler understands them), this leads to the generated code to crash near immediately on any CPU that does not support AVX2.
See also BtbN/FFmpeg-Builds#411
The issue is made even worse by the use of static initializers like
vvenc/source/Lib/CommonLib/Buffer.cpp
Line 500 in 0c2c21e
So even if for example an ffmpeg user doesn't even want to do anything with vvenc, ffmpeg will crash instantly on startup, since the static initializer runs and was generated with advanced simd instructions by gcc.
What confuses me a bit about this is that there's clearly some degree of runtime simd level detection in https://github.com/fraunhoferhhi/vvenc/blob/master/source/Lib/CommonLib/x86/InitX86.cpp, but it'll be mostly useless if the code generated by the compiler itself uses avx2 everywhere.
A possible workaround to at least prevent the crashing static initializers would be to build specifically those with a generic arch, by attaching some compiler attribute or moving them to their own file or something.
The text was updated successfully, but these errors were encountered: