Boost C++ Libraries: Ticket #3363: linking 2 files compiled with different NDEBUG causes segfault https://svn.boost.org/trac10/ticket/3363 <p> Linking y1.o and y2.o compiled as below causes the resulting executable to segfault and show valgrind errors. x1.o defines NDEBUG before including a boost header, x2.o doesn't. If both define NDEBUG, or both don't then linking them produces an executable that runs, and shows no valgrind errors. </p> <p> This is y1.cpp: #define NDEBUG 1 #include &lt;boost/date_time/posix_time/posix_time.hpp&gt; #include &lt;iostream&gt; </p> <p> void foobar() { </p> <blockquote> <p> boost::posix_time::time_duration td(0, 0, 1, 0); std::stringstream ss; ss &lt;&lt; td; </p> </blockquote> <p> } void bar(void); int main() { </p> <blockquote> <p> bar(); return 0; </p> </blockquote> <p> } </p> <p> This is y2.cpp: #include &lt;boost/date_time/posix_time/posix_time.hpp&gt; void bar(void) { </p> <blockquote> <p> std::cerr&lt;&lt;boost::posix_time::second_clock::local_time()&lt;&lt;' '; </p> </blockquote> <p> } </p> <p> Fails: $ g++ y1.cpp y2.cpp &amp;&amp; ./a.out Segmentation fault </p> <p> Reported by Debian user; see <a class="ext-link" href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=537680"><span class="icon">​</span>http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=537680</a> for valgrind output. </p> <p> I have reproduced this behaviour on today's trunk, so I expect it is still a problem in 1.39.0 and upcoming 1.40.0. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3363 Trac 1.4.3 smr@… Mon, 04 Jan 2010 02:38:27 GMT <link>https://svn.boost.org/trac10/ticket/3363#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3363#comment:1</guid> <description> <p> I reproduced this bug with Boost 1.41. </p> </description> <category>Ticket</category> </item> <item> <author>smr@…</author> <pubDate>Mon, 04 Jan 2010 02:40:07 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/3363 https://svn.boost.org/trac10/ticket/3363 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">valgrid.log</span> </li> </ul> <p> Log of valgrind run with Boost 1.41 on Debian x86_64 </p> Ticket smr@… Sun, 28 Feb 2010 04:09:58 GMT attachment set https://svn.boost.org/trac10/ticket/3363 https://svn.boost.org/trac10/ticket/3363 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">boost-1.42-valgrind.log</span> </li> </ul> <p> Log of valgrind run with Boost 1.42 on Debian x86_64 </p> Ticket Vladimir Prus Sat, 27 Mar 2010 07:11:22 GMT <link>https://svn.boost.org/trac10/ticket/3363#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3363#comment:2</guid> <description> <p> Generally speaking, why is this a problem? In general, NDEBUG may change ABI, and therefore should be consistent for entire application -- unless there's a standard saying otherwise. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 01 Apr 2010 02:34:24 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3363#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3363#comment:3</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/3363#comment:2" title="Comment 2">vladimir_prus</a>: </p> <blockquote class="citation"> <p> Generally speaking, why is this a problem? In general, NDEBUG may change ABI, and therefore should be consistent for entire application -- unless there's a standard saying otherwise. </p> </blockquote> <p> What I can find on the web is <a class="ext-link" href="http://www.visualco.de/NDEBUG.html"><span class="icon">​</span>http://www.visualco.de/NDEBUG.html</a> which asserts that </p> <blockquote> <p> The C standard only dictates that when NDEBUG is defined, the assert macro shall expand to nothing. NDEBUG has no other effect or meaning. </p> </blockquote> <p> The standardization of assert() supports that; c.f. <a class="ext-link" href="http://www.opengroup.org/onlinepubs/9699919799/functions/assert.html"><span class="icon">​</span>http://www.opengroup.org/onlinepubs/9699919799/functions/assert.html</a> I don't know of anything that states <strong>NDEBUG may change ABI</strong> -- do you? </p> <p> One problem the current situation causes is that a boost-using library may be compiled without NDEBUG while someone's application uses NDEBUG, and then goes kabloom when it runs. </p> </description> <category>Ticket</category> </item> <item> <author>smr@…</author> <pubDate>Mon, 21 Feb 2011 04:29:58 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3363#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3363#comment:4</guid> <description> <p> Hi, </p> <p> I don't see any activity on this bug, but I just tried it with the 1.46 Release Candidate and the specific issue here seems resolved. I no longer get a segfault. </p> </description> <category>Ticket</category> </item> </channel> </rss>