randombit / botan

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

Botan 2.12.1: gcc/mingw windows build does not work #2187

Closed Uw42 closed 4 years ago

Uw42 commented 4 years ago

Hello, i tried to build the library on a windows system using g++ and mingw. The build does not produce an error but the botan-test program stops emmediately with any output. The output of the configure.py script is:

INFO: configure.py invoked with options "--cc=gcc --os=mingw --prefix=/build_Botan --minimized-build" INFO: Configuring to build Botan 2.12.1 (revision git:1a6ad661ce64287ccbe26460ccc3aa4247d86ba8) INFO: Running under 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] INFO: Autodetected platform information: OS="Windows" machine="AMD64" proc="Intel64 Family 6 Model 142 Stepping 10, GenuineIntel" INFO: Guessing target processor is a x86_64 (use --cpu to set) INFO: Canonicalized CPU target AMD64 to x86_64 INFO: Shared libs not supported on mingw, disabling shared lib support INFO: Auto-detected compiler version 8.1 INFO: Auto-detected compiler arch x86_64 INFO: Target is gcc:8.1-mingw-x86_64 INFO: Assuming target x86_64 is little endian INFO: Skipping (incompatible CPU): aes_armv8 aes_power8 p9_darn sha1_armv8 sha2_32_armv8 sm4_armv8 INFO: Skipping (incompatible OS): certstor_system_macos certstor_system_windows commoncrypto dev_random fd_unix getentropy proc_walk INFO: Skipping (not requested): adler32 aead aes aes_ni aes_vperm aont argon2 aria asio asn1 auto_rng base32 base58 base64 bcrypt bcrypt_pbkdf bigint blake2 block blowfish camellia cascade cast128 cast256 cbc cbc_mac ccm cecpq1 certstor_flatfile certstor_sql certstor_sqlite3 certstor_system cfb chacha chacha20poly1305 chacha_avx2 chacha_rng chacha_simd32 checksum clmul_cpu clmul_ssse3 cmac codec_filt comb4p compression crc24 crc32 cryptobox ctr curve25519 des 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 ffi filters fpe_fe1 gcm gmac gost_28147 gost_3410 gost_3411 hash hash_id hkdf hmac hmac_drbg hotp http_util idea idea_sse2 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 par_hash passhash9 pbes2 pbkdf pbkdf1 pbkdf2 pem pgp_s2k pk_pad pkcs11 poly1305 poly_dbl prf_tls prf_x942 psk_db pubkey rc4 rdrand rdrand_rng rdseed rfc3394 rfc6979 rmd160 rsa salsa20 scrypt seed serpent serpent_avx2 serpent_simd sessions_sql sessions_sqlite3 sha1 sha1_sse2 sha1_x86 sha2_32 sha2_32_bmi2 sha2_32_x86 sha2_64 sha2_64_bmi2 sha3 sha3_bmi2 shacal2 shacal2_simd shacal2_x86 shake shake_cipher simd simd_avx2 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 threefish_512_avx2 tiger tls tls_cbc tss twofish uuid whirlpool win32_stats x509 x919_mac xmss xtea xts INFO: Skipping (requires external dependency): boost bzip2 lzma openssl sqlite3 tpm zlib INFO: Loading modules: base cpuid entropy hex rng utils INFO: Using hardlink 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

Can you give me a hint what i can try to find the problem? Should i add the output of the make-command?

Thanks an kind regards

randombit commented 4 years ago

This sounds related to #1896 where someone reported a similar problem with MinGW but we were not able to diagnose the problem.

#include <botan/hash.h>
#include <iostream>

int main ()
   {
   auto hash = Botan::HashFunction::create("SHA-256");
   std::cout << hash->name() << std::endl;
   }
Uw42 commented 4 years ago

Thank you for your response.

