boostorg / exception

Boost.org exception module
http://boost.org/libs/exception
Boost Software License 1.0
15 stars 46 forks source link

boost::get_error_info() fails to lookup info for boost::stacktrace tag #37

Closed daverigby closed 3 years ago

daverigby commented 3 years ago

Summary

On macOS Catalina when throwing a boost::enable_error_info annotated exception from a shared library, then catching it from the main executable, and built with default symbol visibility to “hidden”, get_error_info() from main exe fails to locate exception details.

Steps to reproduce

See reproducer at https://github.com/daverigby/boost_error_info_visibility

Analysis

Thanks to @pdimov on #boost cpplang slack, we identified that a number of symbols in exception / stacktrace need BOOST_SYMBOL_VISIBLE applying. In my local Boost 1.75 world adding to the forward-decl and defns of all of the following was required to make the test pass:

daverigby commented 3 years ago

Note: Adding the following forward-decls to the above testcase is sufficient to workaround the issue:

#define PUBLIC_API __attribute__((visibility("default")))

namespace boost {
template <class Tag, class T>
class PUBLIC_API error_info;
};
namespace boost { namespace exception_detail {
class PUBLIC_API error_info_base;
};
};
namespace boost { namespace stacktrace {
class PUBLIC_API frame;
template <class Allocator> class PUBLIC_API basic_stacktrace;
};
};

Testcase updated to include this (commented out).

daverigby commented 3 years ago

Applied changes from feature/symbol_visibility_test to my local Boost 1.75 via homebewl (I don't have build of boost from source):

git diff origin/develop..origin/feature/symbol_visibility_test include/boost/exception > ~/scratch/boost_exception_strcmp.patch
cd /usr/local/include/boost/exception && patch -p4 < ~/scratch/boost_exception_strcmp.patch

This now passes the above testcase 👍

zajo commented 3 years ago

Merged into develop.