Opened 14 years ago

Closed 11 years ago

#2309 closed Bugs (fixed)

Lack of g++ symbol visibility support in Boost.Thread

Reported by: rbock@… Owned by: viboes
Milestone: Boost 1.49.0 Component: thread
Version: Boost 1.36.0 Severity: Problem
Keywords: visibility catch exception thread thread_interrupted Cc: Bailey@…

Description

Compiling code which includes boost/thread.hpp with

g++ -fvisibility=hidden

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.

The attached example yields

Thread 0x60b050 caught something else Thread 0x60b3e0 caught something else

instead of

Thread 0x60b050 got interrupted Thread 0x60b3e0 got interrupted

More information on this topic can be found in the respective thread on boost:users mailing list, especially the following two postings:

http://lists.boost.org/boost-users/2008/09/40268.php http://lists.boost.org/boost-users/2008/09/40270.php

Attachments (2)

BoostThreads.cpp (964 bytes ) - added by rbock@… 14 years ago.
Small sample, compile with g++ -fvisibility-hidden and link with the shared object instead of the static library
thread_interrupted.patch (2.6 KB ) - added by Scott Bailey <Bailey@…> 13 years ago.
created vs Boost v 1.42.0 to add visibility to boost::thread's exceptions

Download all attachments as: .zip

Change History (6)

by rbock@…, 14 years ago

Attachment: BoostThreads.cpp added

Small sample, compile with g++ -fvisibility-hidden and link with the shared object instead of the static library

comment:1 by Jürgen Hunold, 14 years ago

This is related to #2114. That issue contains a patch adding visibility support for most Boost Libraries.

by Scott Bailey <Bailey@…>, 13 years ago

Attachment: thread_interrupted.patch added

created vs Boost v 1.42.0 to add visibility to boost::thread's exceptions

comment:3 by Scott Bailey <Bailey@…>, 13 years ago

Cc: Bailey@… added
Keywords: thread thread_interrupted added
Milestone: Boost 1.37.0Boost 1.43.0

Description

thread_interrupted can't be caught when crossing shared object's boundaries when visibility is hidden.

Found In

Boost v1.40, v1.41, and 1.42

Recreating

Here is the setup:

MyCommon.so

  • this lib contains some basic classes, one of which (baseTRx) has a boost::thread.
  • this lib includes boost_system and boost_thread 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...

MyTRx.so

  • this lib contains a class derived from baseTRx (myTRx).
  • links to MyCommon

MyEXE

  • this contains main().
  • links to MyCommon
  • loads MyTRx at run time.
  • creates an instance of myTRx.
  • signals MyEXE (via interupt()) when its time to cleanly shut down

Using GCC 4.2 w/ -fvisibility=hidden, thread_interrupted isn't being caught in myTRx since it's being thrown from a different so with hidden visibility.

Possible Fixes

These are the options as I see them:

  • push, then set visibility to default in the BOOST_ABI_PREFIX. Then pop in the BOOST_ABI_SUFFIX.
  • add class decorators to modify visibility of exceptions

I provided a patch (thread_interrupted.patch) for the second option. I am using this patch in a production environment.

Similar/possibly Related Defects

This is similar to the following defects:

  • #2114 Patch for export symbols from shared library

comment:4 by viboes, 11 years ago

Milestone: Boost 1.43.0Boost 1.49.0
Owner: changed from Anthony Williams to viboes
Status: newassigned

Committed in trunk At revision: 75799

comment:5 by viboes, 11 years ago

Resolution: fixed
Status: assignedclosed

Committed in release at #76291

Note: See TracTickets for help on using tickets.