randombit / botan

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

Compile error on PPC64 #2226

Closed dharanlinux closed 4 years ago

dharanlinux commented 4 years ago

Both Power8 and Power9 support is default add to ppc64 architecture. I am using NXP powerpc processor (cpu e6500).

Configure output: INFO: Autodetected platform information: OS="Linux" machine="x86_64" proc="x86_64" INFO: Using /etc/ssl/certs/ca-certificates.crt as system certificate store INFO: Canonicalized CPU target powerpc64 to ppc64 INFO: Auto-detected compiler version 5.5 INFO: Auto-detected compiler arch ppc64 INFO: Target is gcc:5.5-linux-ppc64 INFO: Assuming target ppc64 is big endian INFO: Skipping (dependency failure): asio certstor_sqlite3 rdrand sessions_sqlite3 INFO: Skipping (disabled by user): boost bzip2 lzma sqlite3 tpm INFO: Skipping (incompatible CPU): aes_armv8 aes_ni aes_vperm chacha_avx2 clmul_cpu clmul_ssse3 idea_sse2 rdrand_rng rdseed serpent_avx2 sha1_armv8 sha1_sse2 sha1_x86 sha2_32_armv8 sha2_32_bmi2 sha2_32_x86 sha2_64_bmi2 sha3_bmi2 shacal2_x86 simd_avx2 sm4_armv8 threefish_512_avx2 INFO: Skipping (incompatible OS): certstor_system_macos certstor_system_windows commoncrypto getentropy win32_stats INFO: Enabling use of external dependency openssl INFO: Enabling use of external dependency zlib INFO: Loading modules: adler32 aead aes aes_power8 aont argon2 aria asn1 auto_rng base base32 base58 base64 bcrypt bcrypt_pbkdf bigint blake2 block blowfish camellia cascade cast128 cast256 cbc cbc_mac ccm cecpq1 certstor_flatfile certstor_sql certstor_system cfb chacha chacha20poly1305 chacha_rng chacha_simd32 checksum cmac codec_filt comb4p compression cpuid crc24 crc32 cryptobox ctr curve25519 des dev_random dh dl_algo dl_group dlies dsa dyn_load eax ec_group ecc_key ecdh ecdsa ecgdsa ecies eckcdsa ed25519 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 hotp http_util idea iso9796 kasumi kdf kdf1 kdf1_iso18033 kdf2 keccak keypair lion locking_allocator mac mce mceies md4 md5 mdx_hash mem_pool mgf1 misty1 mode_pad modes mp newhope nist_keywrap noekeon noekeon_simd numbertheory ocb ofb openssl p9_darn par_hash passhash9 pbes2 pbkdf pbkdf1 pbkdf2 pem pgp_s2k pk_pad pkcs11 poly1305 poly_dbl prf_tls prf_x942 proc_walk psk_db pubkey rc4 rfc3394 rfc6979 rmd160 rng rsa salsa20 scrypt seed serpent serpent_simd sessions_sql sha1 sha2_32 sha2_64 sha3 shacal2 shacal2_simd shake shake_cipher simd siphash siv skein sm2 sm3 sm4 socket sodium sp800_108 sp800_56a sp800_56c srp6 stateful_rng stream streebog system_rng thread_utils threefish_512 tiger tls tls_cbc tss twofish utils uuid whirlpool x509 x919_mac xmss xtea xts zlib INFO: Using symlink to link files into build dir (use --link-method to change) INFO: Botan 2.12.1 (revision git:1a6ad661ce64287ccbe26460ccc3aa4247d86ba8) (release dated 20191014) build setup is complete

Error log: src/lib/block/aes/aes_power8/aes_power8.cpp:115:82: error: target attribute or pragma changes single precision floating point void AES_128::power8_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const ^ src/lib/block/aes/aes_power8/aes_power8.cpp:115:82: error: target attribute or pragma changes double precision floating point src/lib/block/aes/aes_power8/aes_power8.cpp:115:82: error: target attribute or pragma changes single precision floating point src/lib/block/aes/aes_power8/aes_power8.cpp:115:82: error: target attribute or pragma changes double precision floating point src/lib/block/aes/aes_power8/aes_power8.cpp:179:82: error: target attribute or pragma changes single precision floating point void AES_128::power8_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const

So power8 support is added here. To overcome this issue, added the "--cc-abi-flags='-mcpu=power8 -mtune=power8'" in configure (but my target cpu is e6500) and facing below issue:

