Boost C++ Libraries: Ticket #9118: Seg fault on thread join when llvm and libc++ are used https://svn.boost.org/trac10/ticket/9118 <p> This issue appears to be specific to llvm libc++ standard library </p> <p> the program compiled with the following options will have a seg fault on thread join. </p> <pre class="wiki">clang -x c++ -arch x86_64 -std=gnu++11 -stdlib=libc++ -I/opt/local/include -c main.cpp -o main.o clang++ -arch x86_64 -L/opt/local/lib main.o -stdlib=libc++ -lboost_system-mt -lboost_thread-mt -o mutex_test </pre><p> the program compiled with </p> <pre class="wiki">clang -x c++ -arch x86_64 -I/opt/local/include -c main.cpp -o main.o clang++ -arch x86_64 -L/opt/local/lib main.o -lboost_system-mt -lboost_thread-mt -o mutex_test </pre><pre class="wiki">System Version : OS X Mountain Lion 10.8.4 Compiler : $ clang --version Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn) Target: x86_64-apple-darwin12.4.0 Thread model: posix Boost: built/installed with mac ports </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9118 Trac 1.4.3 gosuperninja@… Sun, 15 Sep 2013 19:48:04 GMT attachment set https://svn.boost.org/trac10/ticket/9118 https://svn.boost.org/trac10/ticket/9118 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">main.cpp</span> </li> </ul> Ticket anonymous Sun, 15 Sep 2013 19:51:43 GMT <link>https://svn.boost.org/trac10/ticket/9118#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9118#comment:1</guid> <description> <p> The description got messed up when I copied and pasted it in </p> <p> The following generates an executable that will seg fault. </p> <pre class="wiki">clang -x c++ -arch x86_64 -std=gnu++11 -stdlib=libc++ -I/opt/local/include -c main.cpp -o main.o clang++ -arch x86_64 -L/opt/local/lib main.o -stdlib=libc++ -lboost_system-mt -lboost_thread-mt -o mutex_test </pre><p> The following will generate an executable that will not seg fault </p> <pre class="wiki">clang -x c++ -arch x86_64 -I/opt/local/include -std=gnu++11 -c main.cpp -o main.o clang++ -arch x86_64 -L/opt/local/lib main.o -lboost_system-mt -lboost_thread-mt -o mutex_test </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Sun, 15 Sep 2013 19:55:05 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9118#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9118#comment:2</guid> <description> <p> Here is a the backtrace : </p> <pre class="wiki"> Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000001 0x000000010002df45 in boost::detail::thread_data_base::~thread_data_base () (gdb) bt #0 0x000000010002df45 in boost::detail::thread_data_base::~thread_data_base () #1 0x0000000100004c15 in boost::detail::thread_data&lt;boost::_bi::bind_t&lt;void, void (*)(), boost::_bi::list0&gt; &gt;::~thread_data () #2 0x0000000100003b05 in boost::detail::thread_data&lt;boost::_bi::bind_t&lt;void, void (*)(), boost::_bi::list0&gt; &gt;::~thread_data () #3 0x0000000100003b29 in boost::detail::thread_data&lt;boost::_bi::bind_t&lt;void, void (*)(), boost::_bi::list0&gt; &gt;::~thread_data () #4 0x0000000100005aee in boost::checked_delete&lt;boost::detail::thread_data&lt;boost::_bi::bind_t&lt;void, void (*)(), boost::_bi::list0&gt; &gt; &gt; () #5 0x0000000100005be9 in boost::detail::sp_counted_impl_p&lt;boost::detail::thread_data&lt;boost::_bi::bind_t&lt;void, void (*)(), boost::_bi::list0&gt; &gt; &gt;::dispose () #6 0x000000010002e9bf in boost::thread::join_noexcept () #7 0x00000001000019a4 in boost::thread::join () #8 0x0000000100000d45 in main () (gdb) </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 15 Sep 2013 20:54:59 GMT</pubDate> <title>owner, status, description changed https://svn.boost.org/trac10/ticket/9118#comment:3 https://svn.boost.org/trac10/ticket/9118#comment:3 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Anthony Williams</span> to <span class="trac-author">viboes</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> <li><strong>description</strong> modified (<a href="/trac10/ticket/9118?action=diff&amp;version=3">diff</a>) </li> </ul> Ticket viboes Sun, 15 Sep 2013 21:03:40 GMT <link>https://svn.boost.org/trac10/ticket/9118#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9118#comment:4</guid> <description> <p> Do you get the same error if you change </p> <pre class="wiki"> boost::thread t1 (boost::bind( &amp;do_nothing)); </pre><p> by </p> <pre class="wiki"> boost::thread t1 ( &amp;do_nothing ); </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 15 Sep 2013 21:06:15 GMT</pubDate> <title>component changed https://svn.boost.org/trac10/ticket/9118#comment:5 https://svn.boost.org/trac10/ticket/9118#comment:5 <ul> <li><strong>component</strong> <span class="trac-field-old">threads</span> → <span class="trac-field-new">thread</span> </li> </ul> Ticket viboes Sun, 15 Sep 2013 21:45:18 GMT <link>https://svn.boost.org/trac10/ticket/9118#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9118#comment:6</guid> <description> <p> The same program works on trunk </p> <pre class="wiki">clang-darwin.compile.c++ ../../../bin.v2/libs/thread/test/clang_main.test/clang-darwin-g3.2x/release/threading-multi/clang_main.o "/Users/viboes/clang/clang+llvm-3.2-x86_64-apple-darwin11/bin/clang++" -x c++ -arch x86_64 -std=gnu++11 -O3 -Wextra -Wno-long-long -Wunused-function -pedantic -O3 -finline-functions -Wno-inline -Wall -pedantic -DBOOST_ALL_NO_LIB=1 -DBOOST_CHRONO_DYN_LINK=1 -DBOOST_SYSTEM_DYN_LINK=1 -DBOOST_SYSTEM_NO_DEPRECATED -DBOOST_THREAD_BUILD_DLL=1 -DBOOST_THREAD_POSIX -DBOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED -DBOOST_THREAD_USE_DLL=1 -DNDEBUG -I"../../.." -c -o "../../../bin.v2/libs/thread/test/clang_main.test/clang-darwin-g3.2x/release/threading-multi/clang_main.o" "clang_main.cpp" clang-darwin.link ../../../bin.v2/libs/thread/test/clang_main.test/clang-darwin-g3.2x/release/threading-multi/clang_main "/Users/viboes/clang/clang+llvm-3.2-x86_64-apple-darwin11/bin/clang++" -o "../../../bin.v2/libs/thread/test/clang_main.test/clang-darwin-g3.2x/release/threading-multi/clang_main" "../../../bin.v2/libs/thread/test/clang_main.test/clang-darwin-g3.2x/release/threading-multi/clang_main.o" "../../../bin.v2/libs/chrono/build/clang-darwin-g3.2x/release/threading-multi/libboost_chrono.dylib" "../../../bin.v2/libs/thread/build/clang-darwin-g3.2x/release/threading-multi/libboost_thread.dylib" "../../../bin.v2/libs/system/build/clang-darwin-g3.2x/release/threading-multi/libboost_system.dylib" -arch x86_64 -std=gnu++11 </pre><pre class="wiki">Mac OS X Lion 10.7.5 (11G63) /Users/viboes/clang/clang+llvm-3.2-x86_64-apple-darwin11/bin/clang++ --version clang version 3.2 (tags/RELEASE_32/final) Target: x86_64-apple-darwin11.4.2 Thread model: posix </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Tue, 17 Sep 2013 05:10:54 GMT</pubDate> <title>summary changed https://svn.boost.org/trac10/ticket/9118#comment:7 https://svn.boost.org/trac10/ticket/9118#comment:7 <ul> <li><strong>summary</strong> <span class="trac-field-old">Seg fault on thread join</span> → <span class="trac-field-new">Seg fault on thread join when llvm and libc++ are used</span> </li> </ul> Ticket viboes Tue, 17 Sep 2013 21:23:55 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/9118#comment:8 https://svn.boost.org/trac10/ticket/9118#comment:8 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">duplicate</span> </li> </ul> <p> Isn't this a duplicate of <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7666" title="#7666: Bugs: Boost Thread SIGSEGV on join() when -D_GLIBCXX_DEBUG is used (closed: invalid)">#7666</a>? </p> Ticket viboes Thu, 19 Sep 2013 22:07:07 GMT <link>https://svn.boost.org/trac10/ticket/9118#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9118#comment:9</guid> <description> <p> With which options was built Boost? </p> <p> What is the size of boost::detail::thread_data_base on each case? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Thu, 26 Sep 2013 18:01:45 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9118#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9118#comment:10</guid> <description> <p> I suspect that this is related to an ABI incompatibility. </p> </description> <category>Ticket</category> </item> <item> <author>markus.weber@…</author> <pubDate>Thu, 03 Apr 2014 12:25:15 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9118#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9118#comment:11</guid> <description> <p> We've recently run into this problem as well and have been able to tie it to the use of pragma pack(...). </p> <p> The same code runs smooth on Windows, but fails on Mac in one case but works in another place. We noticed that we can provoke the failure by deliberately setting a structure packing != 8 before include boost/thread.hpp, e.g. #pragma pack(1). </p> <p> Amazingly the code also fails if we explicitly switch back to default packing prior to the include (#pragma pack()). </p> <p> It only seems to work if we explicitly sett the packing to 8 prior to the include. </p> <p> This seems to indicate a missing pack statement somewhere in the platform specific code, which would also explain why most parties cannot reproduce it, while some can, and the code is not susceptible to any specific packing statement on Windows. </p> <p> I should note that we also had the impression that #pragma pack(x) does not seem to work reliable on GCC, as we saw complaints in other code as well. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 17 Apr 2014 11:24:23 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9118#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9118#comment:12</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/9118#comment:11" title="Comment 11">markus.weber@…</a>: </p> <blockquote class="citation"> <p> It only seems to work if we explicitly sett the packing to 8 prior to the include. </p> </blockquote> <p> That indeed solves the problem. Added #pragma pack(8) just before first include file in boost/boost/thread.hpp </p> <p> However its a temporary workaround and not a proper fix. Very much looking forward for a proper fix (a proper location for pragma statement to go or something similar). Reproducible on MacOSX 10.8.5 using CLang compiler (Xcode 5) built with stdc++98 and libstdc++ </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 17 Apr 2014 14:27:51 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9118#comment:13 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9118#comment:13</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/9118#comment:12" title="Comment 12">anonymous</a>: </p> <blockquote class="citation"> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/9118#comment:11" title="Comment 11">markus.weber@…</a>: </p> <blockquote class="citation"> <p> It only seems to work if we explicitly sett the packing to 8 prior to the include. </p> </blockquote> <p> That indeed solves the problem. Added #pragma pack(8) just before first include file in boost/boost/thread.hpp </p> </blockquote> <p> Looks like an oversight. With this change crash did not come up once and thought that is solved. But upon successive builds, its back to square one! </p> </description> <category>Ticket</category> </item> <item> <author>markus.weber@…</author> <pubDate>Tue, 22 Apr 2014 11:13:55 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9118#comment:14 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9118#comment:14</guid> <description> <p> For what it is worth: We were initially slow in discovering this issue as we developed the code on Windows first - and there the problem does not show. I tend to interpret this as a missing pack statement in one of the platform-specific headers. Shouldn't be that difficult to find if you know exactly what you are doing as there is not all *that* much going into the control structure which gets corrupted. For someone who knows the code intimately it should not be a hard challenge. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Tue, 22 Apr 2014 16:27:02 GMT</pubDate> <title>status changed; resolution deleted https://svn.boost.org/trac10/ticket/9118#comment:15 https://svn.boost.org/trac10/ticket/9118#comment:15 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">duplicate</span> </li> </ul> <p> Please reopen the ticket next time if you want that I follow up it. </p> <p> I will take a look at as soon as I have some time. </p> Ticket viboes Fri, 26 Sep 2014 06:15:26 GMT <link>https://svn.boost.org/trac10/ticket/9118#comment:16 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9118#comment:16</guid> <description> <p> I have take a look and I don't see where the pack is needed. Any idea? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 06 Oct 2014 12:06:58 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9118#comment:17 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9118#comment:17</guid> <description> <p> Given the long lead-time I am working from memory here: At the time I investigated this I did really dive way into the control structures, but I don't recall all the details anymore. Some of the members in there are platform-dependent. I tried to locate them but they turned out to be quite involved and hard to back-trace if you don't know them by heart - that's why I gave up when we found the pack(8) work-around, leaving this to someone who knows them better than me. </p> <p> So the short answer is: No, I have no better idea. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Wed, 08 Oct 2014 05:51:44 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9118#comment:18 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9118#comment:18</guid> <description> <p> The back-trace call 3 times to ~thread_data. This is weird. Are you sure that you have created a single thread? </p> <p> Are you able to reproduce it now? </p> </description> <category>Ticket</category> </item> <item> <author>markus.weber@…</author> <pubDate>Fri, 10 Oct 2014 14:11:58 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9118#comment:19 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9118#comment:19</guid> <description> <p> I had one of our engineers verify this. We have switched to version 1.55 since reporting this issue and we positively verified it to be still present. In the test scenario (part of the standard regression tests) multiple threads may be running, but this is the only one created and maintained by boost. Please let me know if this might be a problem source. During original verification we wrote some short test which only created the thread and terminated it immediately again (nothing else running). </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 11 Oct 2014 02:58:27 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9118#comment:20 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9118#comment:20</guid> <description> <p> Do you mean that the backtrace doesn't corresponds to the example? </p> </description> <category>Ticket</category> </item> </channel> </rss>