armv6 specific std::async crash from g++6 built a.out [stable/11 -r304943 context; /usr/ports -r421001 context]

Mark Millard markmi at dsl-only.net
Thu Sep 1 15:29:20 UTC 2016


On 2016-Sep-1, at 7:46 AM, Mark Millard <markmi at dsl-only.net> wrote:

> [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 
>> #include <vector>       // vector
>> #include <future>       // future, async, launch::async
>> #include <thread>       // thread::hardware_concurrency
>> 
>> decltype(std::thread::hardware_concurrency()) static parallel_count{0u};
>> 
>> static void take_time_measurements() {}
>> 
>> int main(int, const char* [])
>> {
>>    parallel_count = std::thread::hardware_concurrency();
>>        // Do not presume more threads than this are possible.
>> 
>>    if (1 < parallel_count)
>>    {
>>        --parallel_count; // leave room for main's thread.
>> 
>>        std::vector<std::future<void>> parallels{};
>>        parallels.reserve(parallel_count);
>> 
>>        parallels.emplace_back
>>            ( std::async( std::launch::async, take_time_measurements ) );
>> 
>>        parallels.emplace_back
>>            ( std::async( std::launch::async, take_time_measurements ) );
>> 
>>        for (auto const& at : parallels)
>>            { at.wait(); }
>> 
>>        for (auto& at : parallels)
>>            { at.get(); }
>>    }
>>    return 0;
>> }

The rpi2 gets 4==std::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.
> 
> 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 
>> [New LWP 100255 of process 12266]
>> 
>> 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=<optimized out>, init_routine=<optimized out>) at /usr/src/lib/libthr/thread/thr_once.c:95
>> #2  0x0001312c in __gthread_once (__func=<optimized out>, __once=0x20824024) at /usr/local/lib/gcc6/include/c++/armv6-portbld-freebsd11.0/bits/gthr-default.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=<optimized out>, __once=...) 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=false, 
>>    __res=..., this=0x2082400c) 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=0x2082500c)
>>    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=0x2082500c) 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=0x2082500c) at /usr/local/lib/gcc6/include/c++/functional:1389
>> #8  std::thread::_State_impl<std::_Bind_simple<std::__future_base::_Async_state_impl<std::_Bind_simple<void (*())()>, void>::_Async_state_impl(std::_Bind_simple<void (*())()>&&)::{lambda()#1} ()> >::_
>> M_run() (this=0x20825008) at /usr/local/lib/gcc6/include/c++/thread:196
>> #9  0x201ac464 in std::execute_native_thread_routine (__p=0x20825008) 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=<optimized out>) at /usr/src/lib/libthr/thread/thr_create.c:289
>> #11 0x200a9a90 in _pthread_create (thread=0xbfbfecbc, attr=<optimized out>, start_routine=<optimized out>, arg=<optimized out>) at /usr/src/lib/libthr/thread/thr_create.c:185
>> #12 0x201ac724 in __gthread_create (__args=<optimized out>, __func=0x201ac450 <std::execute_native_thread_routine(void*)>, __threadid=0xbfbfec84)
>>    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=this at entry=0xbfbfecb4, state=std::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_simple<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=<optimized out>, this=0xbfbfecb4)
>>    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=<optimized out>, this=0x2082404c)
>>    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=<optimized out>, __p=<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<void (*())()>, void> >&, std::__future_base::_Async_state_impl<std::_Bind_simple<voi
>> d (*())()>, void>*, std::_Bind_simple<void (*())()>&&) (__a=..., __p=<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::_Bind_simple<void (*())()>, void>, std::allocator<std::__future_base::_Async_state_impl<std::_Bind_simple<void (*())()>, voi
>> d> >, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<std::_Bind_simple<void (*())()> >(std::allocator<std::__future_base::_Async_state_impl<std::_Bind_simple<void (*())()>, void> >, std::_Bind_s
>> imple<void (*())()>&&) (__a=..., this=0x20824040) 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::__future_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=..., this=<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_base::_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<void (*())()>, void> > const&, s
>> td::_Bind_simple<void (*())()>&&) (__a=..., __tag=..., this=<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<void (*())()>, void> >::shared_ptr<std::allocator<std::__future_base::_Async_state_impl<std::_Bind_simple<void (*())()>, voi
>> d> >, std::_Bind_simple<void (*())()> >(std::_Sp_make_shared_tag, std::allocator<std::__future_base::_Async_state_impl<std::_Bind_simple<void (*())()>, void> > const&, std::_Bind_simple<void (*())()>&
>> &) (__a=..., __tag=..., this=<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_simple<void (*())()>, void>, std::allocator<std::__future_base::_Async_state_impl<std::_Bind_simple<void (*())()>, void> >, st
>> d::_Bind_simple<void (*())()> >(std::allocator<std::__future_base::_Async_state_impl<std::_Bind_simple<void (*())()>, void> > const&, std::_Bind_simple<void (*())()>&&) (__a=...)
>>    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<void (*())()>, 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=<optimized out>) at /usr/local/lib/gcc6/include/c++/future:1702
>> #25 std::async<void (&)()> (__policy=__policy at entry=std::launch::async, __fn=@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 at 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 
>> DEFAULT_VERSIONS+=perl5=5.22
>> WRKDIRPREFIX=/usr/obj/portswork
>> WITH_DEBUG=
>> WITH_DEBUG_FILES=
>> MALLOC_PRODUCTION=
> 
> 
> The compiler -v output is shown in the below:
> (Removing the -mcpu=cortex-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=c++14 -Wpedantic -Wall -O2 -pthread -Wl,-rpath=/usr/local/lib/gcc6 -mcpu=cortex-a7 g++6_build_crashes.cpp
>> Using built-in specs.
>> COLLECT_GCC=g++6
>> COLLECT_LTO_WRAPPER=/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=/usr/local/lib/gcc6 --libe
>> xecdir=/usr/local/libexec/gcc6 --program-suffix=6 --with-as=/usr/local/bin/as --with-gmp=/usr/local --with-gxx-include-dir=/usr/local/lib/gcc6/include/c++/ --with-ld=/usr/local/bin/ld --with-pkgversio
>> n='FreeBSD Ports Collection' --with-system-zlib --disable-libgcj --enable-languages=c,c++,objc,fortran --prefix=/usr/local --localstatedir=/var --mandir=/usr/local/man --infodir=/usr/local/info/gcc6 -
>> -build=armv6-portbld-freebsd11.0
>> Thread model: posix
>> gcc version 6.2.0 (FreeBSD Ports Collection) 
>> COLLECT_GCC_OPTIONS='-g' '-v' '-std=c++14' '-Wpedantic' '-Wall' '-O2' '-pthread' '-mcpu=cortex-a7' '-shared-libgcc' '-mtls-dialect=gnu'
>> /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=cortex-a7 -mtls-dialect=gnu -auxbase g++6_build_cras
>> hes -g -O2 -Wpedantic -Wall -std=c++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=93 --param ggc-min-heapsize=119509
>> ignoring nonexistent directory "/usr/local/lib/gcc6/gcc/armv6-portbld-freebsd11.0/6.2.0/../../../../../armv6-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=93 --param ggc-min-heapsize=119509
>> Compiler executable checksum: 0997b9bc5b083d9cfbb96481fb14adbd
>> COLLECT_GCC_OPTIONS='-g' '-v' '-std=c++14' '-Wpedantic' '-Wall' '-O2' '-pthread' '-mcpu=cortex-a7' '-shared-libgcc' '-mtls-dialect=gnu'
>> /usr/local/bin/as -v -mcpu=cortex-a7 -mfpu=vfp -meabi=5 -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=/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/armv6-portbld-freebsd11.0/:/usr/local/lib/gcc6/gcc/armv6-portbld-freebsd11.0/6.2.0/../../../../../armv6-portbld-freebsd11.0/bin/
>> LIBRARY_PATH=/usr/local/lib/gcc6/gcc/armv6-portbld-freebsd11.0/6.2.0/:/usr/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='-g' '-v' '-std=c++14' '-Wpedantic' '-Wall' '-O2' '-pthread' '-mcpu=cortex-a7' '-shared-libgcc' '-mtls-dialect=gnu'
>> /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=/usr/local/libexec/gcc6/gcc/armv6
>> -portbld-freebsd11.0/6.2.0/lto-wrapper -plugin-opt=-fresolution=/tmp//ccD1bSsW.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lpthread -plugin-opt=-pa
>> ss-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --eh-frame-hdr -V -dynamic-linker /libexec/ld-elf.so.1 --hash-style=both --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=/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.
> 

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




More information about the freebsd-ports mailing list