Hi,

On Windows x86_64 host, targeting x86_64, a segfault occurs when
-flto, -static and any -O are used together; details are as follows.

> #include <iostream>
>
> int main() {
>     std::cout << std::endl;
> }

> D:\>g++ -flto -static -Og -g test.cpp
>
> D:\>gdb a
> GNU gdb (GDB) 7.6
> Copyright (C) 2013 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".
> For bug reporting instructions, please see:
> <http://www.gnu.org/software/gdb/bugs/>...
> Reading symbols from D:\a.exe...done.
> (gdb) run
> Starting program: D:\a.exe
> [New Thread 32020.0x2658]
>
> Program received signal SIGSEGV, Segmentation fault.
> 0x0000000000000000 in ?? ()
> (gdb) bt
> #0  0x0000000000000000 in ?? ()
> #1  0x00000000004210be in std::ctype<char>::_M_widen_init() const ()
> #2  0x00000000003a2940 in ?? ()
> #3  0x000007fa14070013 in ?? ()
> #4  0x0000000000000001 in ?? ()
> #5  0x000007fa337d54bc in ?? ()
> #6  0x0706050403020100 in ?? ()
> #7  0x0f0e0d0c0b0a0908 in ?? ()
> #8  0x1716151413121110 in ?? ()
> #9  0x1f1e1d1c1b1a1918 in ?? ()
> #10 0x2726252423222120 in ?? ()
> #11 0x2f2e2d2c2b2a2928 in ?? ()
> #12 0x3736353433323130 in ?? ()
> #13 0x3f3e3d3c3b3a3938 in ?? ()
> #14 0x4746454443424140 in ?? ()
> #15 0x4f4e4d4c4b4a4948 in ?? ()
> #16 0x5756555453525150 in ?? ()
> #17 0x5f5e5d5c5b5a5958 in ?? ()
> #18 0x6766656463626160 in ?? ()
> #19 0x6f6e6d6c6b6a6968 in ?? ()
> #20 0x7776757473727170 in ?? ()
> #21 0x7f7e7d7c7b7a7978 in ?? ()
> #22 0x8786858483828180 in ?? ()
> #23 0x8f8e8d8c8b8a8988 in ?? ()
> #24 0x9796959493929190 in ?? ()
> #25 0x9f9e9d9c9b9a9998 in ?? ()
> #26 0xa7a6a5a4a3a2a1a0 in ?? ()
> #27 0xafaeadacabaaa9a8 in ?? ()
> #28 0xb7b6b5b4b3b2b1b0 in ?? ()
> #29 0xbfbebdbcbbbab9b8 in ?? ()
> #30 0xc7c6c5c4c3c2c1c0 in ?? ()
> #31 0xcfcecdcccbcac9c8 in ?? ()
> #32 0xd7d6d5d4d3d2d1d0 in ?? ()
> #33 0xdfdedddcdbdad9d8 in ?? ()
> #34 0xe7e6e5e4e3e2e1e0 in ?? ()
> #35 0xefeeedecebeae9e8 in ?? ()
> #36 0xf7f6f5f4f3f2f1f0 in ?? ()
> #37 0xfffefdfcfbfaf9f8 in ?? ()
> #38 0x0000000000479520 in (anonymous namespace)::name_c ()
> #39 0x000000000047ab60 in std::clog ()
> #40 0x00000000003a1320 in ?? ()
> #41 0x0000000000461648 in std::basic_ostream<char, std::char_traits<char> >& 
> std::endl<char, std::char_traits<char> >(std::basic_ostream<char, 
> std::char_traits<char> >&) ()
> #42 0x000000000040a8b0 in fpreset ()
> #43 0x0000000000000009 in ?? ()
> #44 0x00000000003a1320 in ?? ()
> #45 0x00000000003a12e0 in ?? ()
> #46 0xffffffffffffffff in ?? ()
> #47 0x0000000000000001 in ?? ()
> #48 0x0000000000000009 in ?? ()
> #49 0x0000000000401573 in operator<< (this=<optimized out>, __pf=<optimized 
> out>)
>     at 
> d:/misc/applications/utilities/gcc64/mingw64/lib/gcc/x86_64-w64-mingw32/4.8.1/include/c++/ostream:113
> #50 main () at test.cpp:4
> (gdb)
>
> D:\>g++ -v
> Using built-in specs.
> COLLECT_GCC=g++
> COLLECT_LTO_WRAPPER=d:/misc/applications/utilities/gcc64/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/4.8.1/lto-wrapper.exe
> Target: x86_64-w64-mingw32
> Configured with: ../../../src/gcc-4.8.1/configure --host=x86_64-w64-mingw32 
> --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 
> --with-sysroot=/tmp/x64-481-posix-se
> h-r1/mingw64 --enable-shared --enable-static --disable-multilib 
> --enable-languages=c,c++,fortran,lto --enable-libstdcxx-time=yes 
> --enable-threads=posix --enable-libgomp --enable-lto --e
> nable-graphite --enable-checking=release --enable-fully-dynamic-string 
> --enable-version-specific-runtime-libs --disable-isl-version-check 
> --disable-cloog-version-check --disable-libstdc
> xx-pch --disable-libstdcxx-debug --disable-bootstrap --disable-rpath 
> --disable-win32-registry --disable-nls --disable-werror --disable-symvers 
> --with-gnu-as --with-gnu-ld --with-arch=no
> cona --with-tune=core2 --with-host-libstdcxx='-static -lstdc++' 
> --with-libiconv --with-system-zlib 
> --with-gmp=/tmp/mingw-prereq/x86_64-w64-mingw32-static 
> --with-mpfr=/tmp/mingw-prereq/x
> 86_64-w64-mingw32-static 
> --with-mpc=/tmp/mingw-prereq/x86_64-w64-mingw32-static 
> --with-isl=/tmp/mingw-prereq/x86_64-w64-mingw32-static 
> --with-cloog=/tmp/mingw-prereq/x86_64-w64-mingw32-
> static --enable-cloog-backend=isl --with-pkgversion='rev1, Built by 
> MinGW-builds project' 
> --with-bugurl=http://sourceforge.net/projects/mingwbuilds/ CFLAGS='-O2 -pipe 
> -I/tmp/x64-481-pos
> ix-seh-r1/libs/include -I/tmp/mingw-prereq/x64-zlib/include 
> -I/tmp/mingw-prereq/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe 
> -I/tmp/x64-481-posix-seh-r1/libs/include -I/tmp/mi
> ngw-prereq/x64-zlib/include 
> -I/tmp/mingw-prereq/x86_64-w64-mingw32-static/include' CPPFLAGS= 
> LDFLAGS='-pipe -L/tmp/x64-481-posix-seh-r1/libs/lib 
> -L/tmp/mingw-prereq/x64-zlib/lib -L/tmp/
> mingw-prereq/x86_64-w64-mingw32-static/lib 
> -L/tmp/x64-481-posix-seh-r1/mingw64/opt/lib'
> Thread model: posix
> gcc version 4.8.1 (rev1, Built by MinGW-builds project)