GNU gdb (GDB) 8.1 Copyright (C) 2018 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-w64-mingw32". Type "show configuration" for configuration details. For bug reporting instructions, please see: http://www.gnu.org/software/gdb/bugs/. Find the GDB manual and other documentation resources online at: http://www.gnu.org/software/gdb/documentation/. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from ./botan-test...done. (gdb) r Starting program: D:\Mathe\Kryptographie\Botan-2.12.1\botan-test.exe [New Thread 13136.0x1964] [New Thread 13136.0x2a0] [New Thread 13136.0x2f68] [New Thread 13136.0x2f38]

Thread 1 received signal SIGSEGV, Segmentation fault. 0x00000000004521d5 in __static_initialization_and_destruction_0(int, int) [clone .constprop.397] ()

I tried to run a simple program like you suggested using the eclipse ide, but i could not link the botan library. I' m a beginner with c++ so maybe did something wrong with the configuration of the projetct but maybe it did not work because the library is not valid.

Does the gdb response give any useful hint to you? Can i try somthing else?

randombit commented 4 years ago

Hrm interesting. At the point where gdb reports the crash can you run the gdb command backtrace?

Uw42 commented 4 years ago

The Result of backtrace is: (gdb) backtrace

0 0x00000000004521d5 in __static_initialization_and_destruction_0(int, int) [clone .constprop.397] ()

1 0x000000000043beb2 in __do_global_ctors ()

2 0x000000000040139a in __tmainCRTStartup ()

3 0x00000000004014fb in mainCRTStartup ()

Uw42 commented 4 years ago

Hello, when i set a breakpoint at mainCRTStartup and then use the list command i get:

(gdb) break mainCRTStartup
Breakpoint 1 at 0x4014e4
(gdb) list
1       ../../../../../src/gcc-8.1.0/libgcc/config/i386/cygwin.S: No such file or directory.

to me it looks as if the segmentation fault happens before any function of the botan library is called and my installation of mingw is not correct and i should install it new. What do you think?

Thanks and kind regards

randombit commented 4 years ago

It looks like this is an issue with stack protector on MinGW: https://sourceforge.net/p/mingw-w64/bugs/755/

Can you try rebuilding adding --without-stack-protector to configure.py invocation? If that works, I'll disable SSP for MinGW.

Uw42 commented 4 years ago

I had to install mingw new and then executed the following command:

py configure.py --cc=gcc --os=mingw --without-stack-protector --minimized-build

After that botan-test executed the tests all correct. Thank you for your help

Uw42 commented 4 years ago

Just to verify i called the script without the --without-stack-protector option and again the botan-test terminated without any response. So that is really the problem.

Uw42 commented 4 years ago

Hello, when i try to use the generated library libbotan-2.a in a simple Testprogram:

`#include <botan/hash.h>

include <botan/hex.h>

include

using namespace std;

int main() { std::unique_ptr hash1(Botan::HashFunction::create("SHA-256")); cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!! return 0; }` i get an error during the build of the project:

D:\ws\TestBotan\Debug/../src/TestBotan.cpp:16: undefined reference to `Botan::HashFunction::create(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::cxx11::basic_string<char, std::char_traits, std::allocator > const&)'

I used the eclipse ide and put the search path for libraries in the Project Properties under C/C++ Build->settings->MinGW C++ Linker->Libraries ->Library search path. That should work but it seams as if the library is not found. It would be very nice if you have any suggestion how i can find out what 's the problem. But the problem i originaly addressed is solved.

Thank you for your help and kind regards

randombit commented 4 years ago

In addition to the library search path you will also need to somewhere specify to link against libbotan-2 (eg -lbotan-2). I am not sure where in Eclipse one does that though.

But the problem i originaly addressed is solved.

OK I think I misunderstood your earlier comment. It is the case the disabling stack protector fixed the issue where botan-test crashed/exited with no messages?

Uw42 commented 4 years ago

It is the case the disabling stack protector fixed the issue where botan-test crashed/exited with no messages?

Yes, that is right!