Skip to content
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

Update libsodium #206

Closed
wants to merge 5 commits into from
Closed

Conversation

kasperisager
Copy link
Contributor

No description provided.

@kasperisager kasperisager changed the title Disable AVX2 support Disable AVX2 on Linux Oct 29, 2024
@kasperisager
Copy link
Contributor Author

@jedisct1 Thanks so much for dropping by, it's much appreciated! 🙏

@kasperisager kasperisager changed the title Disable AVX2 on Linux Fix AVX2 support on Linux Oct 29, 2024
@jedisct1
Copy link
Contributor

In the original build system, only the files that actually require AVX2 are compiled with the avx2 compile flag. Same thing for AVX, AVX512, ARM crypto extensions, AES, etc. And functions in these files are only called if, at runtime, these features are available on the current CPU.

But it looks like this CMakefile is applying the same flags, which includes non-portable flags, to all the files. So the result is indeed non portable.

Since the introduction of the Zig build system, files requiring specific extensions also enable them individually, using clang/gcc extensions. That should be fine in your case.

@gholam-deblan
Copy link

@jedisct1 glad to see you there Jedi Sector One, we used to code on HP48SX a while ago, thanks for the fix very appreciated!

@kasperisager kasperisager changed the title Fix AVX2 support on Linux Update libsodium Oct 29, 2024
@kasperisager
Copy link
Contributor Author

@jedisct1 So far, so good; I've updated libsodium to latest main to hopefully weed out the last compilation issues. The only iffy bit is now this, without which compilation fails on Windows:

if(target MATCHES "win32")
target_compile_options(
sodium
PRIVATE
-mrdrnd
-mavx
-mavx2
-mavx512f
)
endif()

@jedisct1
Copy link
Contributor

@jedisct1 glad to see you there Jedi Sector One, we used to code on HP48SX a while ago, thanks for the fix very appreciated!

Wow, that was a looooong time ago! But I miss these good old days!

@jedisct1
Copy link
Contributor

@jedisct1 So far, so good; I've updated libsodium to latest main to hopefully weed out the last compilation issues. The only iffy bit is now this, without which compilation fails on Windows:

How does it fail on Windows?

@jedisct1
Copy link
Contributor

I've updated libsodium to latest main

Use the stable branch, not master which is development code.

@kasperisager
Copy link
Contributor Author

Without -mrdrnd, for example, the Windows build fails with the following error:

D:\a\sodium-native\sodium-native\vendor\libsodium\src\libsodium\randombytes\internal\randombytes_internal_random.c(561,12): error: call to undeclared function '_rdrand32_step'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  561 |     (void) _rdrand32_step(&r);
      |            ^

@jedisct1
Copy link
Contributor

Maybe the compiler toolchain is too old. You can undefine HAVE_RDRAND on Windows. It doesn't matter much.

@kasperisager
Copy link
Contributor Author

This applies to both RDRAND, AVX, AVX2, and AVX512F on Windows though and at least AVX2 and AVX512F are automatically enabled by libsodium: https://github.com/jedisct1/libsodium/blob/cd92e5cfc8ed53a3a8d76c2116e1b77460e88bb9/src/libsodium/include/sodium/private/common.h#L257-L262

@jedisct1
Copy link
Contributor

That's for Visual Studio.

@kasperisager
Copy link
Contributor Author

Clang defines _MSC_VER on Windows, so it applies there as well.

@kewlfft
Copy link

kewlfft commented Oct 29, 2024

@jedisct1 glad to see you there Jedi Sector One, we used to code on HP48SX a while ago, thanks for the fix very appreciated!

Wow, that was a looooong time ago! But I miss these good old days!

You may remember Kewl/FFT, I'm a heavy user of libsodium, keep on the good work!

@jedisct1
Copy link
Contributor

You may remember Kewl/FFT

FUCK FRANCE TELECOM!

@jedisct1
Copy link
Contributor

Clang defines _MSC_VER on Windows, so it applies there as well.

Ah ok. But that just indicates that these headers are present, it doesn't enable compiler features.

@kasperisager
Copy link
Contributor Author

I'm not sure that LLVM agrees as it refuses to compile the code on Windows without those features being explicitly enabled using the corresponding -m flags.

@kasperisager
Copy link
Contributor Author

It actually looks like an already known bug in Clang: llvm/llvm-project#53520

@kasperisager
Copy link
Contributor Author

@jedisct1 Everything seems to be compiling correctly now, thanks so much for the assistance! The only remaining issue, which may very well be a non-issue, is some warnings emitted when compiling for Windows:

D:\a\sodium-native\sodium-native\vendor\libsodium\src\libsodium\crypto_aead\aes256gcm\aesni\aead_aes256gcm_aesni.c(447,13): warning: passing 'const unsigned char *' to parameter of type 'const char *' converts between pointers to integer types where one is of the unique plain 'char' type and the other is not [-Wpointer-sign]
  447 |             PREFETCH_READ(src + i + PARALLEL_BLOCKS * 16);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D:\a\sodium-native\sodium-native\vendor\libsodium\src\libsodium\crypto_aead\aes256gcm\aesni\aead_aes256gcm_aesni.c(66,49): note: expanded from macro 'PREFETCH_READ'
   66 | #define PREFETCH_READ(x)           _mm_prefetch((x), _MM_HINT_T1)
      |                                                 ^~~
D:\a\sodium-native\sodium-native\vendor\libsodium\src\libsodium\crypto_aead\aes256gcm\aesni\aead_aes256gcm_aesni.c(449,13): warning: passing 'const unsigned char *' to parameter of type 'const char *' converts between pointers to integer types where one is of the unique plain 'char' type and the other is not [-Wpointer-sign]
  449 |             PREFETCH_READ(src + i + PARALLEL_BLOCKS * 16 + 64);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D:\a\sodium-native\sodium-native\vendor\libsodium\src\libsodium\crypto_aead\aes256gcm\aesni\aead_aes256gcm_aesni.c(66,49): note: expanded from macro 'PREFETCH_READ'
   66 | #define PREFETCH_READ(x)           _mm_prefetch((x), _MM_HINT_T1)
      |                                                 ^~~
D:\a\sodium-native\sodium-native\vendor\libsodium\src\libsodium\crypto_aead\aes256gcm\aesni\aead_aes256gcm_aesni.c(462,13): warning: passing 'const unsigned char *' to parameter of type 'const char *' converts between pointers to integer types where one is of the unique plain 'char' type and the other is not [-Wpointer-sign]
  462 |             PREFETCH_READ(src + i + 2 * PARALLEL_BLOCKS * 16);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D:\a\sodium-native\sodium-native\vendor\libsodium\src\libsodium\crypto_aead\aes256gcm\aesni\aead_aes256gcm_aesni.c(66,49): note: expanded from macro 'PREFETCH_READ'
   66 | #define PREFETCH_READ(x)           _mm_prefetch((x), _MM_HINT_T1)
      |                                                 ^~~
D:\a\sodium-native\sodium-native\vendor\libsodium\src\libsodium\crypto_aead\aes256gcm\aesni\aead_aes256gcm_aesni.c(464,13): warning: passing 'const unsigned char *' to parameter of type 'const char *' converts between pointers to integer types where one is of the unique plain 'char' type and the other is not [-Wpointer-sign]
  464 |             PREFETCH_READ(src + i + 2 * PARALLEL_BLOCKS * 16 + 64);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D:\a\sodium-native\sodium-native\vendor\libsodium\src\libsodium\crypto_aead\aes256gcm\aesni\aead_aes256gcm_aesni.c(66,49): note: expanded from macro 'PREFETCH_READ'
   66 | #define PREFETCH_READ(x)           _mm_prefetch((x), _MM_HINT_T1)
      |                                                 ^~~
D:\a\sodium-native\sodium-native\vendor\libsodium\src\libsodium\crypto_aead\aes256gcm\aesni\aead_aes256gcm_aesni.c(806,5): warning: passing 'unsigned char *' to parameter of type 'const char *' converts between pointers to integer types where one is of the unique plain 'char' type and the other is not [-Wpointer-sign]
  806 |     PREFETCH_WRITE(c);
      |     ^~~~~~~~~~~~~~~~~
D:\a\sodium-native\sodium-native\vendor\libsodium\src\libsodium\crypto_aead\aes256gcm\aesni\aead_aes256gcm_aesni.c(67,49): note: expanded from macro 'PREFETCH_WRITE'
   67 | #define PREFETCH_WRITE(x)          _mm_prefetch((x), _MM_HINT_T1)
      |                                                 ^~~
D:\a\sodium-native\sodium-native\vendor\libsodium\src\libsodium\crypto_aead\aes256gcm\aesni\aead_aes256gcm_aesni.c(807,5): warning: passing 'const unsigned char *' to parameter of type 'const char *' converts between pointers to integer types where one is of the unique plain 'char' type and the other is not [-Wpointer-sign]
  807 |     PREFETCH_READ(m);
      |     ^~~~~~~~~~~~~~~~
D:\a\sodium-native\sodium-native\vendor\libsodium\src\libsodium\crypto_aead\aes256gcm\aesni\aead_aes256gcm_aesni.c(66,49): note: expanded from macro 'PREFETCH_READ'
   66 | #define PREFETCH_READ(x)           _mm_prefetch((x), _MM_HINT_T1)
      |                                                 ^~~
D:\a\sodium-native\sodium-native\vendor\libsodium\src\libsodium\crypto_aead\aes256gcm\aesni\aead_aes256gcm_aesni.c(808,5): warning: passing 'const unsigned char *' to parameter of type 'const char *' converts between pointers to integer types where one is of the unique plain 'char' type and the other is not [-Wpointer-sign]
  808 |     PREFETCH_READ(ad);
      |     ^~~~~~~~~~~~~~~~~
D:\a\sodium-native\sodium-native\vendor\libsodium\src\libsodium\crypto_aead\aes256gcm\aesni\aead_aes256gcm_aesni.c(66,49): note: expanded from macro 'PREFETCH_READ'
   66 | #define PREFETCH_READ(x)           _mm_prefetch((x), _MM_HINT_T1)
      |                                                 ^~~