Earlier today I asked about this issue on IRC; the transcript is here:

> [04:06:34] <angelsl> on 4.8.1 rev1, x86_64 SEH & posix threading
> [04:06:59] <angelsl> compiling anything with -flto -static causes the 
> resulting executable to segfault at address 0x0
> [04:07:11] <angelsl> i.. have no idea why
> [04:07:54] <@ktietz> hmm, do you see any warnings?
> [04:07:59] <angelsl> no warnings
> [04:08:07] <angelsl> having -flto or -static alone works fine
> [04:09:59] <angelsl> seems like static libstdc++ is causing it
> [04:10:55] <@ktietz> hmm, are all dependencies in search-path?
> [04:11:28] <angelsl> all dependencies?
> [04:11:40] <@ktietz> I mean DLLs
> [04:12:04] <@ktietz> you could check, if executable has such DLL dependencies
> [04:12:36] <@ktietz> well, does executable actual starts, or does it crash on 
> startup?
> [04:13:04] <@ktietz> have you tried to debug it and found the 0-pointer 
> access?
> [04:13:25] <angelsl> it starts and works until some point which i can't seem 
> to find
> [04:13:35] <@ktietz> ok
> [04:14:03] <angelsl> when i debug (either msvc or gdb) code at 0x0 deref 
> memory at 0x0
> [04:14:13] <@ktietz> does this happens on 32-bit and 64-bit target?  Or just 
> for one?
> [04:14:18] <angelsl> hold on
> [04:15:13] <angelsl> only x86_64 targetting x86_64 it seems
> [04:15:25] <angelsl> doesn't happen on i686 targetting i686
> [04:19:52] <angelsl> ktietz: this is what i'm compiling: 
> https://github.com/angelsl/ms-reNX.cpp
> [04:19:59] <angelsl> with this command line: `c++ -I. -std=c++11 -Wall 
> -Wextra -pedantic -o64 -march=native -flto -Ofast -static *.cpp`
> [04:21:25] <angelsl> seems like the call to std::endl causes it
> [04:21:28] <angelsl> very weird :l
> [04:31:09] <angelsl> the segfault's reproducible with "#include <iostream> \n 
> int main() { std::cout << std::endl; }"
> [04:31:23] <angelsl> compiled with g++ -flto -static -Og
> [04:31:38] <angelsl> doesn't happen without some form of -O though
> [04:37:21] <angelsl> ktietz: http://pastie.org/private/wopugnhqro4ldy9lldxzza

Thank you!

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to