-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add check for SSE 4.2 and PCLMUL support to native zlib, add system properties for disabling natives #3718
Conversation
Added the following system properties for manually disabling natives:
Example usage:
|
Alright I tested this on a pentium-based laptop from 2006 running debian and a pretty old kernel, it does correctly detect the unsupported CPU and print the message to the console without crashing, and uses the Java library instead. However, it doesn't appear to detect the unsupported CPU until I actually connect to the server. The log messages printed when BungeeCord start up initially say that its using the native compression library. |
I guess you need to move the checking code from newInstance to load to fix that |
Fixed, here's the output on the pentium-based laptop from 2006:
|
How come it says and then 21:26:15 [INFO] Native library native-compress is incompatible: This CPU does not support the required Eyeballing the code, it should only be the second message |
cipher and compress are two different things. for cipher/mbedtls maybe a different check is needed, if at all? right now this is just about zlib. |
I only implemented the SSE 4.2 check for the compression natives, the cipher doesn't use SSE, so there's no need to disable it. Only the compression library uses features we can't expect every CPU made in the past 2 decades to support. |
Whoops, my mistake. Sorry |
It looks like mbedtls already has all the CPUID checks baked directly into it, and selects a supported implementation at runtime |
Are we sure both of these are required? It's failing on Jenkins which was historically fine:
Are you sure pclmul is required? cpuinfo for the QEMU vCPU has |
I looked through the code a bit and used by the CRC32 algorithm. Apparently the CRC32 function is only used for gzip, not deflate (this is news to me), so I guess if we can verify that the compression natives will only ever need to handle deflate and not gzip we could disable gzip support and compile the library for deflate/inflate only. I'm not sure if zlib's inflate function automatically detects gzip or not or if the gzip handling code is never even called in the first place and optimized away. https://github.com/cloudflare/zlib/blob/gcc.amd64/crc32_simd.c |
Is there a way to do this? |
I'm 90% sure there's a simple preprocessor directive we can set to compile zlib without gzip support. I'll try it out when I get home from work, I get off in about 2.5hrs. |
No rush, thanks |
Fix for #3717
I implemented a function in
native-compress.so
to check the CPUID registers if the required features for the cloudflare zlib library are supported on the CPU or not, by checking for the SSE 4.2 and PCLMUL bits. My implementation is only compatible with GCC as far as I know. This should probably be tested on real hardware, I haven't verified if the function actually returns false on a CPU that doesn't support SSE 4.2 or PCLMUL. I have only verified that the Java exception is handled correctly when I change the function to return false manually.I also tested the binary on both Debian and Alpine Linux to make sure there are no C library portability issues like we had with the SSL library.