From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13733 invoked by alias); 14 Mar 2012 20:39:04 -0000 Received: (qmail 13582 invoked by uid 22791); 14 Mar 2012 20:39:03 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_BJ,TW_CX,TW_DC,TW_GX X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 14 Mar 2012 20:38:50 +0000 From: "jason at cornsyrup dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/52590] New: std::thread Segmentation fault static linking Date: Wed, 14 Mar 2012 20:42:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Keywords: X-Bugzilla-Severity: major X-Bugzilla-Who: jason at cornsyrup dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-03/txt/msg01288.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52590 Bug #: 52590 Summary: std::thread Segmentation fault static linking Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: major Priority: P3 Component: libstdc++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: jason@cornsyrup.org $ g++ -v Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.7/lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.7.0~rc1-1ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++,go --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.7.0 20120302 (prerelease) (Ubuntu/Linaro 4.7.0~rc1-1ubuntu1) $ g++ -static -pthread -std=c++0x -o thread thread.cc $ ./thread pthread_create works std::thread works Segmentation fault $ cat thread.cc #include #include void *foo1(void *) { std::cout << "pthread_create works\n"; return 0; } void foo2() { std::cout << "std::thread works\n"; } int main() { { pthread_t t; pthread_create(&t, 0, foo1, 0); void *r; pthread_join(t, &r); } { std::thread t(foo2); t.join(); } return 0; } I was surprised to see that pthreads worked in this case while std::thread did not. I've also heard that boost::thread works. I'm having a hard time finding any documentation on whether static linking and std::thread should work together. Also see http://stackoverflow.com/questions/7090623/c0x-thread-static-linking-problem If it is the case that pthreads and std::thread cannot work together with static linking, then it'd be nice to fail at some point before runtime if that is possible.