-
-
Notifications
You must be signed in to change notification settings - Fork 31.2k
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
blake2module.c needs to be compiled with libhacl SIMD flags #130213
Comments
Aren't we setting them in // Small mismatch between the variable names Python defines as part of configure
// at the ones HACL* expects to be set in order to enable those headers.
#define HACL_CAN_COMPILE_VEC128 HACL_CAN_COMPILE_SIMD128
#define HACL_CAN_COMPILE_VEC256 HACL_CAN_COMPILE_SIMD256
#include "_hacl/Hacl_Hash_Blake2b.h"
#include "_hacl/Hacl_Hash_Blake2s.h"
#if HACL_CAN_COMPILE_SIMD256
#include "_hacl/Hacl_Hash_Blake2b_Simd256.h"
#endif
#if HACL_CAN_COMPILE_SIMD128
#include "_hacl/Hacl_Hash_Blake2s_Simd128.h"
#endif So, the headers shouldn't even be included if |
In addition, if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || test "$ANDROID_API_LEVEL" -ge 28; then
AX_CHECK_COMPILE_FLAG([-mavx2],[
[LIBHACL_SIMD256_FLAGS="-mavx2"]
AC_DEFINE([HACL_CAN_COMPILE_SIMD256], [1], [HACL* library can compile SIMD256 implementations]) |
Oh, I think I see what happens: Modules/blake2module.o: $(srcdir)/Modules/blake2module.c $(MODULE__BLAKE2_DEPS) $(MODULE_DEPS_SHARED) $(PYTHON_HEADERS); $(CC) -I$(srcdir)/Modules/_hacl/include $(PY_STDMODULE_CFLAGS) $(CCSHARED) -c $(srcdir)/Modules/blake2module.c -o Modules/blake2module.o We might be missing some flag here indeed. OTOH, we have
in Setup.stdlib, but maybe we're missing a |
I won't have time to investigate more so I leave it to @msprotz |
@jmroot I'm slightly confused by your report. It looks like merely including smmintrin.h triggers an error if you do not pass -msse4.1, as opposed to actually using definitions from smmintrin.h @jmroot I dimly recall something like that happening on old clang versions. Can you check with a very recent clang please? @picnixz blake2module.c should not be compiled with any -m flags, otherwise, the compiler might start introducing, say, SSE4.1 instructions in a section of code that is not guarded behind the run-time check for e.g. has_simd256(), which will generate illegal instruction errors if Python is executed on a machine that does not have these instructions. The idea is that one should be able to include various *mmintrin.h headers without issues, but must guard their usage behind suitable runtime checks. |
Yes, that seems to be the case.
It works fine with current clang of course, because |
The trigger for the error in |
On my system (which definitely does not have avx512):
the header inclusion works just fine. But I try to use the header without the right -m flags:
Then I do get an actual error. So it appears on my system, you're allowed to include headers for intrinsics that are not currently enabled via suitable -m flags, but you do get an error if you try to use such intrinsics. On your system, it appears that the behavior of the headers is much stricter. What you suggest would work, but I would like to make sure I 100% understand why it's needed before I add it.
Thanks! |
Slightly hard to tell given that with current clang from Xcode 16.2
But it's certainly consistent with the evidence.
I don't know what the policy is. The only requirement I'm aware of is C11. Disabling SIMD for older clang would also be an acceptable though less preferable resolution. |
The other part of the problem is that one of the types defined in the intrinsics headers is always used ( Disabling SIMD may well be the only easy fix here. What do you think would be the best way to do that? Perhaps a configure check for whether |
@jmroot I re-read your message above. Just to recap (correct me if I missed something):
Fixes include:
Option 3. will take considerable time and effort, and option 2 is a big hack. I lean towards your proposed solution (option 1). @jmroot do you know which version of clang it is that those headers started behaving "the right way"? |
I think that's all correct.
This seems to be specific to
It looks like on the Apple side it happened in either Xcode 8 or some late 7.x version. |
@msprotz PR opened for option 1, please take a look. |
The not-so-old clang-cl 18.1.8 currently shipped with Visual Studio 2022 fails with:
I think this is related? clang-cl 19.1.1 shipped with VS 2022 Preview 5 compiles fine. If option 1 is the way to go, then IIUC we'll have to do something similar in
|
It seems like the same problem indeed. Based on my understanding, yes to both points. Pinging @gpshead who might be interested in this discussion |
Thanks for looking into it. I figured option 3 would likely be a longer term effort. |
Bug report
Bug description:
blake2module.c
may include_hacl/Hacl_Hash_Blake2b_Simd256.h
and/or_hacl/Hacl_Hash_Blake2s_Simd128.h
, and thus needs to compile withLIBHACL_SIMD128_FLAGS
and/orLIBHACL_SIMD256_FLAGS
, or you get an error like this if the compiler doesn't enable those SIMD features by default:I would create a PR but unfortunately I can't figure out where this needs to be added.
CPython versions tested on:
3.14
Operating systems tested on:
macOS
Linked PRs
The text was updated successfully, but these errors were encountered: