randombit / botan

Cryptography Toolkit
https://botan.randombit.net
BSD 2-Clause "Simplified" License
2.6k stars 570 forks source link

Add Sun Studio x86 ISAs #846

Closed noloader closed 7 years ago

noloader commented 7 years ago

This little patch gets Botan past configuration issues when using Sun Studio.

$ cat sunstudio.diff
diff --git a/src/build-data/cc/sunstudio.txt b/src/build-data/cc/sunstudio.txt
index 9ace5107c..64618792a 100644
--- a/src/build-data/cc/sunstudio.txt
+++ b/src/build-data/cc/sunstudio.txt
@@ -54,3 +54,18 @@ linux      -> "-library=stlport4"
 sparc64    -> "-xarch=v9"
 x86_64     -> "-m64"
 </mach_abi_linking>
+
+<isa_flags>
+# Botan needs C++11, and that requires Sun Studio 12.4 or above.
+#  Sun Studio 12.4 supports upto -xarch=avx2, but the processor must support it
+#  AESNI requires -xarch=aes, and RDRAND requires -xarch=avx_i.
+#  https://docs.oracle.com/cd/E37069_01/html/E37074/bjapp.html#OSSCGbkazd
+sse2       -> "-xarch=sse2"
+ssse3      -> "-xarch=ssse3"
+sse4.1     -> "-xarch=sse4_1"
+sse4.2     -> "-xarch=sse4_2"
+aes        -> "-xarch=aes"
+avx        -> "-xarch=avx"
+avx_i      -> "-xarch=avx_i"
+avx2       -> "-xarch=avx2"
+</isa_flags>

solaris:botan$ ./configure.py --cc=sunstudio --cpu=x86_64 --cc-bin=/opt/solarisstudio12.4/bin/CC --cc-abi="-std=c++11"
   INFO: ./configure.py invoked with options "--cc=sunstudio --cpu=x86_64 --cc-bin=/opt/solarisstudio12.4/bin/CC --cc-abi=-std=c++11"
   INFO: Platform: OS="SunOS" machine="i86pc" proc="i386"
   INFO: Guessing target OS is sunos (use --os to set)
   INFO: Canonicalizized CPU target x86_64 to x86_64/x86_64
   INFO: Target is sunstudio-solaris-x86_64-x86_64
   INFO: Skipping, dependency failure - certstor_sqlite3 rdrand sessions_sqlite3
   INFO: Skipping, incompatible OS - cryptoapi_rng darwin_secrandom locking_allocator win32_stats
   INFO: Skipping, incompatible compiler - aes_ni clmul rdrand_rng rdseed
   INFO: Skipping, no enabled compression schemes - compression
   INFO: Skipping, requires external dependency - boost bzip2 lzma openssl sqlite3 tpm zlib
   INFO: Loading modules adler32 aead aes aes_ssse3 aont asn1 auto_rng base base64 bcrypt bigint blake2 block blowfish camellia cascade cast cbc cbc_mac ccm cecpq1 certstor_sql cfb chacha chacha20poly1305 chacha_sse2 cmac codec_filt comb4p crc24 crc32 cryptobox ctr curve25519 des dev_random dh dl_algo dl_group dlies dsa dyn_load eax ec_gfp ec_group ecc_key ecdh ecdsa ecgdsa ecies eckcdsa elgamal eme_oaep eme_pkcs1 eme_raw emsa1 emsa_pkcs1 emsa_pssr emsa_raw emsa_x931 entropy fd_unix ffi filters fpe_fe1 gcm gmac gost_28147 gost_3410 gost_3411 hash hash_id hex hkdf hmac hmac_drbg http_util idea idea_sse2 iso9796 kasumi kdf kdf1 kdf1_iso18033 kdf2 keccak keypair lion mac mce mceies md4 md5 mdx_hash mgf1 misty1 mode_pad modes mp newhope noekeon noekeon_simd numbertheory ocb ofb par_hash passhash9 pbes2 pbkdf pbkdf1 pbkdf2 pem pk_pad pkcs11 poly1305 prf_tls prf_x942 proc_walk pubkey rc4 rfc3394 rfc6979 rmd160 rng rsa salsa20 seed serpent serpent_simd sessions_sql sha1 sha1_sse2 sha2_32 sha2_64 sha3 shake shake_cipher simd siphash siv skein sp800_108 sp800_56c srp6 stateful_rng stream system_rng threefish threefish_avx2 tiger tls tls_cbc tss twofish utils whirlpool x509 x919_mac xmss xtea xts
   INFO: Assuming CPU is little endian
   INFO: Assuming unaligned memory access works
   INFO: Using symlink to link files into build dir (use --link-method to change)
   INFO: Botan 2.0.1 (VC git:bdb811a87255920dc672e3d6ea08793a95736422) (unreleased undated) build setup is complete
solaris:botan$
randombit commented 7 years ago

Thanks. The error you were seeing was bogus, I've changed configure so it handles not knowing how to enable the compiler ISA extensions nicely, without stopping the entire build. (In addition to merging your patch of course)

noloader commented 7 years ago

Awesome, thanks @randombit.

The support is starting to pay off. The SunCC compiler is raising issues with some of the code. I've found when SunCC complains, usually you are in an area that's implementation specific, and it may not be portable or produce consistent results. Once the SunCC issues are cleared, the piece of code will be good on all platforms and compilers.

(I've also found a handful of SunCC bugs that are awful to work around).