Error log: {standard input}: Assembler messages: {standard input}:850: Error: unrecognized opcode: `darn' make[1]: *** [build/obj/lib/entropy_p9_darn.o] Error 1

randombit commented 4 years ago

Thanks for the report. I think enabling POWER8 code generation here will not get you the result you want since my understanding is the E6500 does not have any of the ISA additions from POWER8/POWER9, so even if it built the code would not execute correctly.

Right now there is no convenient flag to disable POWER ISA additions. TBH the only PPC machines I have access to are POWER7/8/9 so other CPUs of this type are untested by me. But if you use --disable-modules=aes_power8,p9_darn (and drop the -mcpu,-mtune flags) that will disable use of the POWER instructions that are currently in use. I will make some changes so this is more convenient in future releases.

randombit commented 4 years ago

With #2227 you can now use configure.py option --disable-powercrypto which disables all uses of these POWER specific instructions, that will be included in 2.13.

I believe the previous suggestion to disable the use of POWER8 AES and POWER9 DARN works for 2.12. Please feel free to reopen if you are still having problems.

dharanlinux commented 3 years ago

I could able to build the Botan-2.12.1 for E6500 target with --disable-modules='aes_power8,p9_darn'.

But while I am using the Botan-2.18.1 for the same target with '--disable-powercrypto', facing the below build issue.

Configure output:

INFO: Autodetected platform information: OS="Linux" machine="x86_64" proc="x86_64" INFO: Using /etc/ssl/certs/ca-certificates.crt as system certificate store INFO: Canonicalized CPU target powerpc64 to ppc64 INFO: Auto-detected compiler version 5.5 INFO: Auto-detected compiler arch ppc64 INFO: Target is gcc:5.5-linux-ppc64 INFO: Assuming target ppc64 is big endian INFO: Skipping (incompatible CPU): aes_armv8 aes_ni aes_power8 aes_vperm chacha_avx2 ghash_cpu ghash_vperm idea_sse2 rdrand_rng rdseed serpent_avx2 sha1_armv8 sha1_sse2 sha1_x86 sha2_32_armv8 sha2_32_bmi2 sha2_32_x86 sha2_64_bmi2 sha3_bmi2 shacal2_avx2 shacal2_x86 simd_avx2 sm4_armv8 threefish_512_avx2 INFO: Skipping (incompatible OS): certstor_system_macos certstor_system_windows commoncrypto getentropy win32_stats INFO: Enabling use of external dependency boost INFO: Enabling use of external dependency bzip2 INFO: Enabling use of external dependency lzma INFO: Enabling use of external dependency openssl INFO: Enabling use of external dependency sqlite3 INFO: Enabling use of external dependency tpm INFO: Enabling use of external dependency zlib INFO: Loading modules: adler32 aead aes aont argon2 aria asio asn1 auto_rng base base32 base58 base64 bcrypt bcrypt_pbkdf bigint blake2 block blowfish boost bzip2 camellia cascade cast128 cast256 cbc cbc_mac ccm cecpq1 certstor_flatfile certstor_sql certstor_sqlite3 certstor_system cfb chacha chacha20poly1305 chacha_rng chacha_simd32 checksum cmac comb4p compression cpuid crc24 crc32 cryptobox ctr curve25519 des dev_random dh dl_algo dl_group dlies dsa dyn_load eax ec_group ecc_key ecdh ecdsa ecgdsa ecies eckcdsa ed25519 elgamal eme_oaep eme_pkcs1 eme_raw emsa1 emsa_pkcs1 emsa_pssr emsa_raw emsa_x931 entropy fd_unix ffi filters fpe_fe1 gcm ghash gmac gost_28147 gost_3410 gost_3411 hash hash_id hex hkdf hmac hmac_drbg hotp http_util idea iso9796 kasumi kdf kdf1 kdf1_iso18033 kdf2 keccak keypair lion locking_allocator lzma mac mce mceies md4 md5 mdx_hash mem_pool mgf1 misty1 mode_pad modes mp newhope nist_keywrap noekeon noekeon_simd numbertheory ocb ofb openssl par_hash passhash9 pbes2 pbkdf pbkdf1 pbkdf2 pem pgp_s2k pk_pad pkcs11 poly1305 poly_dbl prf_tls prf_x942 proc_walk processor_rng psk_db pubkey rc4 rfc3394 rfc6979 rmd160 rng roughtime rsa salsa20 scrypt seed serpent serpent_simd sessions_sql sessions_sqlite3 sha1 sha2_32 sha2_64 sha3 shacal2 shacal2_simd shake shake_cipher simd siphash siv skein sm2 sm3 sm4 socket sodium sp800_108 sp800_56a sp800_56c sqlite3 srp6 stateful_rng stream streebog system_rng thread_utils threefish_512 tiger tls tls_10 tls_cbc tpm tss twofish utils uuid whirlpool x509 x919_mac xmss xtea xts zlib INFO: Using symlink to link files into build dir (use --link-method to change) INFO: Botan 2.18.1 (revision git:d4bd416702a65eddcc14ee06b9c1b674631e6ae3) (release dated 20210509) build setup is complete

Build error:

D_REENTRANT -Os -g -pipe -DBOTAN_IS_BEING_BUILT -Wall -Wextra -Wpedantic -Wstrict-aliasing -Wcast-align -Wmissing-declarations -Wpointer-arith -Wcast-qual -Wzero-as-null-pointer-constant -Wnon-virtual-dtor -Ibuild/include -Ibuild/include/external -c src/lib/block/serpent/serpent.cpp -o build/obj/lib/block_serpent.o In file included from build/include/botan/build.h:449:0, from build/include/botan/types.h:13, from build/include/botan/secmem.h:11, from build/include/botan/symkey.h:11, from build/include/botan/sym_algo.h:11, from build/include/botan/block_cipher.h:11, from build/include/botan/noekeon.h:11, from src/lib/block/noekeon/noekeon_simd/noekeon_simd.cpp:8: build/include/botan/compiler.h:75:59: error: target attribute or pragma changes single precision floating point

define BOTAN_FUNC_ISA(isa) attribute ((target(isa)))

                                                       ^

build/include/botan/internal/simd_32.h:612:36: note: in expansion of macro 'BOTAN_FUNC_ISA' native_simd_type raw() const BOTAN_FUNC_ISA(BOTAN_SIMD_ISA) { return m_simd; } ^ build/include/botan/compiler.h:75:59: error: target attribute or pragma changes double precision floating point

define BOTAN_FUNC_ISA(isa) attribute ((target(isa)))

                                                       ^

build/include/botan/internal/simd_32.h:612:36: note: in expansion of macro 'BOTAN_FUNC_ISA' native_simd_type raw() const BOTAN_FUNC_ISA(BOTAN_SIMD_ISA) { return m_simd; } ^ build/include/botan/compiler.h:75:59: error: target attribute or pragma changes single precision floating point

define BOTAN_FUNC_ISA(isa) attribute ((target(isa)))

                                                       ^

build/include/botan/internal/simd_32.h:612:36: note: in expansion of macro 'BOTAN_FUNC_ISA' native_simd_type raw() const BOTAN_FUNC_ISA(BOTAN_SIMD_ISA) { return m_simd; } ^ build/include/botan/compiler.h:75:59: error: target attribute or pragma changes double precision floating point

define BOTAN_FUNC_ISA(isa) attribute ((target(isa)))

                                                       ^

build/include/botan/internal/simd_32.h:612:36: note: in expansion of macro 'BOTAN_FUNC_ISA' native_simd_type raw() const BOTAN_FUNC_ISA(BOTAN_SIMD_ISA) { return m_simd; } ^ make[1]: [build/obj/lib/block_noekeon_simd.o] Error 1 make[1]: Waiting for unfinished jobs....

randombit commented 3 years ago

Does E6500 not support VMX/AltiVec? I'm not sure what has changed since 2.12 also had VMX support but --disable-altivec might help

randombit commented 3 years ago

BTW commenting on closed issues is easy for me to miss, better to open a new issue

nefigtut commented 2 years ago

a necro-update to this issue (i've just hit the same so I want to share). recently gcc has limited DARN instruction to power9 target (and may be to others with ISA3.0), since Power9 CPUs are ISA3.0 and Power8 CPUs are ISA 2.07 and do not have DARN. A default gcc target on PPC64 is power8 as of now.

so a code with DARN ( with asm("DARN") or __builtin_darn()) fails to build with:

# gcc -m64 -o darn darn.c
/tmp/ccc8p8ZO.s: Assembler messages:
/tmp/ccc8p8ZO.s:85: Error: unrecognized opcode: `darn'

# gcc -m64 -mcpu=power8 -mtune=power8 -o darn darn.c
darn.c: In function ‘get_darn’:
darn.c:33:28: error: ‘__builtin_darn’ requires the ‘-mcpu=power9’ option
   33 |                 darn_val = __builtin_darn();

The solution is to explicitly set -mcpu=power9 -mtune=power9 for a code which uses DARN.

randombit commented 2 years ago

How are you building the library? On pcc64 targets, processor_rng.cpp should be getting built with -mcpu=power9

nefigtut commented 2 years ago

i don't. i've just hit an issue seemingly similar to this one and decided to share a research and a solution.