Boost C++ Libraries: Ticket #2347: 'Bus error' on OS X when combining ublas and thread https://svn.boost.org/trac10/ticket/2347 <p> The following code compiles but gives an error on OS X 10.5.5: </p> <pre class="wiki">#include &lt;boost/numeric/ublas/matrix_sparse.hpp&gt; #include &lt;boost/thread.hpp&gt; int main (int argc, char * argv[]) { boost::numeric::ublas::coordinate_matrix&lt;double&gt; cm; cm.resize(3,3, false); return 0; } </pre><p> Jamroot is: </p> <pre class="wiki">lib boost_thread : : &lt;file&gt;/Users/djp/sg/sage-3.1.1/local/lib/boost/libboost_thread-xgcc40-mt-1_36.a ; exe ut : main.cpp boost_thread : &lt;include&gt;boost ; </pre><p> The program does not crash if: (1) I don't link to boost.thread, or remove boost/thread.hpp from main.cpp. (2) I don't 'strip' the executable before running it. </p> <p> The error is independent of whether I link statically or dynamically, and whether I compile in 'debug' or 'release' mode. (Though it doesn't appear in 'debug' mode unless I strip the executable myself.) </p> <p> The error doesn't depend on coordinate matrix, it happens just the same if I use a ublas::vector (and include the relevant header.) </p> <p> Anyway, the above is about as small an example as I can figure out, and I certainly don't have the skills to go any further. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2347 Trac 1.4.3 Dave Philp <dphilp@…> Thu, 18 Sep 2008 23:26:03 GMT <link>https://svn.boost.org/trac10/ticket/2347#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2347#comment:1</guid> <description> <p> I should have mentioned: I have not filed it against ublas, thread, or even build because I have no idea which is causing the problem. I'm happy to help chase it down, and can be contacted at dphilp@… </p> </description> <category>Ticket</category> </item> <item> <author>Dave Philp <dphilp@…></author> <pubDate>Sun, 21 Sep 2008 23:13:19 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2347#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2347#comment:2</guid> <description> <p> The problem is that 'strip' should not be run without options---doing this strips too much out of the binary. Running strip with the -S and -x options seems to be appropriate on OS X but I don't have the expertise to verify this. (Thanks to Zeljko Vrba for figuring this out.) </p> </description> <category>Ticket</category> </item> <item> <author>Dave Philp <dphilp@…></author> <pubDate>Sun, 21 Sep 2008 23:39:40 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2347#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2347#comment:3</guid> <description> <p> I would appreciate being kept in the loop wrt this bug, please send me an email when you get around to looking at it. D </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Vladimir Prus</dc:creator> <pubDate>Mon, 29 Sep 2008 16:37:00 GMT</pubDate> <title>component changed; owner set https://svn.boost.org/trac10/ticket/2347#comment:4 https://svn.boost.org/trac10/ticket/2347#comment:4 <ul> <li><strong>owner</strong> set to <span class="trac-author">Vladimir Prus</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">build</span> </li> </ul> <p> Do I understand correctly that if you build in debug mode, application works, but if you strip it with just 'strip', it crashes? What happens if you strip with "strip -u -r"? Does the application actually work if stripped with "strip -S -x"? Can you run 'nm' on a binary that crashes and a binary that does not, and post both outputs here? </p> Ticket Dave Philp <dphilp@…> Mon, 29 Sep 2008 23:35:40 GMT <link>https://svn.boost.org/trac10/ticket/2347#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2347#comment:5</guid> <description> <blockquote class="citation"> <p> Do I understand correctly that if you build in debug mode, application works, but if you strip it with just 'strip', it crashes? </p> </blockquote> <p> Correct. </p> <blockquote class="citation"> <p> What happens if you strip with "strip -u -r"? </p> </blockquote> <p> Bus error. </p> <blockquote class="citation"> <p> Does the application actually work if stripped with "strip -S -x"? </p> </blockquote> <p> Well, the application above doesn't actually do much! But it doesn't crash. If I add in a few headers and send the cm matrix to std::cout, everything works as expected: </p> <pre class="wiki">#include &lt;boost/thread.hpp&gt; #include &lt;boost/numeric/ublas/matrix_sparse.hpp&gt; #include &lt;boost/numeric/ublas/io.hpp&gt; #include &lt;iostream&gt; int main (int argc, char * argv[]) { boost::numeric::ublas::coordinate_matrix&lt;double&gt; cm; cm.resize(3, 3, false); cm(0, 0) = 1; cm(1, 1) = 2; cm(2, 2) = 3; std::cout &lt;&lt; cm &lt;&lt; std::endl; return 0; } </pre><p> In the above, if you compile and run with bjam debug and strip (no options), it crashes before giving any output. (If you comment out #include boost/thread.hpp, it works as expected.) </p> </description> <category>Ticket</category> </item> <item> <author>Dave Philp <dphilp@…></author> <pubDate>Mon, 29 Sep 2008 23:36:06 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/2347 https://svn.boost.org/trac10/ticket/2347 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">crasher.txt</span> </li> </ul> Ticket Dave Philp <dphilp@…> Mon, 29 Sep 2008 23:36:18 GMT attachment set https://svn.boost.org/trac10/ticket/2347 https://svn.boost.org/trac10/ticket/2347 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">non-crasher.txt</span> </li> </ul> Ticket Dave Philp <dphilp@…> Mon, 29 Sep 2008 23:37:42 GMT <link>https://svn.boost.org/trac10/ticket/2347#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2347#comment:6</guid> <description> <p> I have attached the output of "nm" to this ticket. It's for the new version above with the io stuff. </p> <p> I've never used nm before so don't know if this is what you're after. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Vladimir Prus</dc:creator> <pubDate>Tue, 30 Sep 2008 06:19:42 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/2347#comment:7 https://svn.boost.org/trac10/ticket/2347#comment:7 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Thanks, the output you've posted is what I was looking for. Diffing the outputs gives this: </p> <pre class="wiki">--- non-crasher.txt 2008-09-30 09:56:43.000000000 +0400 +++ crasher.txt 2008-09-30 09:56:26.000000000 +0400 @@ -1,8 +1,4 @@ -0000f00c D _NXArgc -0000f008 D _NXArgv -0000c812 s __GLOBAL__I_main U __Unwind_Resume -0000c780 s __Z41__static_initialization_and_destruction_0ii .... -0000f000 D ___progname -00002346 t ___tcf_0 -00002124 t __dyld_func_lookup 00001000 A __mh_execute_header -0000f004 D _environ U _exit -00002132 T _main -0000f010 d dyld__mach_header -00002110 t dyld_stub_binding_helper -000020d0 T start </pre><p> which surely looks very scary. I was not able to find a definite explanation why strip breaks a binary like this, so I presume we're using strip in some way it was not meant to, which breaks on newer OSX. But to make progress, I've switched to use -S -x. Feel free to open another ticket if you find a "better" way to strip binaries. </p> Ticket