Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 1 Sep 2016 07:46:20 -0700
From:      Mark Millard <markmi@dsl-only.net>
To:        freebsd-arm <freebsd-arm@freebsd.org>, FreeBSD Ports <freebsd-ports@freebsd.org>
Subject:   armv6 specific std::async crash from g++6 built a.out [stable/11 -r304943 context; /usr/ports -r421001 context]
Message-ID:  <25A60F75-B228-4C95-A890-8D6A8DA3F2CE@dsl-only.net>

next in thread | raw e-mail | index | archive | help
[I've only compared armv6 and amd64 behavior for this. amd64 did not get =
the problem.]

The program is under 40 lines and is shown below:
(It is a simplification of the context of the original discovery.)

> # more g++6_build_crashes.cpp=20
> #include <vector>       // vector
> #include <future>       // future, async, launch::async
> #include <thread>       // 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<std::future<void>> 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;
> }

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.

g++6 based builds run fine in my amd64 context (FreeBSD stable/11 under =
VirtualBox under Mac OS X).

The clang++ 3.8.0 system compiler based build works fine on both amd64 =
and armv6 (an rpi2).

Builds via g++6 on the rpi2 produce an a.out that fails as shown below =
(SIGSEGV):

> # /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 =
<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 "armv6-portbld-freebsd11.0".
> Type "show configuration" for configuration details.
> For bug reporting instructions, please see:
> <http://www.gnu.org/software/gdb/bugs/>.
> Find the GDB manual and other documentation resources online at:
> <http://www.gnu.org/software/gdb/documentation/>.
> 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<optimized out>, =
init_routine=3D<optimized out>) at =
/usr/src/lib/libthr/thread/thr_once.c:95
> #2  0x0001312c in __gthread_once (__func=3D<optimized out>, =
__once=3D0x20824024) at =
/usr/local/lib/gcc6/include/c++/armv6-portbld-freebsd11.0/bits/gthr-defaul=
t.h:699
> #3  std::call_once<void =
(std::__future_base::_State_baseV2::*)(std::function<std::unique_ptr<std::=
__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> =
()>*, bool*), std::__future_b
> ase::_State_baseV2*, =
std::function<std::unique_ptr<std::__future_base::_Result_base, =
std::__future_base::_Result_base::_Deleter> ()>*, =
bool*>(std::once_flag&, void (std::__future_base::_State_baseV2::
> *&&)(std::function<std::unique_ptr<std::__future_base::_Result_base, =
std::__future_base::_Result_base::_Deleter> ()>*, bool*), =
std::__future_base::_State_baseV2*&&, =
std::function<std::unique_ptr<std::
> __future_base::_Result_base, =
std::__future_base::_Result_base::_Deleter> ()>*&&, bool*&&) =
(__f=3D<optimized out>, __once=3D...) at =
/usr/local/lib/gcc6/include/c++/mutex:619
> #4  =
std::__future_base::_State_baseV2::_M_set_result(std::function<std::unique=
_ptr<std::__future_base::_Result_base, =
std::__future_base::_Result_base::_Deleter> ()>, 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<std::_Bind_simple<void =
(*())()>, void>::_Async_state_impl(std::_Bind_simple<void =
(*())()>&&)::{lambda()#1}::operator()() const (__closure=3D0x2082500c)
>     at /usr/local/lib/gcc6/include/c++/future:1664
> #6  =
std::_Bind_simple<std::__future_base::_Async_state_impl<std::_Bind_simple<=
void (*())()>, void>::_Async_state_impl(std::_Bind_simple<void =
(*())()>&&)::{lambda()#1} ()>::_M_invoke<>(std::_Index_tupl
> e<>) (this=3D0x2082500c) at =
/usr/local/lib/gcc6/include/c++/functional:1400
> #7  =
std::_Bind_simple<std::__future_base::_Async_state_impl<std::_Bind_simple<=
void (*())()>, void>::_Async_state_impl(std::_Bind_simple<void =
(*())()>&&)::{lambda()#1} ()>::operator()() (
>     this=3D0x2082500c) at =
/usr/local/lib/gcc6/include/c++/functional:1389
> #8  =
std::thread::_State_impl<std::_Bind_simple<std::__future_base::_Async_stat=
e_impl<std::_Bind_simple<void (*())()>, =
void>::_Async_state_impl(std::_Bind_simple<void =
(*())()>&&)::{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<optimized out>) at =
/usr/src/lib/libthr/thread/thr_create.c:289
> #11 0x200a9a90 in _pthread_create (thread=3D0xbfbfecbc, =
attr=3D<optimized out>, start_routine=3D<optimized out>, arg=3D<optimized =
out>) at /usr/src/lib/libthr/thread/thr_create.c:185
> #12 0x201ac724 in __gthread_create (__args=3D<optimized out>, =
__func=3D0x201ac450 <std::execute_native_thread_routine(void*)>, =
__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<std::thread::_State> 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<std::__future_base::_Async_state_impl<std::_Bind_simpl=
e<void (*())()>, void>::_Async_state_impl(std::_Bind_simple<void =
(*())()>&&)::{lambda()#1}>(std::__future_ba
> se::_Async_state_impl<std::_Bind_simple<void (*())()>, =
void>::_Async_state_impl(std::_Bind_simple<void =
(*())()>&&)::{lambda()#1}&&) (__f=3D<optimized out>, this=3D0xbfbfecb4)
>     at /usr/local/lib/gcc6/include/c++/thread:136
> #15 std::__future_base::_Async_state_impl<std::_Bind_simple<void =
(*())()>, void>::_Async_state_impl(std::_Bind_simple<void (*())()>&&) =
(__fn=3D<optimized out>, this=3D0x2082404c)
>     at /usr/local/lib/gcc6/include/c++/future:1661
> #16 =
__gnu_cxx::new_allocator<std::__future_base::_Async_state_impl<std::_Bind_=
simple<void (*())()>, void> =
>::construct<std::__future_base::_Async_state_impl<std::_Bind_simple<void =
(*())()>, void>, std
> ::_Bind_simple<void (*())()> =
>(std::__future_base::_Async_state_impl<std::_Bind_simple<void (*())()>, =
void>*, std::_Bind_simple<void (*())()>&&) (this=3D<optimized out>, =
__p=3D<optimized out>)
>     at /usr/local/lib/gcc6/include/c++/ext/new_allocator.h:120
> #17 =
std::allocator_traits<std::allocator<std::__future_base::_Async_state_impl=
<std::_Bind_simple<void (*())()>, void> > =
>::construct<std::__future_base::_Async_state_impl<std::_Bind_simple<void =
(*())(
> )>, void>, std::_Bind_simple<void (*())()> =
>(std::allocator<std::__future_base::_Async_state_impl<std::_Bind_simple<v=
oid (*())()>, void> >&, =
std::__future_base::_Async_state_impl<std::_Bind_simple<voi
> d (*())()>, void>*, std::_Bind_simple<void (*())()>&&) (__a=3D..., =
__p=3D<optimized out>) at =
/usr/local/lib/gcc6/include/c++/bits/alloc_traits.h:455
> #18 =
std::_Sp_counted_ptr_inplace<std::__future_base::_Async_state_impl<std::_B=
ind_simple<void (*())()>, void>, =
std::allocator<std::__future_base::_Async_state_impl<std::_Bind_simple<voi=
d (*())()>, voi
> d> >, =
(__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<std::_Bind_simple<voi=
d (*())()> =
>(std::allocator<std::__future_base::_Async_state_impl<std::_Bind_simple<v=
oid (*())()>, void> >, std::_Bind_s
> imple<void (*())()>&&) (__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<std::__fut=
ure_base::_Async_state_impl<std::_Bind_simple<void (*())()>, void>, =
std::allocator<std::__future_base::_Async_state_impl<s
> td::_Bind_simple<void (*())()>, void> >, std::_Bind_simple<void =
(*())()> >(std::_Sp_make_shared_tag, =
std::__future_base::_Async_state_impl<std::_Bind_simple<void (*())()>, =
void>*, std::allocator<std::
> __future_base::_Async_state_impl<std::_Bind_simple<void (*())()>, =
void> > const&, std::_Bind_simple<void (*())()>&&) (__a=3D..., =
this=3D<optimized out>)
>     at /usr/local/lib/gcc6/include/c++/bits/shared_ptr_base.h:615
> #20 =
std::__shared_ptr<std::__future_base::_Async_state_impl<std::_Bind_simple<=
void (*())()>, void>, =
(__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<std::__future_bas=
e::_Async_state_impl<std::
> _Bind_simple<void (*())()>, void> >, std::_Bind_simple<void (*())()> =
>(std::_Sp_make_shared_tag, =
std::allocator<std::__future_base::_Async_state_impl<std::_Bind_simple<voi=
d (*())()>, void> > const&, s
> td::_Bind_simple<void (*())()>&&) (__a=3D..., __tag=3D..., =
this=3D<optimized out>) at =
/usr/local/lib/gcc6/include/c++/bits/shared_ptr_base.h:1100
> #21 =
std::shared_ptr<std::__future_base::_Async_state_impl<std::_Bind_simple<vo=
id (*())()>, void> =
>::shared_ptr<std::allocator<std::__future_base::_Async_state_impl<std::_B=
ind_simple<void (*())()>, voi
> d> >, std::_Bind_simple<void (*())()> >(std::_Sp_make_shared_tag, =
std::allocator<std::__future_base::_Async_state_impl<std::_Bind_simple<voi=
d (*())()>, void> > const&, std::_Bind_simple<void (*())()>&
> &) (__a=3D..., __tag=3D..., this=3D<optimized out>) at =
/usr/local/lib/gcc6/include/c++/bits/shared_ptr.h:319
> #22 =
std::allocate_shared<std::__future_base::_Async_state_impl<std::_Bind_simp=
le<void (*())()>, void>, =
std::allocator<std::__future_base::_Async_state_impl<std::_Bind_simple<voi=
d (*())()>, void> >, st
> d::_Bind_simple<void (*())()> =
>(std::allocator<std::__future_base::_Async_state_impl<std::_Bind_simple<v=
oid (*())()>, void> > const&, std::_Bind_simple<void (*())()>&&) =
(__a=3D...)
>     at /usr/local/lib/gcc6/include/c++/bits/shared_ptr.h:620
> #23 =
std::make_shared<std::__future_base::_Async_state_impl<std::_Bind_simple<v=
oid (*())()>, void>, std::_Bind_simple<void (*())()> =
>(std::_Bind_simple<void (*())()>&&) ()
>     at /usr/local/lib/gcc6/include/c++/bits/shared_ptr.h:636
> #24 std::__future_base::_S_make_async_state<std::_Bind_simple<void =
(*())()> >(std::_Bind_simple<void (*())()>&&) (__fn=3D<optimized out>) =
at /usr/local/lib/gcc6/include/c++/future:1702
> #25 std::async<void (&)()> =
(__policy=3D__policy@entry=3Dstd::launch::async, __fn=3D@0x120d8: {void =
(void)} 0x120d8 <take_time_measurements()>) at =
/usr/local/lib/gcc6/include/c++/future:1716
> #26 0x00011788 in main () at g++6_build_crashes.cpp:25
> (gdb)


Context:

> # 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

> # svnlite info /usr/src | grep "Re[vl][ai:]"
> Relative URL: ^/stable/11
> Revision: 304943
> Last Changed Rev: 304943

> # svnlite info /usr/ports | grep "Re[vl][ai:]"
> Relative URL: ^/head
> Revision: 421001
> Last Changed Rev: 421001

> # 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


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.)

> 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:

. . .

I end up having to kill -9 gdb as kill and quit each hang.

Just running via ./a.out (no gdb) gets the SIGSEGV but does not hang.


=3D=3D=3D
Mark Millard
markmi at dsl-only.net




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?25A60F75-B228-4C95-A890-8D6A8DA3F2CE>