randombit / botan

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

Building botan on Windows using nmake: '_umul128': identifier not found error #456

Closed KarelGGIT closed 8 years ago

KarelGGIT commented 8 years ago

I have downloaded the tarball of botan, which has the next version: botan-1.11.28 (tested this too at 1.11.29 - see edit here below). To build the library, i have used the instructions outlined here.

I have issued the following commands on the developer console (Visual Studio 2015 CE 64 bit)

D:\build\botan-1.11.28>python configure.py --cc=msvc --prefix="D:\build\botan" --with-debug-info

This ran without problems. But when i issue nmake after that, I get an error.

D:\build\botan-1.11.28>nmake

Microsoft (R) Program Maintenance Utility Version 14.00.23506.0
Copyright (C) Microsoft Corporation.  All rights reserved.

        cl  /MDd /bigobj /DBOTAN_DLL=__declspec(dllexport) /EHs /GR /Zi /FS /O2 /W3 /wd4275 /wd4267 /Ibuild\include /nologo /c src\lib\asn1\alg_id.cpp /Fobuild\obj\lib\asn1_alg_id.obj
alg_id.cpp

        ... other successful cl runs

        cl  /MDd /bigobj /DBOTAN_DLL=__declspec(dllexport) /EHs /GR /Zi /FS /O2 /W3 /wd4275 /wd4267 /Ibuild\include /nologo /c src\lib\mac\poly1305\poly1305.cpp /Fobuild\obj\lib\mac_poly1305.obj
poly1305.cpp
D:\build\botan-1.11.28\build\include\botan/mul128.h(38): warning C4163: '_umul128': not available as an intrinsic function
D:\build\botan-1.11.28\build\include\botan/mul128.h(84): error C3861: '_umul128': identifier not found
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Visual Studio 14.0\VC\BIN\cl.EXE"' : return code '0x2'
Stop.

EDIT 1: The same problem occurs at the recent build, botan-1.11.29

Is this a known issue ? Is there a way to solve this ?

Oh, an other small question, is the build suitable for both 32 and 64 bit applications or 64 bit only ? It is not clear for me atm. Thank you.

Appendix: Here below is an outline of the output after running the python script (see the first code fragment here above). If you aren't interested in this, feel free to ignore it. It's just for those who wants to get more information.

D:\build\botan-1.11.28>python configure.py --cc=msvc --prefix="D:\build\botan" --with-debug-info
   INFO: Platform: OS="Windows" machine="AMD64" proc="Intel64 Family 6 Model 70 Stepping 1, GenuineIntel"
   INFO: Guessing target OS is windows (use --os to set)
   INFO: Guessing target processor is a x86_64/x86_64 (use --cpu to set)
   INFO: Target is msvc-windows-x86_64-x86_64
   INFO: Skipping, by request only - cvc
   INFO: Skipping, dependency failure - sessions_sqlite3
   INFO: Skipping, incompatible CPU - mp_x86_32_msvc
   INFO: Skipping, incompatible OS - beos_stats darwin_secrandom dev_random egd fd_unix proc_walk unix_procs
   INFO: Skipping, incompatible compiler - mp_x86_32 mp_x86_64 simd_altivec
   INFO: Skipping, loaded only if needed by dependency - dyn_load simd_scalar
   INFO: Skipping, requires external dependency - boost bzip2 lzma openssl sqlite3 tpm zlib
   INFO: Using MP module mp_generic
   INFO: Using SIMD module simd_sse2
   INFO: Loading modules adler32 aead aes aes_ni aes_ssse3 aont asn1 auto_rng base base64 bcrypt bigint blake2 block blowfish camellia cascade cast cbc cbc_mac ccm cfb chacha chacha20poly1305 clmul cmac codec_filt comb4p compression crc24 crc32 cryptoapi_rng cryptobox ctr curve25519 datastor des dh dl_algo dl_group dlies dsa eax ec_gfp ec_group ecb ecc_key ecdh ecdsa elgamal eme_oaep eme_pkcs1 eme_raw emsa1 emsa1_bsi emsa_pkcs1 emsa_pssr emsa_raw emsa_x931 entropy ffi filters fpe_fe1 gcm gost_28147 gost_3410 gost_3411 has160 hash hash_id hex hkdf hmac hmac_drbg hmac_rng hres_timer http_util idea idea_sse2 if_algo kasumi kdf kdf1 kdf2 keccak keypair lion locking_allocator mac mars mce mceies md2 md4 md5 mdx_hash mgf1 misty1 mode_pad modes mp mp_generic noekeon noekeon_simd nr numbertheory ocb ofb oid_lookup openpgp par_hash passhash9 pbes2 pbkdf pbkdf1 pbkdf2 pem pk_pad poly1305 prf_tls prf_x942 pubkey rc2 rc4 rc5 rc6 rdrand rdseed rfc3394 rfc6979 rmd128 rmd160 rng rsa rw safer salsa20 seed serpent serpent_simd sessions_sql sha1 sha1_sse2 sha2_32 sha2_64 simd simd_sse2 siphash siv skein srp6 stream system_rng tea threefish threefish_avx2 tiger tls tss twofish utils whirlpool win32_stats x509 x919_mac x931_rng xtea xtea_simd xts
   INFO: Assuming CPU is little endian
   INFO: Assuming unaligned memory access works
   INFO: Using hardlink to link files into build dir (use --link-method to change)
   INFO: Botan 1.11.28 (unreleased undated) build setup is complete
randombit commented 8 years ago

Very strange, I thought the _umul128 intrinsic was available on all even semi recent MSVC versions under x86-64. I'm not sure what is happening here - this works on CI in 2013+2015.

The build as you've set it up will be targeted specifically for x86-64 (due to use of 64 bit instructions such as the 64-bit multiply instruction causing problems here). You could use an x86-32 build under x86-64, albeit leaving some significant optimizations on the table.

neusdan commented 8 years ago

this kind of error occurs if you try to build botan x64 using the VS x86 command prompt or botan x86 using the x64 command prompt.

KarelGGIT commented 8 years ago

@neusdan , can you clarify your answer a bit more ? Do you mean that the python script guessed the environment incorrectly ? Should i tell the script to generate a 64 bit version ?

neusdan commented 8 years ago

you will find different visual studio command prompts in your start menu. For example one for building x86 applications and one for x64.

So if you use the x86 prompt, I think that's the default prompt, you have to tell the configure.py that you wan't to build botan in x86 mode by specifying --cpu x86

KarelGGIT commented 8 years ago

Neusdan, you were correct. So this issue may be closed.

randombit commented 8 years ago

Can we easily detect this mismatch between the configuration target and what the compiler is doing with a macro check? Since in practice it never makes sense to compile a 32-bit build with a 64-bit compiler (it would probably work, but isn't useful) or compile for a 64-bit target with a 32-bit compiler (which would result in build problems like this issue), it would be best to notice and #error out fast.

In GCC/Clang these would be __i386__ and __x86_64__ macros, hopefully MSVC defines something similar. Even just checking x86-32 vs x86-64 and maybe arm vs aarch64 would catch most of the times this trips people up.

KarelGGIT commented 8 years ago

If i recall it right, msvc can use a predefined macro, _WIN64, to detect a 64 bit compile.