Boost C++ Libraries: Ticket #2309: Lack of g++ symbol visibility support in Boost.Thread https://svn.boost.org/trac10/ticket/2309 <p> Compiling code which includes boost/thread.hpp with </p> <p> g++ -fvisibility=hidden </p> <p> leads to a lack of visibility of symbols inside Boost.Thread. As a result, boost::thread_interrupted exception cannot be caught in the client code. </p> <p> The attached example yields </p> <p> Thread 0x60b050 caught something else Thread 0x60b3e0 caught something else </p> <p> instead of </p> <p> Thread 0x60b050 got interrupted Thread 0x60b3e0 got interrupted </p> <p> More information on this topic can be found in the respective thread on boost:users mailing list, especially the following two postings: </p> <p> <a class="ext-link" href="http://lists.boost.org/boost-users/2008/09/40268.php"><span class="icon">​</span>http://lists.boost.org/boost-users/2008/09/40268.php</a> <a class="ext-link" href="http://lists.boost.org/boost-users/2008/09/40270.php"><span class="icon">​</span>http://lists.boost.org/boost-users/2008/09/40270.php</a> </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2309 Trac 1.4.3 rbock@… Tue, 09 Sep 2008 08:16:56 GMT attachment set https://svn.boost.org/trac10/ticket/2309 https://svn.boost.org/trac10/ticket/2309 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">BoostThreads.cpp</span> </li> </ul> <p> Small sample, compile with g++ -fvisibility-hidden and link with the shared object instead of the static library </p> Ticket Jürgen Hunold Wed, 10 Sep 2008 16:58:25 GMT <link>https://svn.boost.org/trac10/ticket/2309#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2309#comment:1</guid> <description> <p> This is related to <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2114" title="#2114: Patches: Patch for export symbols from shared library (closed: obsolete)">#2114</a>. That issue contains a patch adding visibility support for most Boost Libraries. </p> </description> <category>Ticket</category> </item> <item> <author>Scott Bailey <Bailey@…></author> <pubDate>Tue, 09 Feb 2010 20:53:32 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/2309 https://svn.boost.org/trac10/ticket/2309 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">thread_interrupted.patch</span> </li> </ul> <p> created vs Boost v 1.42.0 to add visibility to boost::thread's exceptions </p> Ticket Scott Bailey <Bailey@…> Tue, 09 Feb 2010 21:08:34 GMT keywords, milestone changed; cc set https://svn.boost.org/trac10/ticket/2309#comment:3 https://svn.boost.org/trac10/ticket/2309#comment:3 <ul> <li><strong>cc</strong> <span class="trac-author">Bailey@…</span> added </li> <li><strong>keywords</strong> thread thread_interrupted added </li> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.37.0</span> → <span class="trac-field-new">Boost 1.43.0</span> </li> </ul> <h2 class="section" id="Description">Description</h2> <p> thread_interrupted can't be caught when crossing shared object's boundaries when visibility is hidden. </p> <h2 class="section" id="FoundIn">Found In</h2> <p> Boost v1.40, v1.41, and 1.42 </p> <h2 class="section" id="Recreating">Recreating</h2> <p> Here is the setup: </p> <p> <code>MyCommon.so</code> </p> <ul><li>this lib contains some basic classes, one of which (<code>baseTRx</code>) has a <code>boost::thread</code>. </li><li>this lib includes <code>boost_system</code> and <code>boost_thread</code> using the --whole-archive flag (linux) and equivalent for darwin and win -- this was done to minimize the number of files the customer would receive, among other reasons... </li></ul><p> <code>MyTRx.so</code> </p> <ul><li>this lib contains a class derived from <code>baseTRx</code> (<code>myTRx</code>). </li><li>links to <code>MyCommon</code> </li></ul><p> <code>MyEXE</code> </p> <ul><li>this contains <code>main()</code>. </li><li>links to <code>MyCommon</code> </li><li>loads <code>MyTRx</code> at run time. </li><li>creates an instance of <code>myTRx</code>. </li><li>signals <code>MyEXE</code> (via <code>interupt()</code>) when its time to cleanly shut down </li></ul><p> Using GCC 4.2 w/ <strong>-fvisibility=hidden</strong>, <strong>thread_interrupted isn't being caught</strong> in <code>myTRx</code> since it's being thrown from a different so with <em>hidden visibility</em>. </p> <h2 class="section" id="PossibleFixes">Possible Fixes</h2> <p> These are the options as I see them: </p> <ul><li>push, then set visibility to default in the BOOST_ABI_PREFIX. Then pop in the BOOST_ABI_SUFFIX. </li><li>add class decorators to modify visibility of exceptions </li></ul><p> I provided a patch (<a class="attachment" href="https://svn.boost.org/trac10/attachment/ticket/2309/thread_interrupted.patch" title="Attachment 'thread_interrupted.patch' in Ticket #2309">thread_interrupted.patch</a><a class="trac-rawlink" href="https://svn.boost.org/trac10/raw-attachment/ticket/2309/thread_interrupted.patch" title="Download">​</a>) for the second option. I am using this patch in a production environment. </p> <h2 class="section" id="SimilarpossiblyRelatedDefects">Similar/possibly Related Defects</h2> <p> This is similar to the following defects: </p> <ul><li><a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2114" title="#2114: Patches: Patch for export symbols from shared library (closed: obsolete)">#2114</a> Patch for export symbols from shared library </li></ul> Ticket viboes Sun, 04 Dec 2011 10:38:19 GMT owner, status, milestone changed https://svn.boost.org/trac10/ticket/2309#comment:4 https://svn.boost.org/trac10/ticket/2309#comment:4 <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>milestone</strong> <span class="trac-field-old">Boost 1.43.0</span> → <span class="trac-field-new">Boost 1.49.0</span> </li> </ul> <p> Committed in trunk At revision: 75799 </p> Ticket viboes Sat, 07 Jan 2012 21:48:29 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2309#comment:5 https://svn.boost.org/trac10/ticket/2309#comment:5 <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">fixed</span> </li> </ul> <p> Committed in release at <a class="missing ticket">#76291</a> </p> Ticket