Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#42496 closed defect (wontfix)

boost::thread join() crashes under Mountain Lion when linked against libc++

Reported by: trojanfoe@… Owned by: macports-tickets@…
Priority: Normal Milestone:
Component: ports Version: 2.2.1
Keywords: Cc:
Port: boost

Description

I have boost-1.55.0_1 installed under Mavericks and Mountain Lion and the code (attached) crashes under Mountain Lion:

kraken:tmp $ uname -a
Darwin kraken.trojanfoe.com 12.5.0 Darwin Kernel Version 12.5.0: Sun Sep 29 13:33:47 PDT 2013; root:xnu-2050.48.12~1/RELEASE_X86_64 x86_64
kraken:tmp $ port info boost
boost @1.55.0_1 (devel)
Variants:             clang30, clang31, clang32, clang33, clang34, clang35,
                      debug, dragonegg30, dragonegg31, dragonegg32, dragonegg33,
                      dragonegg34, g95, gcc44, gcc45, gcc46, gcc47, gcc48,
                      gcc49, gfortran, llvm, mpich, mpich_devel, [+]no_single,
                      [+]no_static, openmpi, openmpi_devel, python25, python26,
                      [+]python27, python31, python32, python33,
                      regex_match_extra, universal

Description:          Boost provides free portable peer-reviewed C++ libraries.
                      The emphasis is on portable libraries which work well with
                      the C++ Standard Library.
Homepage:             http://www.boost.org

Library Dependencies: zlib, expat, bzip2, libiconv, icu, python27
Platforms:            darwin
License:              Boost-1
Maintainers:          nomaintainer@macports.org
kraken:tmp $ clang --version
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin12.5.0
Thread model: posix
kraken:tmp $ clang++ -std=c++11 -stdlib=libc++ -I /opt/local/include -o threadtest threadtest.cpp -L /opt/local/lib -lboost_system-mt -lboost_thread-mt
kraken:tmp $ lldb threadtest
Current executable set to 'threadtest' (x86_64).
(lldb) run
Process 61735 launched: '/Users/andy/tmp/threadtest' (x86_64)
starting
enter thread
exit thread
Process 61735 stopped
* thread #1: tid = 0x230b7b, 0x000000010004e725 libboost_thread-mt.dylib`boost::detail::thread_data_base::~thread_data_base() + 181, queue = 'com.apple.main-thread, stop reason = EXC_BAD_ACCESS (code=1, address=0x1)
    frame #0: 0x000000010004e725 libboost_thread-mt.dylib`boost::detail::thread_data_base::~thread_data_base() + 181
libboost_thread-mt.dylib`boost::detail::thread_data_base::~thread_data_base() + 181:
-> 0x10004e725:  movq   (%r13), %rbx
   0x10004e729:  leaq   56(%rbx), %rax
   0x10004e72d:  movq   %rax, -56(%rbp)
   0x10004e731:  movb   $0, -48(%rbp)
(lldb) bt
* thread #1: tid = 0x230b7b, 0x000000010004e725 libboost_thread-mt.dylib`boost::detail::thread_data_base::~thread_data_base() + 181, queue = 'com.apple.main-thread, stop reason = EXC_BAD_ACCESS (code=1, address=0x1)
    frame #0: 0x000000010004e725 libboost_thread-mt.dylib`boost::detail::thread_data_base::~thread_data_base() + 181
    frame #1: 0x000000010000b685 threadtest`boost::detail::thread_data<boost::_bi::bind_t<void, boost::_mfi::mf0<void, Test>, boost::_bi::list1<boost::_bi::value<Test*> > > >::~thread_data() + 21
    frame #2: 0x000000010000a495 threadtest`boost::detail::thread_data<boost::_bi::bind_t<void, boost::_mfi::mf0<void, Test>, boost::_bi::list1<boost::_bi::value<Test*> > > >::~thread_data() + 21
    frame #3: 0x000000010000a4b9 threadtest`boost::detail::thread_data<boost::_bi::bind_t<void, boost::_mfi::mf0<void, Test>, boost::_bi::list1<boost::_bi::value<Test*> > > >::~thread_data() + 25
    frame #4: 0x000000010000c5ae threadtest`void boost::checked_delete<boost::detail::thread_data<boost::_bi::bind_t<void, boost::_mfi::mf0<void, Test>, boost::_bi::list1<boost::_bi::value<Test*> > > > >(boost::detail::thread_data<boost::_bi::bind_t<void, boost::_mfi::mf0<void, Test>, boost::_bi::list1<boost::_bi::value<Test*> > > >*) + 46
    frame #5: 0x000000010000c6a9 threadtest`boost::detail::sp_counted_impl_p<boost::detail::thread_data<boost::_bi::bind_t<void, boost::_mfi::mf0<void, Test>, boost::_bi::list1<boost::_bi::value<Test*> > > > >::dispose() + 25
    frame #6: 0x000000010004f2af libboost_thread-mt.dylib`boost::thread::join_noexcept() + 447
    frame #7: 0x00000001000027f4 threadtest`boost::thread::join() + 148
    frame #8: 0x000000010000157d threadtest`Test::test() + 589
    frame #9: 0x0000000100001741 threadtest`main + 33
    frame #10: 0x00007fff86cea7e1 libdyld.dylib`start + 1
(lldb) quit
Quitting LLDB will kill one or more processes. Do you really want to proceed: [Y/n] y
kraken:tmp $ 

Note that the same code works flawlessly under Mavericks:

medusa:tmp $ uname -a
Darwin medusa.local 13.0.0 Darwin Kernel Version 13.0.0: Thu Sep 19 22:22:27 PDT 2013; root:xnu-2422.1.72~6/RELEASE_X86_64 x86_64
medusa:tmp $ port info boost
boost @1.55.0_1 (devel)
Variants:             clang30, clang31, clang32, clang33, clang34, clang35,
                      debug, dragonegg30, dragonegg31, dragonegg32, dragonegg33,
                      dragonegg34, g95, gcc44, gcc45, gcc46, gcc47, gcc48,
                      gcc49, gfortran, llvm, mpich, mpich_devel, [+]no_single,
                      [+]no_static, openmpi, openmpi_devel, python25, python26,
                      [+]python27, python31, python32, python33,
                      regex_match_extra, universal

Description:          Boost provides free portable peer-reviewed C++ libraries.
                      The emphasis is on portable libraries which work well with
                      the C++ Standard Library.
Homepage:             http://www.boost.org

Library Dependencies: zlib, expat, bzip2, libiconv, icu, python27
Platforms:            darwin
License:              Boost-1
Maintainers:          nomaintainer@macports.org
medusa:tmp $ clang --version
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
medusa:tmp $ clang++ -std=c++11 -stdlib=libc++ -I /opt/local/include -o threadtest threadtest.cpp -L /opt/local/lib -lboost_system-mt -lboost_thread-mt
medusa:tmp $ lldb threadtest
Current executable set to 'threadtest' (x86_64).
(lldb) run
Process 55929 launched: '/Users/andy/tmp/threadtest' (x86_64)
starting
enter thread
exit thread
finishing
Process 55929 exited with status = 0 (0x00000000) 
(lldb) quit
medusa:tmp $ 

Attachments (1)

threadtest.cpp (602 bytes) - added by trojanfoe@… 10 years ago.
Test source code

Download all attachments as: .zip

Change History (6)

Changed 10 years ago by trojanfoe@…

Attachment: threadtest.cpp added

Test source code

comment:1 Changed 10 years ago by trojanfoe@…

Sorry, "port info" isn't very useful:

medusa:~ $ port list boost
boost                          @1.55.0         devel/boost

kraken:~ $ port list boost
boost                          @1.55.0         devel/boost

comment:2 Changed 10 years ago by neverpanic (Clemens Lang)

Resolution: wontfix
Status: newclosed
Summary: boost::thread join() crashes under Mountain Lion.boost::thread join() crashes under Mountain Lion when linked against libc++

You must use the same standard library implementation used by boost when compiling your own executables. On Mountain Lion, MacPorts builds boost against libstdc++ (which is the default on this OS). If you use this version of boost in an executable compiled with clang++ -std=c++11 -stdlib=libc++ the generated executable will link against both /usr/lib/libc++.1.dylib and /usr/lib/libstdc++.6.dylib which will lead to undefined behavior and crashes, as you have seen.

If you want to use C++11 on Mountain Lion, you'll have to compile boost against libc++ on your own. See also https://lists.macosforge.org/pipermail/macports-dev/2013-December/025360.html which describes the issue in more detail and outlines possible solutions (none of which have been implemented in MacPorts due to lack of manpower).

comment:3 Changed 10 years ago by mf2k (Frank Schima)

Note that port list is not useful either. port installed boost would tell us something about your setup though.

comment:4 Changed 10 years ago by trojanfoe@…

Ah that's interesting; thanks. I need to use libc++ so I will try and get boost to compile against libc++.

Last edited 10 years ago by trojanfoe@… (previous) (diff)

comment:5 Changed 10 years ago by trojanfoe@…

All sorted now, many thanks. For others, who don't want to follow the comment-trail in order to figure out how this was fixed, I:

  1. Installed macports-svn and switched to using a file-based "source" (as per https://guide.macports.org/#installing.macports.subversion).
  2. Got a list of my existing ports using:
port list installed | cut -f1 -d' ' > /tmp/portlist.txt
  1. Uninstalled all ports:
port uninstall installed
  1. Editted /opt/local/etc/macports/macports.conf and set these values:
buildfromsource always
delete_la_files yes
cxx_stdlib libc++
  1. Reinstalled all ports:
port install $(cat /tmp/portlist.txt)
Note: See TracTickets for help on using tickets.