Opened 14 years ago
Closed 11 years ago
#2309 closed Bugs (fixed)
Lack of g++ symbol visibility support in Boost.Thread
| Reported by: | 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)
Change History (6)
by , 14 years ago
| Attachment: | BoostThreads.cpp added |
|---|
comment:1 by , 14 years ago
This is related to #2114. That issue contains a patch adding visibility support for most Boost Libraries.
by , 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 , 13 years ago
| Cc: | added |
|---|---|
| Keywords: | thread thread_interrupted added |
| Milestone: | Boost 1.37.0 → Boost 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 aboost::thread. - this lib includes
boost_systemandboost_threadusing 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
MyTRxat run time. - creates an instance of
myTRx. - signals
MyEXE(viainterupt()) 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 , 11 years ago
| Milestone: | Boost 1.43.0 → Boost 1.49.0 |
|---|---|
| Owner: | changed from to |
| Status: | new → assigned |
Committed in trunk At revision: 75799
comment:5 by , 11 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
Committed in release at #76291

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