Added an implementation for uncaught_exceptions for libc++abi.

This should fix compilation errors due to missing declaration of
__cxa_get_globals when compiled against libc++ on Linux.
This commit is contained in:
Andrey Semashev
2019-01-07 02:14:31 +03:00
parent 6f3e6254e7
commit cdcc50a455

View File

@ -46,16 +46,23 @@
#if defined(BOOST_CORE_HAS_CXXABI_H)
// MinGW GCC 4.4 seem to not work the same way the newer GCC versions do. As a result, __cxa_get_globals based implementation will always return 0.
// Just disable it for now and fall back to std::uncaught_exception().
#if !defined(__MINGW32__) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)))
#if !(defined(__MINGW32__) && (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) < 405))
#include <cxxabi.h>
// On Linux with clang and libc++, there is a version of cxxabi.h from libc++-abi that doesn't declare __cxa_get_globals, but provides __cxa_uncaught_exceptions.
#if defined(_LIBCPPABI_VERSION)
#define BOOST_CORE_HAS_CXA_UNCAUGHT_EXCEPTIONS
#else
#define BOOST_CORE_HAS_CXA_GET_GLOBALS
// Only MinGW GCC 4.7 declares __cxa_get_globals() in cxxabi.h, older compilers do not expose this function but it's there
#if defined(__MINGW32__) && defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) < 407
// On MinGW only GCC 4.7 declares __cxa_get_globals() in cxxabi.h, older compilers do not expose this function but it's there.
// Note that at least on FreeBSD 11, cxxabi.h declares __cxa_get_globals with a different exception specification, so we can't declare the function unconditionally.
#if (defined(__MINGW32__) && defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) < 407)
namespace __cxxabiv1 {
struct __cxa_eh_globals;
extern "C" __cxa_eh_globals* __cxa_get_globals() BOOST_NOEXCEPT_OR_NOTHROW __attribute__((__const__));
} // namespace __cxxabiv1
#endif // defined(__MINGW32__) && defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) < 407
#endif
#endif
#endif
#endif // defined(BOOST_CORE_HAS_CXXABI_H)
@ -87,6 +94,9 @@ inline unsigned int uncaught_exceptions() BOOST_NOEXCEPT
#if defined(BOOST_CORE_HAS_UNCAUGHT_EXCEPTIONS)
// C++17 implementation
return static_cast< unsigned int >(std::uncaught_exceptions());
#elif defined(BOOST_CORE_HAS_CXA_UNCAUGHT_EXCEPTIONS)
// libc++abi extension
return static_cast< unsigned int >(abi::__cxa_uncaught_exceptions());
#elif defined(BOOST_CORE_HAS_CXA_GET_GLOBALS)
// Tested on {clang 3.2,GCC 3.5.6,GCC 4.1.2,GCC 4.4.6,GCC 4.4.7}x{x32,x64}
return *(reinterpret_cast< const unsigned int* >(reinterpret_cast< const char* >(::abi::__cxa_get_globals()) + sizeof(void*))); // __cxa_eh_globals::uncaughtExceptions, x32 offset - 0x4, x64 - 0x8
@ -105,6 +115,7 @@ inline unsigned int uncaught_exceptions() BOOST_NOEXCEPT
#undef BOOST_CORE_HAS_CXXABI_H
#undef BOOST_CORE_HAS_CXA_GET_GLOBALS
#undef BOOST_CORE_HAS_CXA_UNCAUGHT_EXCEPTIONS
#undef BOOST_CORE_HAS_UNCAUGHT_EXCEPTIONS
#undef BOOST_CORE_HAS_GETPTD