randombit / botan

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

Botan 2.18.2 does not build under Cygwin #2832

Open SideChannel opened 3 years ago

SideChannel commented 3 years ago

Botan 2.18.2 (and 2.18.1, too) does not build under Cygwin with gcc 11.2.0

System: Windows 10 Pro 21H1 19043.1320 (all patches installed) Cygwin 3.2.0 with gcc 11.2

$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-cygwin/11/lto-wrapper.exe
Target: x86_64-pc-cygwin
Configured with: /mnt/share/cygpkgs/gcc/gcc.x86_64/src/gcc-11.2.0/configure --srcdir=/mnt/share/cygpkgs/gcc/gcc.x86_64/src/gcc-11.2.0 --prefix=/usr --exec-prefix=/usr --localstatedir=/var --sysconfdir=/etc --docdir=/usr/share/doc/gcc --htmldir=/usr/share/doc/gcc/html -C --build=x86_64-pc-cygwin --host=x86_64-pc-cygwin --target=x86_64-pc-cygwin --without-libiconv-prefix --without-libintl-prefix --libexecdir=/usr/lib --with-gcc-major-version-only --enable-shared --enable-shared-libgcc --enable-static --enable-version-specific-runtime-libs --enable-bootstrap --enable-__cxa_atexit --with-dwarf2 --with-tune=generic --disable-bootstrap --enable-languages=c,c++,fortran,lto,objc,obj-c++,jit --enable-graphite --enable-threads=posix --enable-libatomic --enable-libgomp --enable-libquadmath --enable-libquadmath-support --disable-libssp --enable-libada --disable-symvers --with-gnu-ld --with-gnu-as --with-cloog-include=/usr/include/cloog-isl --without-libiconv-prefix --without-libintl-prefix --with-system-zlib --enable-linker-build-id --with-default-libstdcxx-abi=gcc4-compatible --enable-libstdcxx-filesystem-ts
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (GCC)

After ./configure.py the Makefile of Botan contains

# Compiler Flags

ABI_FLAGS      =  -U__STRICT_ANSI__ -fstack-protector -m64 -pthread
LANG_FLAGS     = -std=c++11 -D_REENTRANT 
CXXFLAGS       = -O3 -DBOTAN_IS_BEING_BUILT
WARN_FLAGS     = -Wall -Wextra -Wpedantic -Wstrict-aliasing -Wcast-align -Wmissing-declarations -Wpointer-arith -Wcast-qual -Wzero-as-null-pointer-constant -Wnon-virtual-dtor
LIB_FLAGS      = 
LDFLAGS        =

make seems to have problems with undefining STRICT_ANSI as we have a lot of warnings

g++ -U__STRICT_ANSI__ -fstack-protector -m64 -pthread -std=c++11 -march=znver2 -D_REENTRANT  -O3 -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/tests/test_x509_path.cpp -o build/obj/test/test_x509_path.o
In file included from /usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/cstddef:49,
                 from build/include/botan/types.h:15,
                 from build/include/botan/secmem.h:11,
                 from build/include/botan/rng.h:11,
                 from src/tests/tests.h:12,
                 from src/tests/test_x509_path.cpp:7:
/usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/x86_64-pc-cygwin/bits/c++config.h:573:2: warning: #warning "__STRICT_ANSI__ seems to have been undefined; this is not supported" [-Wcpp]
  573 | #warning "__STRICT_ANSI__ seems to have been undefined; this is not supported"
      |  ^~~~~~~

However, compilation breaks with

g++ -U__STRICT_ANSI__ -fstack-protector -m64 -pthread -std=c++11 -march=znver2 -D_REENTRANT  -O3 -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/tests/test_x509_path.cpp -o build/obj/test/test_x509_path.o
In file included from /usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/cstddef:49,
                 from build/include/botan/types.h:15,
                 from build/include/botan/secmem.h:11,
                 from build/include/botan/rng.h:11,
                 from src/tests/tests.h:12,
                 from src/tests/test_x509_path.cpp:7:
/usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/x86_64-pc-cygwin/bits/c++config.h:573:2: warning: #warning "__STRICT_ANSI__ seems to have been undefined; this is not supported" [-Wcpp]
  573 | #warning "__STRICT_ANSI__ seems to have been undefined; this is not supported"
      |  ^~~~~~~
In file included from /usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/bits/stl_algobase.h:63,
                 from /usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/memory:63,
                 from build/include/botan/types.h:17,
                 from build/include/botan/secmem.h:11,
                 from build/include/botan/rng.h:11,
                 from src/tests/tests.h:12,
                 from src/tests/test_x509_path.cpp:7:
/usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/ext/numeric_traits.h: In instantiation of 'struct __gnu_cxx::__numeric_traits_integer<__int128 unsigned>':
/usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/bits/uniform_int_dist.h:251:31:   required from 'static _Up std::uniform_int_distribution<_IntType>::_S_nd(_Urbg&, _Up) [with _Wp = __int128 unsigned; _Urbg = Botan_Tests::{anonymous}::BSI_Path_Validation_Tests::run()::random_bit_generator; _Up = long unsigned int; _IntType = long unsigned int]'
/usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/bits/uniform_int_dist.h:307:35:   required from 'std::uniform_int_distribution<_IntType>::result_type std::uniform_int_distribution<_IntType>::operator()(_UniformRandomBitGenerator&, const std::uniform_int_distribution<_IntType>::param_type&) [with _UniformRandomBitGenerator = Botan_Tests::{anonymous}::BSI_Path_Validation_Tests::run()::random_bit_generator; _IntType = long unsigned int; std::uniform_int_distribution<_IntType>::result_type = long unsigned int]'
/usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/bits/stl_algo.h:3791:35:   required from 'void std::shuffle(_RAIter, _RAIter, _UGenerator&&) [with _RAIter = __gnu_cxx::__normal_iterator<Botan::X509_Certificate*, std::vector<Botan::X509_Certificate> >; _UGenerator = Botan_Tests::{anonymous}::BSI_Path_Validation_Tests::run()::random_bit_generator&]'
src/tests/test_x509_path.cpp:846:25:   required from here
/usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/ext/numeric_traits.h:64:53: error: static assertion failed: invalid specialization
   64 |       static_assert(__is_integer_nonstrict<_Value>::__value,
      |                                                     ^~~~~~~
/usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/ext/numeric_traits.h:64:53: note: 'std::__is_integer<__int128 unsigned>::__value' evaluates to false
In file included from /usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/bits/stl_algo.h:66,
                 from /usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/algorithm:62,
                 from build/include/botan/secmem.h:14,
                 from build/include/botan/rng.h:11,
                 from src/tests/tests.h:12,
                 from src/tests/test_x509_path.cpp:7:
/usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/bits/uniform_int_dist.h: In instantiation of 'static _Up std::uniform_int_distribution<_IntType>::_S_nd(_Urbg&, _Up) [with _Wp = __int128 unsigned; _Urbg = Botan_Tests::{anonymous}::BSI_Path_Validation_Tests::run()::random_bit_generator; _Up = long unsigned int; _IntType = long unsigned int]':
/usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/bits/uniform_int_dist.h:307:35:   required from 'std::uniform_int_distribution<_IntType>::result_type std::uniform_int_distribution<_IntType>::operator()(_UniformRandomBitGenerator&, const std::uniform_int_distribution<_IntType>::param_type&) [with _UniformRandomBitGenerator = Botan_Tests::{anonymous}::BSI_Path_Validation_Tests::run()::random_bit_generator; _IntType = long unsigned int; std::uniform_int_distribution<_IntType>::result_type = long unsigned int]'
/usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/bits/stl_algo.h:3791:35:   required from 'void std::shuffle(_RAIter, _RAIter, _UGenerator&&) [with _RAIter = __gnu_cxx::__normal_iterator<Botan::X509_Certificate*, std::vector<Botan::X509_Certificate> >; _UGenerator = Botan_Tests::{anonymous}::BSI_Path_Validation_Tests::run()::random_bit_generator&]'
src/tests/test_x509_path.cpp:846:25:   required from here
/usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/bits/uniform_int_dist.h:252:46: error: static assertion failed: W must be twice as wide as U
  252 |           static_assert(_Wp_traits::__digits == (2 * _Up_traits::__digits),
      |                                     ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/bits/uniform_int_dist.h:252:46: note: '(((int)__gnu_cxx::__numeric_traits_integer<__int128 unsigned>::__digits) == (2 * ((int)__gnu_cxx::__numeric_traits_integer<long unsigned int>::__digits)))' evaluates to false
make: *** [Makefile:1652: build/obj/test/test_x509_path.o] Error 1

I am not sure if the new Botan version is to blame or the new (since August in Cygwin) gcc 11.2. At least it used to work with older Botan and older (gcc 9.3) compiler. Under Linux (OpenSuSE Tumbleweed with gcc 11.2) everything works fine. (I did not compare the resulting Makefiles)

reneme commented 3 years ago

Unfortunately, I don't have easy access to Cygwin. But this seems to have to do with the __STRICT_ANSI__ warning and GCC 11. In fact the build system undefines __STRICT_ANSI__ explicitly for Cygwin (explicitly stating that it is a hack for Cygwin).

Maybe things have moved on since then? Could you please try to remove this "hack" on your machine and trying again?

SideChannel commented 3 years ago

Okay, from the original Makefile `# Compiler Flags

ABI_FLAGS = -U__STRICT_ANSI__ -fstack-protector -m64 -pthread LANG_FLAGS = -std=c++11 -D_REENTRANT `

I tried first only removing -USTRICT_ANSI, but still having -std=c++11. ==> Does not work. Only when I remove both -USTRICT_ANSI and -std=c++11, then Botan 2.18.2 compiles fine. Tested with Cygwin 3.3.1 from 2021-10-28 and gcc 11.2.0. I think the default with gcc 11 when no -std is given, is -std=gnu++17.

So, the recommendation in one of above clementine issues (drop both -std=c++0x and -U__STRICT_ANSI__) seems to be correct for recent gcc compilers. Problem solved. Thanks.