build: disable -stack-clash-protection on Windows #19318

pull fanquake wants to merge 1 commits into bitcoin:master from fanquake:disable_stack_clash_windows changing 1 files +4 −0
  1. fanquake commented at 1:41 pm on June 18, 2020: member

    This does not currently work properly, and will cause GCC to terminate while compiling for Windows. This affects x86_64-w64-mingw32-g++ 8 through 10. Related upstream issue: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90458.

    I’ve PR’d this separate to #18921, as this doesn’t have to wait for us to decide if we want to opt-in to using those flags on other platforms, and is causing build failures.

    While doing more testing for #18921, I (and the bot) saw build issues that would terminate GCC:

     0  CXX      bitcoind-bitcoind.o
     1during RTL pass: final
     2In file included from ./logging.h:10,
     3                 from ./util/system.h:21,
     4                 from ./init.h:11,
     5                 from bitcoind.cpp:13:
     6./tinyformat.h: In static member function 'static int tinyformat::detail::FormatArg::toIntImpl(const void*) [with T = std::__cxx11::basic_string<char>]':
     7./tinyformat.h:550:9: internal compiler error: in seh_emit_stackalloc, at config/i386/winnt.c:1043
     8         }
     9         ^
    100x7fa20389609a __libc_start_main
    11	../csu/libc-start.c:308
    12Please submit a full bug report,
    13with preprocessed source if appropriate.
    14Please include the complete backtrace with any bug report.
    15See <https://gcc.gnu.org/bugs/> for instructions.
    16{standard input}: Assembler messages:
    17{standard input}: Error: open SEH entry at end of file (missing .seh_endproc)
    

    Here’s a fairly minimal test case, that will cause the issue using -fstack-clash-protection -O1:

     0#include <stdexcept>
     1
     2// tested with
     3// x86_64-w64-mingw32-g++ (GCC) 8.3-posix 20190406 (Debian)
     4// x86_64-w64-mingw32-g++ (GCC) 9.3.0 (macOS)
     5// x86_64-w64-mingw32-g++ (GCC) 10-posix 20200525 (Debian)
     6
     7class _error: public std::runtime_error {
     8public:
     9    _error(const std::string &what): std::runtime_error(what) {}
    10};
    11
    12void crash() {
    13    throw _error("Some crash!");
    14}
    15
    16int main() {
    17    crash();
    18    return 0;
    19}
    
     0x86_64-w64-mingw32-g++ test.cpp -fstack-clash-protection -O1
     1
     2Using built-in specs.
     3COLLECT_GCC=x86_64-w64-mingw32-g++
     4COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-w64-mingw32/10-posix/lto-wrapper
     5Target: x86_64-w64-mingw32
     6Configured with: ../../src/configure --build=x86_64-linux-gnu --prefix=/usr --includedir='/usr/include' --mandir='/usr/share/man' --infodir='/usr/share/info' --sysconfdir=/etc --localstatedir=/var --disable-option-checking --disable-silent-rules --libdir='/usr/lib/x86_64-linux-gnu' --libexecdir='/usr/lib/x86_64-linux-gnu' --disable-maintainer-mode --disable-dependency-tracking --prefix=/usr --enable-shared --enable-static --disable-multilib --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --libdir=/usr/lib --enable-libstdcxx-time=yes --with-tune=generic --with-headers=/usr/x86_64-w64-mingw32/include --enable-version-specific-runtime-libs --enable-fully-dynamic-string --enable-libgomp --enable-languages=c,c++,fortran,objc,obj-c++,ada --enable-lto --enable-threads=posix --program-suffix=-posix --program-prefix=x86_64-w64-mingw32- --target=x86_64-w64-mingw32 --with-as=/usr/bin/x86_64-w64-mingw32-as --with-ld=/usr/bin/x86_64-w64-mingw32-ld --enable-libatomic --enable-libstdcxx-filesystem-ts=yes --enable-dependency-tracking
     7Thread model: posix
     8Supported LTO compression algorithms: zlib
     9gcc version 10-posix 20200525 (GCC) 
    10COLLECT_GCC_OPTIONS='-fstack-clash-protection' '-O1' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
    11 /usr/lib/gcc/x86_64-w64-mingw32/10-posix/cc1plus -quiet -v -D_REENTRANT test.cpp -quiet -dumpbase test.cpp -mtune=generic -march=x86-64 -auxbase test -O1 -version -fstack-clash-protection -o /tmp/ccer6MYu.s
    12GNU C++14 (GCC) version 10-posix 20200525 (x86_64-w64-mingw32)
    13	compiled by GNU C version 10.1.0, GMP version 6.2.0, MPFR version 4.0.2, MPC version 1.1.0, isl version isl-0.22.1-GMP
    14
    15GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
    16ignoring nonexistent directory "/usr/lib/gcc/x86_64-w64-mingw32/10-posix/../../../../x86_64-w64-mingw32/sys-include"
    17#include "..." search starts here:
    18#include <...> search starts here:
    19 /usr/lib/gcc/x86_64-w64-mingw32/10-posix/include/c++
    20 /usr/lib/gcc/x86_64-w64-mingw32/10-posix/include/c++/x86_64-w64-mingw32
    21 /usr/lib/gcc/x86_64-w64-mingw32/10-posix/include/c++/backward
    22 /usr/lib/gcc/x86_64-w64-mingw32/10-posix/include
    23 /usr/lib/gcc/x86_64-w64-mingw32/10-posix/include-fixed
    24 /usr/lib/gcc/x86_64-w64-mingw32/10-posix/../../../../x86_64-w64-mingw32/include
    25End of search list.
    26GNU C++14 (GCC) version 10-posix 20200525 (x86_64-w64-mingw32)
    27	compiled by GNU C version 10.1.0, GMP version 6.2.0, MPFR version 4.0.2, MPC version 1.1.0, isl version isl-0.22.1-GMP
    28
    29GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
    30Compiler executable checksum: c42c71f75c7bf48c403bd1b5d143d4a1
    31during RTL pass: final
    32test.cpp: In function 'int main()':
    33test.cpp:17:1: internal compiler error: in seh_emit_stackalloc, at config/i386/winnt.c:1043
    34   17 | }
    35      | ^
    36Please submit a full bug report,
    37with preprocessed source if appropriate.
    38See <https://gcc.gnu.org/bugs/> for instructions.
    
  2. build: disable -stack-clash-protection on Windows
    This does not currently work properly, and will cause GCC to terminate
    while compiling bitcoind. Related upstream issue:
    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90458
    bb341ced5b
  3. fanquake added the label Build system on Jun 18, 2020
  4. in configure.ac:813 in bb341ced5b
    806@@ -807,6 +807,10 @@ if test x$use_hardening != xno; then
    807   case $host in
    808     *mingw*)
    809        AC_CHECK_LIB([ssp],      [main],, AC_MSG_ERROR(libssp missing))
    810+
    811+       dnl stack-clash-protection does not work on Windows
    812+       dnl https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90458
    813+       AX_CHECK_COMPILE_FLAG([-fno-stack-clash-protection],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fno-stack-clash-protection"])
    


    laanwj commented at 2:35 pm on June 18, 2020:
    Wouldn’t it be preferable in this case to not add it in the first place, instead of append -fno-X here? Or is it enabled by some umbrella option?

    fanquake commented at 2:59 pm on June 18, 2020:
    I think it’s likely we’ll end up enabling this, and other flags (for other platforms) in #18921. Progress there has been slow, so I wanted to split this out and just disable it now. It doesn’t work, and is causing build failures when testing 18921 and related PRs. I haven’t seen it being turned on by an umbrella type option/compiler default yet.

    laanwj commented at 3:39 pm on June 18, 2020:

    What I mean is making the AC_CHECK_COMPILE_FLAG(…) to enable it conditional on non-windows.

    Otherwise you get a gcc overall command line like

    0fstack-clash-protection …  … fno-stack-clash-protection
    

    which probably workd but is confusing to see.


    theuni commented at 10:20 pm on June 18, 2020:

    I agree with @wumpus. It sounds like this combo would fail to compile even the most trivial c++ program, so I can’t imagine anyone shipping a mingw compiler with this on by default. So proactively turning it of seems like overkill.

    Instead, how about for #18921, we add a your minimal test-case as the last (input) param to AX_CHECK_COMPILE_FLAG. That way we don’t have to special-case it, and it may just work on mingw at some point in the future.


    fanquake commented at 10:11 am on June 19, 2020:
    I’ve merged this into #18921.
  5. wumpus commented at 10:52 pm on June 18, 2020: none
    Wrong @wumpus.
  6. fanquake closed this on Jun 19, 2020

  7. DrahtBot locked this on Feb 15, 2022
  8. fanquake deleted the branch on Nov 9, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-10-04 22:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me