D:\a\sodium-native\sodium-native\vendor\libsodium\src\libsodium\crypto_aead\aes256gcm\aesni\aead_aes256gcm_aesni.c(973,5): warning: passing 'unsigned char *' to parameter of type 'const char *' converts between pointers to integer types where one is of the unique plain 'char' type and the other is not [-Wpointer-sign]
  973 |     PREFETCH_WRITE(m);
      |     ^~~~~~~~~~~~~~~~~
D:\a\sodium-native\sodium-native\vendor\libsodium\src\libsodium\crypto_aead\aes256gcm\aesni\aead_aes256gcm_aesni.c(67,49): note: expanded from macro 'PREFETCH_WRITE'
   67 | #define PREFETCH_WRITE(x)          _mm_prefetch((x), _MM_HINT_T1)
      |                                                 ^~~
D:\a\sodium-native\sodium-native\vendor\libsodium\src\libsodium\crypto_aead\aes256gcm\aesni\aead_aes256gcm_aesni.c(974,5): warning: passing 'const unsigned char *' to parameter of type 'const char *' converts between pointers to integer types where one is of the unique plain 'char' type and the other is not [-Wpointer-sign]
  974 |     PREFETCH_READ(c);
      |     ^~~~~~~~~~~~~~~~
D:\a\sodium-native\sodium-native\vendor\libsodium\src\libsodium\crypto_aead\aes256gcm\aesni\aead_aes256gcm_aesni.c(66,49): note: expanded from macro 'PREFETCH_READ'
   66 | #define PREFETCH_READ(x)           _mm_prefetch((x), _MM_HINT_T1)
      |                                                 ^~~
D:\a\sodium-native\sodium-native\vendor\libsodium\src\libsodium\crypto_aead\aes256gcm\aesni\aead_aes256gcm_aesni.c(975,5): warning: passing 'const unsigned char *' to parameter of type 'const char *' converts between pointers to integer types where one is of the unique plain 'char' type and the other is not [-Wpointer-sign]
  975 |     PREFETCH_READ(ad);
      |     ^~~~~~~~~~~~~~~~~
D:\a\sodium-native\sodium-native\vendor\libsodium\src\libsodium\crypto_aead\aes256gcm\aesni\aead_aes256gcm_aesni.c(66,49): note: expanded from macro 'PREFETCH_READ'
   66 | #define PREFETCH_READ(x)           _mm_prefetch((x), _MM_HINT_T1)
      |                                                 ^~~
D:\a\sodium-native\sodium-native\vendor\libsodium\src\libsodium\crypto_aead\aes256gcm\aesni\aead_aes256gcm_aesni.c(992,5): warning: passing 'unsigned char *' to parameter of type 'const char *' converts between pointers to integer types where one is of the unique plain 'char' type and the other is not [-Wpointer-sign]
  992 |     PREFETCH_WRITE(m);
      |     ^~~~~~~~~~~~~~~~~
D:\a\sodium-native\sodium-native\vendor\libsodium\src\libsodium\crypto_aead\aes256gcm\aesni\aead_aes256gcm_aesni.c(67,49): note: expanded from macro 'PREFETCH_WRITE'
   67 | #define PREFETCH_WRITE(x)          _mm_prefetch((x), _MM_HINT_T1)
      |                                                 ^~~
D:\a\sodium-native\sodium-native\vendor\libsodium\src\libsodium\crypto_aead\aes256gcm\aesni\aead_aes256gcm_aesni.c(993,5): warning: passing 'const unsigned char *' to parameter of type 'const char *' converts between pointers to integer types where one is of the unique plain 'char' type and the other is not [-Wpointer-sign]
  993 |     PREFETCH_READ(c);
      |     ^~~~~~~~~~~~~~~~
D:\a\sodium-native\sodium-native\vendor\libsodium\src\libsodium\crypto_aead\aes256gcm\aesni\aead_aes256gcm_aesni.c(66,49): note: expanded from macro 'PREFETCH_READ'
   66 | #define PREFETCH_READ(x)           _mm_prefetch((x), _MM_HINT_T1)
      |                                                 ^~~
D:\a\sodium-native\sodium-native\vendor\libsodium\src\libsodium\crypto_aead\aes256gcm\aesni\aead_aes256gcm_aesni.c(994,5): warning: passing 'const unsigned char *' to parameter of type 'const char *' converts between pointers to integer types where one is of the unique plain 'char' type and the other is not [-Wpointer-sign]
  994 |     PREFETCH_READ(ad);
      |     ^~~~~~~~~~~~~~~~~
D:\a\sodium-native\sodium-native\vendor\libsodium\src\libsodium\crypto_aead\aes256gcm\aesni\aead_aes256gcm_aesni.c(66,49): note: expanded from macro 'PREFETCH_READ'
   66 | #define PREFETCH_READ(x)           _mm_prefetch((x), _MM_HINT_T1)
      |                                                 ^~~
13 warnings generated.

@kasperisager kasperisager mentioned this pull request Oct 31, 2024
@kasperisager
Copy link
Contributor Author

Superseded by #207.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants