Boost C++ Libraries: Ticket #4594: Boost exception classes do not have GCC default visibility https://svn.boost.org/trac10/ticket/4594 <p> All of the boost exception classes, including but not necessarily limited to: </p> <ul><li>boost::exception </li><li>boost::unknown_exception </li><li>boost::exception_detail::clone_base </li></ul><p> do not have visibility attributes associated with them. This means that, when files are built using GCC with -fvisibility=hidden, classes derived from these types become uncatchable as these types when thrown across library boundaries. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4594 Trac 1.4.3 Jonathan Jones <jonathan.jones@…> Wed, 25 Aug 2010 19:25:47 GMT attachment set https://svn.boost.org/trac10/ticket/4594 https://svn.boost.org/trac10/ticket/4594 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">boost_visibility.tar</span> </li> </ul> <p> Isolated reproduction code. </p> Ticket Jonathan Jones <jonathan.jones@…> Wed, 08 Sep 2010 18:05:20 GMT <link>https://svn.boost.org/trac10/ticket/4594#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4594#comment:1</guid> <description> <p> Would it be possible to get an update as to the status of this bug? </p> </description> <category>Ticket</category> </item> <item> <author>Vicente Botet <vicente.botet@…></author> <pubDate>Tue, 07 Dec 2010 20:08:33 GMT</pubDate> <title>type changed https://svn.boost.org/trac10/ticket/4594#comment:2 https://svn.boost.org/trac10/ticket/4594#comment:2 <ul> <li><strong>type</strong> <span class="trac-field-old">Bugs</span> → <span class="trac-field-new">Patches</span> </li> </ul> Ticket Emil Dotchevski Sat, 12 Feb 2011 00:12:28 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/4594#comment:3 https://svn.boost.org/trac10/ticket/4594#comment:3 <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> Ticket Dimitrij Drus Tue, 24 May 2011 07:18:15 GMT <link>https://svn.boost.org/trac10/ticket/4594#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4594#comment:4</guid> <description> <p> I just moved to the 1.46.1 version of boost. It still lacks the visibility support for boost::exception. The trunk has corresponding adjustments, which however are not complete. Within the exception.hpp there is a forward declaration of the exception class. Without surrounding this forward declaration with GCC visibility pragmas too, the boost::exception can't be catched if throwed across the shared lib boundaries. </p> <p> The behaviour was observed on Ubuntu 10.04 with gcc version 4.4.3. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Emil Dotchevski</dc:creator> <pubDate>Tue, 24 May 2011 22:56:53 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4594#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4594#comment:5</guid> <description> <p> Thanks for the feedback Dimitrij. </p> <p> Have you verified that surrounding the forward declaration with visibility pragmas solves the problem? I don't have an easy way to test this so I'd appreciate a patch that is tested to work. </p> </description> <category>Ticket</category> </item> <item> <author>Dimitrij Drus <dadrus@…></author> <pubDate>Tue, 14 Jun 2011 10:12:18 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4594#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4594#comment:6</guid> <description> <p> Yes. Catching boost::exception thrown over the shared library boundaries is only possible after surrounding the forward declaration with the visibility pragmas. Patch is attached. </p> <p> One can use the test attached by Jonathan to verify this. Jonathan, however, expects the class boost::exception_detail::clone_base be exported (surrounded with gcc visibility pragmas) too, that's why corresponding test cases fail. </p> <p> Regards Dimitrij </p> </description> <category>Ticket</category> </item> <item> <author>Dimitrij Drus <dadrus@…></author> <pubDate>Tue, 14 Jun 2011 10:14:21 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/4594 https://svn.boost.org/trac10/ticket/4594 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">exception.patch</span> </li> </ul> <p> Patch for boost/exception/exception.hpp file </p> Ticket Dimitrij Drus <dadrus@…> Tue, 14 Jun 2011 10:20:08 GMT <link>https://svn.boost.org/trac10/ticket/4594#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4594#comment:7</guid> <description> <p> If one has troubles launching Jonathan's test, one should add -Wl,-rpath,'$ORIGIN' to the last line of the make file. In my case the libboost_visibility.so was not found without this modification. </p> <p> I hope it is not too late to apply the path for the coming release. </p> <p> Regards Dimitrij </p> </description> <category>Ticket</category> </item> <item> <author>Jonathan Jones <jonathan.jones@…></author> <pubDate>Tue, 14 Jun 2011 20:32:37 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/4594 https://svn.boost.org/trac10/ticket/4594 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">boost_visibility.2.tar</span> </li> </ul> <p> Updated test case, including showing the fact that error_info/get_error_info also have symbol visibility issues. </p> Ticket Jonathan Jones <jonathan.jones@…> Tue, 14 Jun 2011 20:36:19 GMT <link>https://svn.boost.org/trac10/ticket/4594#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4594#comment:8</guid> <description> <p> It's not enough to ensure that boost::exception, boost::exception_detail::clone_base, and boost::unknown_exception have default symbol visibility on GCC. It appears that boost::error_info also needs to be decorated with default visibility. Otherwise, calls to get_error_info on exceptions propagated across library boundaries will always return NULL, rendering boost::exception essentially useless. </p> </description> <category>Ticket</category> </item> <item> <author>Dimitrij Drus <dadrus@…></author> <pubDate>Tue, 14 Jun 2011 23:31:01 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4594#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4594#comment:9</guid> <description> <p> Why should one be interested in catching boost::exception_detail::clone_base? Its just an internal detail. Either one want catch an own exception or the boost one. </p> </description> <category>Ticket</category> </item> <item> <author>Jonathan Jones <jonathan.jones@…></author> <pubDate>Wed, 15 Jun 2011 13:59:40 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4594#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4594#comment:10</guid> <description> <p> You aren't interested in catching it directly. However, the implementation of boost::current_exception re-throws the exception and catches it as exception_detail::clone_base to determine if it's "cloneable". If exception_detail::clone_base doesn't have default visibility, boost::current_exception doesn't work if the exception originated from a different library. </p> </description> <category>Ticket</category> </item> <item> <author>mark.schisler@…</author> <pubDate>Fri, 08 Jul 2011 14:56:15 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4594#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4594#comment:11</guid> <description> <p> This bug is actually causing X-Code 4.01 and LLVM/GCC 4.2 to not link Boost 1.46.1 correctly with or without symbols hidden. I ended up with the following linker error. </p> <pre class="wiki">ld: bad codegen, pointer diff in boost::exception_detail::clone_impl&lt;boost::exception_detail::error_info_injector&lt;std::runtime_error&gt; &gt;::rethrow() constto global weak symbol vtable for boost::exceptionfor architecture i386 collect2: ld returned 1 exit status </pre><p> I'm not sure if it's a minimal solution or not, but I was able to resolve the problem by applying a fix similar to what was suggested by Jonathan. I enclosed exception/exception.hpp and exception/detail/exception_ptr.hpp in the following guards: </p> <pre class="wiki">#if defined(__GNUC__) # if (__GNUC__ == 4 &amp;&amp; __GNUC_MINOR__ &gt;= 1) || (__GNUC__ &gt; 4) # pragma GCC visibility push (default) # endif #endif #if defined(__GNUC__) # if (__GNUC__ == 4 &amp;&amp; __GNUC_MINOR__ &gt;= 1) || (__GNUC__ &gt; 4) # pragma GCC visibility pop # endif #endif </pre> </description> <category>Ticket</category> </item> <item> <author>Ethan Tira-Thompson <ejt@…></author> <pubDate>Fri, 15 Jul 2011 17:31:16 GMT</pubDate> <title>status, version changed; cc set; resolution deleted https://svn.boost.org/trac10/ticket/4594#comment:12 https://svn.boost.org/trac10/ticket/4594#comment:12 <ul> <li><strong>cc</strong> <span class="trac-author">ejt@…</span> added </li> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>version</strong> <span class="trac-field-old">Boost 1.40.0</span> → <span class="trac-field-new">Boost 1.47.0</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> <p> I confirm Mark's error, I see the same error also with Boost 1.47 (building Ogre3D on Xcode 4, gcc 4.2.1). </p> <p> I notice some visibility stuff was added to exception.hpp, but this is not enough. Apparently, error_info_injector and clone_impl (in exception/exception.hpp) both need to be wrapped with visibility pragmas in order to fix that error. </p> <p> Further, thread/exceptions.hpp also needs to be wrapped with visibility, or you will get: </p> <p> <code>ld: bad codegen, pointer diff in boost::thread_exception::thread_exception()to global weak symbol vtable for boost::thread_exceptionfor architecture i386</code> </p> Ticket Ethan Tira-Thompson <ejt@…> Fri, 15 Jul 2011 17:32:10 GMT attachment set https://svn.boost.org/trac10/ticket/4594 https://svn.boost.org/trac10/ticket/4594 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">thread_visibility.diff</span> </li> </ul> <p> Patch to support visibility with thread module </p> Ticket Ethan Tira-Thompson <ejt@…> Fri, 15 Jul 2011 17:37:38 GMT <link>https://svn.boost.org/trac10/ticket/4594#comment:13 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4594#comment:13</guid> <description> <p> Also, I'm not confident about the current visibility settings in exception. Will there be further linkage issues for other projects which use different features of boost? </p> <p> Perhaps the visibility pragmas should be wrapped around the all of the header contents for exception.hpp and exception_ptr.hpp as Mark suggested to ensure this isn't an ongoing issue. (This doesn't look to be an excessive amount of additional visible symbols, worth the margin of safety?) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Emil Dotchevski</dc:creator> <pubDate>Fri, 15 Jul 2011 17:50:25 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4594#comment:14 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4594#comment:14</guid> <description> <p> I am against making all classes visible. There aren't that many types that need to be visible. The first thing we need is a formal test in libs/exception/test. Can someone help writing this, so I can see all failures that need to be fixed on various platforms? </p> </description> <category>Ticket</category> </item> <item> <author>ian.esten@…</author> <pubDate>Mon, 12 Dec 2011 22:12:37 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4594#comment:15 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4594#comment:15</guid> <description> <p> I was having this problem with a dylib using boost::thread that linked to another dylib using boost::thread. The thread_visibility.diff patch solved the problem for me. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Emil Dotchevski</dc:creator> <pubDate>Thu, 22 Dec 2011 21:31:59 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4594#comment:16 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4594#comment:16</guid> <description> <p> I've committed only the Boost Exception part of thread_visibility.diff patch (that is, without the Boost Thread part of it.) Out of curiosity, do we really need the error_info_injector type to be visible? I don't understand why it is needed, but I haven't tested. </p> <p> Anyone care to add a test program to verify that visibility settings work across different platforms? </p> </description> <category>Ticket</category> </item> <item> <author>shreyas.bme@…</author> <pubDate>Sat, 28 Jan 2012 03:37:09 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4594#comment:17 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4594#comment:17</guid> <description> <p> Hi, </p> <p> I am getting following error. Please guide me. </p> <p> Boost version: 1_45_0 </p> <p> <em></em><em>/ERROR LOGS</em><em></em><em></em><em></em><em></em>/ </p> <p> <strong>ld: bad codegen, pointer diff in boost::signals::connection::connection(boost::signals::connection const&amp;)to global weak symbol boost::detail::spinlock_pool&lt;1&gt;::pool_ for architecture armv7 collect2: ld returned 1 exit status Command <a class="missing wiki">/Developer/Platforms</a>/iPhoneOS.platform/Developer/usr/bin/g++-4.2 failed with exit code 1</strong> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Emil Dotchevski</dc:creator> <pubDate>Sat, 28 Jan 2012 04:09:05 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4594#comment:18 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4594#comment:18</guid> <description> <p> Um, this doesn't seem to have anything to do with ticket 4594? </p> </description> <category>Ticket</category> </item> <item> <author>shreyas.bme@…</author> <pubDate>Sat, 28 Jan 2012 05:28:37 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4594#comment:19 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4594#comment:19</guid> <description> <p> Nope. Do you know solution? Please let me know. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Emil Dotchevski</dc:creator> <pubDate>Tue, 19 Jun 2012 23:57:56 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/4594#comment:20 https://svn.boost.org/trac10/ticket/4594#comment:20 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> I'm closing this, please reopen if visibility on some platform(s) is a problem. </p> Ticket anonymous_but_0X Mon, 20 Oct 2014 17:29:49 GMT <link>https://svn.boost.org/trac10/ticket/4594#comment:21 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4594#comment:21</guid> <description> <p> Hello everyone, </p> <p> hope you had a good weekend, I am afraid the problem is back, moving from LLVM xcode 4.4.1 to Apple LLVM 6.0 (10.9), I got it again, but I think I am not the only one. </p> <p> "boost::exception_detail::error_info_injector &lt;boost::gregorian::bad_month&gt;::error_info_injector(boost::exception_detail::error_info_injector&lt;boost::gregorian::bad_month&gt; const&amp;) to global weak symbol vtable for boost::exception_detail::error_info_injector&lt;boost::gregorian::bad_month&gt; means the weak symbol cannot be overridden at runtime. This was likely caused by different translation units being compiled with different visibility settings." </p> <p> the mysterious thin, and I think I need to question Ted Kremenek, because with the previous LD/compiler everything was fine according to their static analyzer, moving to the next version tool makes it incompatible, weak symbols that's just a convention how you stored them, Kremenek should use its magic wand and give solution.r </p> </description> <category>Ticket</category> </item> <item> <author>logens dou <logens@…></author> <pubDate>Sun, 11 Feb 2018 09:24:16 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4594#comment:22 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4594#comment:22</guid> <description> <p> Hi: </p> <blockquote> <p> i worked with boost1_58_0,it accors some error by compiled.please give me some suggest,thanks. </p> </blockquote> <p> errors: </p> <blockquote> <p> boost/asio/handler_type.hpp:20 boost/asio/detail/push_options.hpp:71:11: error :'pragma' is not allowed here </p> <blockquote> <p> #pragma GCC visibility push(default) </p> </blockquote> <p> boost/asio/detail/pop_options.hpp:71:11: error :expected decalration before end of line </p> </blockquote> </description> <category>Ticket</category> </item> <item> <dc:creator>Emil Dotchevski</dc:creator> <pubDate>Sun, 11 Feb 2018 19:48:28 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4594#comment:23 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4594#comment:23</guid> <description> <p> Which compiler? </p> </description> <category>Ticket</category> </item> </channel> </rss>