From owner-freebsd-arm@freebsd.org Thu Sep 1 15:29:15 2016 Return-Path: Delivered-To: freebsd-arm@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id DCAB1BCB94A for ; Thu, 1 Sep 2016 15:29:15 +0000 (UTC) (envelope-from markmi@dsl-only.net) Received: from asp.reflexion.net (outbound-mail-210-24.reflexion.net [208.70.210.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A2BFF999 for ; Thu, 1 Sep 2016 15:29:14 +0000 (UTC) (envelope-from markmi@dsl-only.net) Received: (qmail 3156 invoked from network); 1 Sep 2016 15:29:57 -0000 Received: from unknown (HELO mail-cs-01.app.dca.reflexion.local) (10.81.19.1) by 0 (rfx-qmail) with SMTP; 1 Sep 2016 15:29:57 -0000 Received: by mail-cs-01.app.dca.reflexion.local (Reflexion email security v8.00.0) with SMTP; Thu, 01 Sep 2016 11:29:17 -0400 (EDT) Received: (qmail 27083 invoked from network); 1 Sep 2016 15:29:17 -0000 Received: from unknown (HELO iron2.pdx.net) (69.64.224.71) by 0 (rfx-qmail) with (AES256-SHA encrypted) SMTP; 1 Sep 2016 15:29:17 -0000 Received: from [192.168.0.104] (ip70-189-131-151.lv.lv.cox.net [70.189.131.151]) by iron2.pdx.net (Postfix) with ESMTPSA id A8147EC8FA7; Thu, 1 Sep 2016 08:29:12 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) Subject: Re: armv6 specific std::async crash from g++6 built a.out [stable/11 -r304943 context; /usr/ports -r421001 context] From: Mark Millard In-Reply-To: <25A60F75-B228-4C95-A890-8D6A8DA3F2CE@dsl-only.net> Date: Thu, 1 Sep 2016 08:29:12 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: <2514E6E1-B405-4C3F-B283-754B948851EF@dsl-only.net> References: <25A60F75-B228-4C95-A890-8D6A8DA3F2CE@dsl-only.net> To: freebsd-arm , FreeBSD Ports X-Mailer: Apple Mail (2.3124) X-BeenThere: freebsd-arm@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Porting FreeBSD to ARM processors." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Sep 2016 15:29:16 -0000 On 2016-Sep-1, at 7:46 AM, Mark Millard wrote: > [I've only compared armv6 and amd64 behavior for this. amd64 did not = get the problem.] >=20 > The program is under 40 lines and is shown below: > (It is a simplification of the context of the original discovery.) >=20 >> # more g++6_build_crashes.cpp=20 >> #include // vector >> #include // future, async, launch::async >> #include // thread::hardware_concurrency >>=20 >> decltype(std::thread::hardware_concurrency()) static = parallel_count{0u}; >>=20 >> static void take_time_measurements() {} >>=20 >> int main(int, const char* []) >> { >> parallel_count =3D std::thread::hardware_concurrency(); >> // Do not presume more threads than this are possible. >>=20 >> if (1 < parallel_count) >> { >> --parallel_count; // leave room for main's thread. >>=20 >> std::vector> parallels{}; >> parallels.reserve(parallel_count); >>=20 >> parallels.emplace_back >> ( std::async( std::launch::async, take_time_measurements ) = ); >>=20 >> parallels.emplace_back >> ( std::async( std::launch::async, take_time_measurements ) = ); >>=20 >> for (auto const& at : parallels) >> { at.wait(); } >>=20 >> for (auto& at : parallels) >> { at.get(); } >> } >> return 0; >> } The rpi2 gets 4=3D=3Dstd::thread::hardware_concurrency(). So the typo in the if test is not involved: 2 < parallel_count should = have been in place. Changing it does not change the observed rpi2 = SIGSEGV behavior. I'll note that it is the second std::async's call chain that gets the = SIGSEGV. > I do not know if the problem is a bad interaction between FreeBSD's = -pthread and g++6's library code vs. if this is strictly a g++6 library = problem somehow specific to armv6. >=20 > g++6 based builds run fine in my amd64 context (FreeBSD stable/11 = under VirtualBox under Mac OS X). >=20 > The clang++ 3.8.0 system compiler based build works fine on both amd64 = and armv6 (an rpi2). >=20 > Builds via g++6 on the rpi2 produce an a.out that fails as shown below = (SIGSEGV): >=20 >> # /usr/local/bin/gdb ./a.out >> GNU gdb (GDB) 7.11.1 [GDB v7.11.1 for FreeBSD] >> Copyright (C) 2016 Free Software Foundation, Inc. >> License GPLv3+: GNU GPL version 3 or later = >> 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 "armv6-portbld-freebsd11.0". >> Type "show configuration" for configuration details. >> For bug reporting instructions, please see: >> . >> Find the GDB manual and other documentation resources online at: >> . >> For help, type "help". >> Type "apropos word" to search for commands related to "word"... >> Reading symbols from ./a.out...done. >> (gdb) run >> Starting program: /root/c_tests/a.out=20 >> [New LWP 100255 of process 12266] >>=20 >> Thread 2 received signal SIGSEGV, Segmentation fault. >> [Switching to LWP 100255 of process 12266] >> 0x00000000 in ?? () >> (gdb) bt >> #0 0x00000000 in ?? () >> #1 0x200b2acc in _pthread_once (once_control=3D, = init_routine=3D) at = /usr/src/lib/libthr/thread/thr_once.c:95 >> #2 0x0001312c in __gthread_once (__func=3D, = __once=3D0x20824024) at = /usr/local/lib/gcc6/include/c++/armv6-portbld-freebsd11.0/bits/gthr-defaul= t.h:699 >> #3 std::call_once = ()>*, bool*), std::__future_b >> ase::_State_baseV2*, = std::function ()>*, = bool*>(std::once_flag&, void (std::__future_base::_State_baseV2:: >> *&&)(std::function ()>*, bool*), = std::__future_base::_State_baseV2*&&, = std::function> __future_base::_Result_base, = std::__future_base::_Result_base::_Deleter> ()>*&&, bool*&&) = (__f=3D, __once=3D...) at = /usr/local/lib/gcc6/include/c++/mutex:619 >> #4 = std::__future_base::_State_baseV2::_M_set_result(std::function ()>, bool) = (__ignore_failure=3Dfalse,=20 >> __res=3D..., this=3D0x2082400c) at = /usr/local/lib/gcc6/include/c++/future:393 >> #5 std::__future_base::_Async_state_impl, void>::_Async_state_impl(std::_Bind_simple&&)::{lambda()#1}::operator()() const (__closure=3D0x2082500c) >> at /usr/local/lib/gcc6/include/c++/future:1664 >> #6 = std::_Bind_simple, void>::_Async_state_impl(std::_Bind_simple&&)::{lambda()#1} ()>::_M_invoke<>(std::_Index_tupl >> e<>) (this=3D0x2082500c) at = /usr/local/lib/gcc6/include/c++/functional:1400 >> #7 = std::_Bind_simple, void>::_Async_state_impl(std::_Bind_simple&&)::{lambda()#1} ()>::operator()() ( >> this=3D0x2082500c) at = /usr/local/lib/gcc6/include/c++/functional:1389 >> #8 = std::thread::_State_impl, = void>::_Async_state_impl(std::_Bind_simple&&)::{lambda()#1} ()> >::_ >> M_run() (this=3D0x20825008) at = /usr/local/lib/gcc6/include/c++/thread:196 >> #9 0x201ac464 in std::execute_native_thread_routine (__p=3D0x20825008)= at = /usr/obj/portswork/usr/ports/lang/gcc6/work/gcc-6.2.0/libstdc++-v3/src/c++= 11/thread.cc:83 >> #10 0x200a9fd4 in thread_start (curthread=3D) at = /usr/src/lib/libthr/thread/thr_create.c:289 >> #11 0x200a9a90 in _pthread_create (thread=3D0xbfbfecbc, = attr=3D, start_routine=3D, arg=3D) at /usr/src/lib/libthr/thread/thr_create.c:185 >> #12 0x201ac724 in __gthread_create (__args=3D, = __func=3D0x201ac450 , = __threadid=3D0xbfbfec84) >> at = /usr/obj/portswork/usr/ports/lang/gcc6/work/.build/armv6-portbld-freebsd11= .0/libstdc++-v3/include/armv6-portbld-freebsd11.0/bits/gthr-default.h:662 >> #13 std::thread::_M_start_thread (this=3Dthis@entry=3D0xbfbfecb4, = state=3Dstd::unique_ptr containing 0x20825018) >> at = /usr/obj/portswork/usr/ports/lang/gcc6/work/gcc-6.2.0/libstdc++-v3/src/c++= 11/thread.cc:163 >> #14 0x000138ec in = std::thread::thread, void>::_Async_state_impl(std::_Bind_simple&&)::{lambda()#1}>(std::__future_ba >> se::_Async_state_impl, = void>::_Async_state_impl(std::_Bind_simple&&)::{lambda()#1}&&) (__f=3D, this=3D0xbfbfecb4) >> at /usr/local/lib/gcc6/include/c++/thread:136 >> #15 std::__future_base::_Async_state_impl, void>::_Async_state_impl(std::_Bind_simple&&) = (__fn=3D, this=3D0x2082404c) >> at /usr/local/lib/gcc6/include/c++/future:1661 >> #16 = __gnu_cxx::new_allocator, void> = >::construct, void>, std >> ::_Bind_simple = >(std::__future_base::_Async_state_impl, = void>*, std::_Bind_simple&&) (this=3D, = __p=3D) >> at /usr/local/lib/gcc6/include/c++/ext/new_allocator.h:120 >> #17 = std::allocator_traits, void> > = >::construct> )>, void>, std::_Bind_simple = >(std::allocator, void> >&, = std::__future_base::_Async_state_impl> d (*())()>, void>*, std::_Bind_simple&&) (__a=3D..., = __p=3D) at = /usr/local/lib/gcc6/include/c++/bits/alloc_traits.h:455 >> #18 = std::_Sp_counted_ptr_inplace, void>, = std::allocator, voi >> d> >, = (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace = >(std::allocator, void> >, std::_Bind_s >> imple&&) (__a=3D..., this=3D0x20824040) at = /usr/local/lib/gcc6/include/c++/bits/shared_ptr_base.h:520 >> #19 = std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count, void>, = std::allocator> td::_Bind_simple, void> >, std::_Bind_simple >(std::_Sp_make_shared_tag, = std::__future_base::_Async_state_impl, = void>*, std::allocator> __future_base::_Async_state_impl, = void> > const&, std::_Bind_simple&&) (__a=3D..., = this=3D) >> at /usr/local/lib/gcc6/include/c++/bits/shared_ptr_base.h:615 >> #20 = std::__shared_ptr, void>, = (__gnu_cxx::_Lock_policy)2>::__shared_ptr> _Bind_simple, void> >, std::_Bind_simple = >(std::_Sp_make_shared_tag, = std::allocator, void> > const&, s >> td::_Bind_simple&&) (__a=3D..., __tag=3D..., = this=3D) at = /usr/local/lib/gcc6/include/c++/bits/shared_ptr_base.h:1100 >> #21 = std::shared_ptr, void> = >::shared_ptr, voi >> d> >, std::_Bind_simple >(std::_Sp_make_shared_tag, = std::allocator, void> > const&, std::_Bind_simple& >> &) (__a=3D..., __tag=3D..., this=3D) at = /usr/local/lib/gcc6/include/c++/bits/shared_ptr.h:319 >> #22 = std::allocate_shared, void>, = std::allocator, void> >, st >> d::_Bind_simple = >(std::allocator, void> > const&, std::_Bind_simple&&) = (__a=3D...) >> at /usr/local/lib/gcc6/include/c++/bits/shared_ptr.h:620 >> #23 = std::make_shared, void>, std::_Bind_simple = >(std::_Bind_simple&&) () >> at /usr/local/lib/gcc6/include/c++/bits/shared_ptr.h:636 >> #24 std::__future_base::_S_make_async_state >(std::_Bind_simple&&) (__fn=3D) = at /usr/local/lib/gcc6/include/c++/future:1702 >> #25 std::async = (__policy=3D__policy@entry=3Dstd::launch::async, __fn=3D@0x120d8: {void = (void)} 0x120d8 ) at = /usr/local/lib/gcc6/include/c++/future:1716 >> #26 0x00011788 in main () at g++6_build_crashes.cpp:25 >> (gdb) >=20 >=20 > Context: >=20 >> # uname -apKU >> FreeBSD rpi2 11.0-PRERELEASE FreeBSD 11.0-PRERELEASE #5 r304943M: Sun = Aug 28 03:17:54 PDT 2016 = markmi@FreeBSDx64:/usr/obj/clang/arm.armv6/usr/src/sys/RPI2-NODBG arm = armv6 1100502 1100502 >=20 >> # svnlite info /usr/src | grep "Re[vl][ai:]" >> Relative URL: ^/stable/11 >> Revision: 304943 >> Last Changed Rev: 304943 >=20 >> # svnlite info /usr/ports | grep "Re[vl][ai:]" >> Relative URL: ^/head >> Revision: 421001 >> Last Changed Rev: 421001 >=20 >> # more /etc/make.conf=20 >> DEFAULT_VERSIONS+=3Dperl5=3D5.22 >> WRKDIRPREFIX=3D/usr/obj/portswork >> WITH_DEBUG=3D >> WITH_DEBUG_FILES=3D >> MALLOC_PRODUCTION=3D >=20 >=20 > The compiler -v output is shown in the below: > (Removing the -mcpu=3Dcortex-a7 still gets the problem. Using -O0 = instead of -O2 also still gets the problem.) >=20 >> Script started on Thu Sep 1 06:52:45 2016 >> Command: g++6 -g -v -std=3Dc++14 -Wpedantic -Wall -O2 -pthread = -Wl,-rpath=3D/usr/local/lib/gcc6 -mcpu=3Dcortex-a7 = g++6_build_crashes.cpp >> Using built-in specs. >> COLLECT_GCC=3Dg++6 >> = COLLECT_LTO_WRAPPER=3D/usr/local/libexec/gcc6/gcc/armv6-portbld-freebsd11.= 0/6.2.0/lto-wrapper >> Target: armv6-portbld-freebsd11.0 >> Configured with: = /usr/obj/portswork/usr/ports/lang/gcc6/work/gcc-6.2.0/configure = --disable-multilib --disable-bootstrap --disable-nls = --enable-gnu-indirect-function --libdir=3D/usr/local/lib/gcc6 --libe >> xecdir=3D/usr/local/libexec/gcc6 --program-suffix=3D6 = --with-as=3D/usr/local/bin/as --with-gmp=3D/usr/local = --with-gxx-include-dir=3D/usr/local/lib/gcc6/include/c++/ = --with-ld=3D/usr/local/bin/ld --with-pkgversio >> n=3D'FreeBSD Ports Collection' --with-system-zlib --disable-libgcj = --enable-languages=3Dc,c++,objc,fortran --prefix=3D/usr/local = --localstatedir=3D/var --mandir=3D/usr/local/man = --infodir=3D/usr/local/info/gcc6 - >> -build=3Darmv6-portbld-freebsd11.0 >> Thread model: posix >> gcc version 6.2.0 (FreeBSD Ports Collection)=20 >> COLLECT_GCC_OPTIONS=3D'-g' '-v' '-std=3Dc++14' '-Wpedantic' '-Wall' = '-O2' '-pthread' '-mcpu=3Dcortex-a7' '-shared-libgcc' = '-mtls-dialect=3Dgnu' >> /usr/local/libexec/gcc6/gcc/armv6-portbld-freebsd11.0/6.2.0/cc1plus = -quiet -v g++6_build_crashes.cpp -quiet -dumpbase g++6_build_crashes.cpp = -mcpu=3Dcortex-a7 -mtls-dialect=3Dgnu -auxbase g++6_build_cras >> hes -g -O2 -Wpedantic -Wall -std=3Dc++14 -version -o /tmp//cc0nzkwI.s >> GNU C++14 (FreeBSD Ports Collection) version 6.2.0 = (armv6-portbld-freebsd11.0) >> compiled by GNU C version 4.2.1 Compatible FreeBSD Clang 3.8.0 = (tags/RELEASE_380/final 262564), GMP version 5.1.3, MPFR version = 3.1.4-p1, MPC version 1.0.3, isl version none >> GGC heuristics: --param ggc-min-expand=3D93 --param = ggc-min-heapsize=3D119509 >> ignoring nonexistent directory = "/usr/local/lib/gcc6/gcc/armv6-portbld-freebsd11.0/6.2.0/../../../../../ar= mv6-portbld-freebsd11.0/include" >> #include "..." search starts here: >> #include <...> search starts here: >> /usr/local/lib/gcc6/include/c++/ >> /usr/local/lib/gcc6/include/c++//armv6-portbld-freebsd11.0 >> /usr/local/lib/gcc6/include/c++//backward >> /usr/local/lib/gcc6/gcc/armv6-portbld-freebsd11.0/6.2.0/include >> /usr/local/include >> /usr/local/lib/gcc6/gcc/armv6-portbld-freebsd11.0/6.2.0/include-fixed >> /usr/include >> End of search list. >> GNU C++14 (FreeBSD Ports Collection) version 6.2.0 = (armv6-portbld-freebsd11.0) >> compiled by GNU C version 4.2.1 Compatible FreeBSD Clang 3.8.0 = (tags/RELEASE_380/final 262564), GMP version 5.1.3, MPFR version = 3.1.4-p1, MPC version 1.0.3, isl version none >> GGC heuristics: --param ggc-min-expand=3D93 --param = ggc-min-heapsize=3D119509 >> Compiler executable checksum: 0997b9bc5b083d9cfbb96481fb14adbd >> COLLECT_GCC_OPTIONS=3D'-g' '-v' '-std=3Dc++14' '-Wpedantic' '-Wall' = '-O2' '-pthread' '-mcpu=3Dcortex-a7' '-shared-libgcc' = '-mtls-dialect=3Dgnu' >> /usr/local/bin/as -v -mcpu=3Dcortex-a7 -mfpu=3Dvfp -meabi=3D5 -o = /tmp//ccx4UQrB.o /tmp//cc0nzkwI.s >> GNU assembler version 2.27 (armv6-portbld-freebsd11.0) using BFD = version (GNU Binutils) 2.27 >> = COMPILER_PATH=3D/usr/local/libexec/gcc6/gcc/armv6-portbld-freebsd11.0/6.2.= 0/:/usr/local/libexec/gcc6/gcc/armv6-portbld-freebsd11.0/6.2.0/:/usr/local= /libexec/gcc6/gcc/armv6-portbld-freebsd11.0/:/usr/loca >> = l/lib/gcc6/gcc/armv6-portbld-freebsd11.0/6.2.0/:/usr/local/lib/gcc6/gcc/ar= mv6-portbld-freebsd11.0/:/usr/local/lib/gcc6/gcc/armv6-portbld-freebsd11.0= /6.2.0/../../../../../armv6-portbld-freebsd11.0/bin/ >> = LIBRARY_PATH=3D/usr/local/lib/gcc6/gcc/armv6-portbld-freebsd11.0/6.2.0/:/u= sr/local/lib/gcc6/gcc/armv6-portbld-freebsd11.0/6.2.0/../../../../../armv6= -portbld-freebsd11.0/lib/:/usr/local/lib/gcc6/gcc/armv >> 6-portbld-freebsd11.0/6.2.0/../../../:/lib/:/usr/lib/ >> COLLECT_GCC_OPTIONS=3D'-g' '-v' '-std=3Dc++14' '-Wpedantic' '-Wall' = '-O2' '-pthread' '-mcpu=3Dcortex-a7' '-shared-libgcc' = '-mtls-dialect=3Dgnu' >> /usr/local/libexec/gcc6/gcc/armv6-portbld-freebsd11.0/6.2.0/collect2 = -plugin = /usr/local/libexec/gcc6/gcc/armv6-portbld-freebsd11.0/6.2.0/liblto_plugin.= so -plugin-opt=3D/usr/local/libexec/gcc6/gcc/armv6 >> -portbld-freebsd11.0/6.2.0/lto-wrapper = -plugin-opt=3D-fresolution=3D/tmp//ccD1bSsW.res = -plugin-opt=3D-pass-through=3D-lgcc_s -plugin-opt=3D-pass-through=3D-lgcc = -plugin-opt=3D-pass-through=3D-lpthread -plugin-opt=3D-pa >> ss-through=3D-lc -plugin-opt=3D-pass-through=3D-lgcc_s = -plugin-opt=3D-pass-through=3D-lgcc --eh-frame-hdr -V -dynamic-linker = /libexec/ld-elf.so.1 --hash-style=3Dboth --enable-new-dtags -X = /usr/lib/crt1.o /usr/lib >> /crti.o = /usr/local/lib/gcc6/gcc/armv6-portbld-freebsd11.0/6.2.0/crtbegin.o = -L/usr/local/lib/gcc6/gcc/armv6-portbld-freebsd11.0/6.2.0 = -L/usr/local/lib/gcc6/gcc/armv6-portbld-freebsd11.0/6.2.0/../../../ >> ../../armv6-portbld-freebsd11.0/lib = -L/usr/local/lib/gcc6/gcc/armv6-portbld-freebsd11.0/6.2.0/../../.. = -rpath=3D/usr/local/lib/gcc6 /tmp//ccx4UQrB.o -lstdc++ -lm -lgcc_s -lgcc = -lpthread -lc -lgcc_s -lgc >> c /usr/local/lib/gcc6/gcc/armv6-portbld-freebsd11.0/6.2.0/crtend.o = /usr/lib/crtn.o >> GNU ld (GNU Binutils) 2.27 >> Supported emulations: >=20 > . . . >=20 > I end up having to kill -9 gdb as kill and quit each hang. >=20 > Just running via ./a.out (no gdb) gets the SIGSEGV but does not hang. >=20 =3D=3D=3D Mark Millard markmi at dsl-only.net