randombit / botan

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

ARM64-v8a compiler error when amalgamation and armv8crypto is used #3774

Closed Trafo closed 6 days ago

Trafo commented 1 year ago

I am trying to make the botan Conan recipe compatible with Android and Emscripten. There I got the issue, that I could not build the Android ARM64-v8a version with amalgamation, because of compiler errors. If I deactivate it, everything builds.

Console output:

(linux) INFO: Downloading conan_sources.tgz
(linux) INFO: botan/3.2.0-emscripten@conan-pkg+botan/testa: Configuring sources in /builds/llt-at-nordlocker/ncrypto/.cache/.conan/data/botan/3.2.0-emscripten/conan-pkg+botan/testa/source/src
(linux) INFO: botan/3.2.0-emscripten@conan-pkg+botan/testa:
(linux) INFO: botan/3.2.0-emscripten@conan-pkg+botan/testa: Copying sources to build folder
(linux) INFO: botan/3.2.0-emscripten@conan-pkg+botan/testa: Building your package in /builds/llt-at-nordlocker/ncrypto/.cache/.conan/data/botan/3.2.0-emscripten/conan-pkg+botan/testa/build/c2911c17b898bcf0bfa856abf449c956bafd6e6b
(linux) INFO: botan/3.2.0-emscripten@conan-pkg+botan/testa: Generator txt created conanbuildinfo.txt
(linux) INFO: botan/3.2.0-emscripten@conan-pkg+botan/testa: Calling generate()
(linux) INFO: botan/3.2.0-emscripten@conan-pkg+botan/testa: Aggregating env generators
(linux) INFO: botan/3.2.0-emscripten@conan-pkg+botan/testa: Calling build()
(linux) INFO: botan/3.2.0-emscripten@conan-pkg+botan/testa: Apply patch (portability): Use WASM esxceptions instead of Emscripten emulation
(linux) INFO:    INFO: ./configure.py invoked with options "--build-targets=static --distribution-info=Conan --without-documentation --cc-abi-flags=  --extra-cxxflags=-fPIC -I /opt/android-ndk-r26-beta1/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/aarch64-linux-android -isysroot /opt/android-ndk-r26-beta1/toolchains/llvm/prebuilt/linux-x86_64/sysroot --cc=clang --cpu=armv8 --prefix=/builds/llt-at-nordlocker/ncrypto/.cache/.conan/data/botan/3.2.0-emscripten/conan-pkg+botan/testa/package/c2911c17b898bcf0bfa856abf449c956bafd6e6b --os=android --cc-bin=/opt/android-ndk-r26-beta1/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang++ --amalgamation --debug-mode --without-pkg-config"
(linux) INFO:    INFO: Configuring to build Botan 3.2.0 (revision git:f15078e0eca9e2277955b16947d57f76302ec884)
(linux) INFO:    INFO: Python version: "3.11.4 (main, Jun  9 2023, 07:59:55) [GCC 12.3.0]"
(linux) INFO:    INFO: Autodetected platform information: OS="Linux" machine="x86_64" proc="x86_64"
(linux) INFO:    INFO: Using /etc/ssl/certs/ca-certificates.crt as system certificate store
(linux) INFO:    INFO: Canonicalized CPU target armv8 to arm64
(linux) INFO:    INFO: Auto-detected compiler version clang 17.0
(linux) INFO:    INFO: Auto-detected compiler arch arm64
(linux) INFO:    INFO: Target is clang:17.0-android-arm64
(linux) INFO:    INFO: Assuming target arm64 is little endian
(linux) INFO:    INFO: Skipping (dependency failure): asio certstor_sqlite3 sessions_sqlite3
(linux) INFO:    INFO: Skipping (incompatible CPU): aes_ni aes_power8 argon2_avx2 argon2_ssse3 chacha_avx2 chacha_avx512 ghash_vperm idea_sse2 keccak_perm_bmi2 processor_rng rdseed serpent_avx2 serpent_avx512 sha1_sse2 sha1_x86 sha2_32_bmi2 sha2_32_x86 sha2_64_bmi2 shacal2_avx2 shacal2_x86 simd_avx2 simd_avx512 zfec_sse2
(linux) INFO:    INFO: Skipping (incompatible OS): certstor_system_macos certstor_system_windows commoncrypto getentropy win32_stats
(linux) INFO:    INFO: Skipping (incompatible compiler): sm4_armv8
(linux) INFO:    INFO: Skipping (no enabled compression schemes): compression
(linux) INFO:    INFO: Skipping (requires external dependency): boost bzip2 lzma sqlite3 tpm zlib
(linux) INFO:    INFO: Loading modules: adler32 aead aes aes_armv8 aes_crystals_xof aes_vperm argon2 argon2fmt aria asn1 auto_rng base base32 base58 base64 bcrypt bcrypt_pbkdf bigint blake2 blake2mac block blowfish camellia cascade cast128 cbc ccm certstor_flatfile certstor_sql certstor_system cfb chacha chacha20poly1305 chacha_rng chacha_simd32 checksum cmac comb4p cpuid crc24 crc32 cryptobox cshake_xof ctr curve25519 des dh dilithium dilithium_aes dilithium_common dl_algo dl_group dlies dsa dyn_load eax ec_group ec_h2c ecc_key ecdh ecdsa ecgdsa ecies eckcdsa ed25519 elgamal eme_oaep eme_pkcs1 eme_raw emsa_pkcs1 emsa_pssr emsa_raw emsa_x931 entropy fd_unix ffi filters fpe_fe1 gcm ghash ghash_cpu gmac gost_28147 gost_3410 gost_3411 hash hash_id hex hkdf hmac hmac_drbg hotp http_util idea iso9796 kdf kdf1 kdf1_iso18033 kdf2 keccak keccak_perm keypair kmac kuznyechik kyber kyber_90s kyber_common lion locking_allocator mac mce md4 md5 mdx_hash mem_pool mgf1 mode_pad modes mp nist_keywrap noekeon noekeon_simd numbertheory ocb ofb par_hash passhash9 pbes2 pbkdf pbkdf2 pem pgp_s2k pk_pad pkcs11 poly1305 poly_dbl prf_tls prf_x942 psk_db pubkey raw_hash rc4 rfc3394 rfc6979 rmd160 rng roughtime rsa salsa20 scrypt seed serpent serpent_simd sessions_sql sha1 sha1_armv8 sha2_32 sha2_32_armv8 sha2_64 sha3 shacal2 shacal2_armv8 shacal2_simd shake shake_cipher shake_xof simd siphash siv skein sm2 sm3 sm4 socket sodium sp800_108 sp800_56a sp800_56c sphincsplus_common sphincsplus_sha2 sphincsplus_shake srp6 stateful_rng stream streebog system_rng thread_utils threefish_512 tls tls12 tls13 tls13_pqc tls_cbc trunc_hash tss twofish utils uuid whirlpool x509 x919_mac xmss xof xts zfec zfec_vperm
(linux) INFO:    INFO: Using symlink to link files into build dir (use --link-method to change)
(linux) INFO:    INFO: Writing amalgamation header to botan_all.h
(linux) INFO:    INFO: Writing amalgamation source to botan_all.cpp
(linux) INFO:    INFO: Botan 3.2.0 (revision git:f15078e0eca9e2277955b16947d57f76302ec884) (unreleased undated) build setup is complete
(linux) INFO: /opt/android-ndk-r26-beta1/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang++  -fstack-protector -pthread   -std=c++20 -D_REENTRANT  -g -fPIC -I /opt/android-ndk-r26-beta1/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/aarch64-linux-android -isysroot /opt/android-ndk-r26-beta1/toolchains/llvm/prebuilt/linux-x86_64/sysroot -DBOTAN_IS_BEING_BUILT -Wall -Wextra -Wpedantic -Wshadow -Wstrict-aliasing -Wstrict-overflow=5 -Wcast-align -Wmissing-declarations -Wpointer-arith -Wcast-qual -Wshorten-64-to-32 -Wcomma -Wdocumentation  -I build/include -isystem build/include/external -c botan_all.cpp -o build/obj/lib/botan_all.o
(linux) INFO: botan_all.cpp:22247:20: error: always_inline function 'vaesdq_u8' requires target feature 'aes', but would be inlined into function 'hw_aes_decrypt_n' that is compiled without support for 'aes'
(linux) INFO:       B = veorq_u8(vaesdq_u8(B, K9), K10);
(linux) INFO:                    ^
(linux) INFO: botan_all.cpp:22316:20: error: always_inline function 'vaeseq_u8' requires target feature 'aes', but would be inlined into function 'hw_aes_encrypt_n' that is compiled without support for 'aes'
(linux) INFO:       B = veorq_u8(vaeseq_u8(B, K11), K12);
(linux) INFO:                    ^
(linux) INFO: botan_all.cpp:22385:20: error: always_inline function 'vaesdq_u8' requires target feature 'aes', but would be inlined into function 'hw_aes_decrypt_n' that is compiled without support for 'aes'
(linux) INFO:       B = veorq_u8(vaesdq_u8(B, K11), K12);
(linux) INFO:                    ^
(linux) INFO: botan_all.cpp:22462:20: error: always_inline function 'vaeseq_u8' requires target feature 'aes', but would be inlined into function 'hw_aes_encrypt_n' that is compiled without support for 'aes'
(linux) INFO:       B = veorq_u8(vaeseq_u8(B, K13), K14);
(linux) INFO:                    ^
(linux) INFO: botan_all.cpp:22537:20: error: always_inline function 'vaesdq_u8' requires target feature 'aes', but would be inlined into function 'hw_aes_decrypt_n' that is compiled without support for 'aes'
(linux) INFO:       B = veorq_u8(vaesdq_u8(B, K13), K14);
(linux) INFO:                    ^
(linux) INFO: 5 errors generated.
(linux) INFO: make: *** [Makefile:102: build/obj/lib/botan_all.o] Error 1

[EDIT] We will go without amalgamation, so that's why we are fine, but in the conan recipe this is the default value for using it, why I wanted to report it.

randombit commented 1 year ago

Thanks for reporting

lieser commented 1 year ago

The aes_armv8 module gets enabled which requires the isa armv8crypto. But the -march=armv8+crypto does not get automatically added to the compilation of botan_all.cpp.

I thinks this relates to #2246. Before that PR multiple cpp files for different isa there added. Unsure what the best way to fix this is as I'm not much experienced with this flags.

Some things are unclear to me and some observations:

reneme commented 9 months ago

I believe #3931 (finally) resolves this. Feedback on it would be highly appreciated. 😃

Trafo commented 6 days ago

Thank you very much for your support, it has been fixed since Botan 3.5.0.