Prepare for running on top of new libc++abi.

llvm-svn: 149634
Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: 2c9c6a579a8f3d4f7c65b8073ef8fc6a64a7fa76
diff --git a/src/exception.cpp b/src/exception.cpp
index 26d97a9..40327d6 100644
--- a/src/exception.cpp
+++ b/src/exception.cpp
@@ -12,14 +12,17 @@
 
 #if __APPLE__
   #include <cxxabi.h>
+
   using namespace __cxxabiv1;
-  using namespace __cxxabiapple;
-  // On Darwin, there are two STL shared libraries and a lower level ABI
-  // shared libray.  The globals holding the current terminate handler and
-  // current unexpected handler are in the ABI library.
-  #define __terminate_handler  __cxxabiapple::__cxa_terminate_handler
-  #define __unexpected_handler __cxxabiapple::__cxa_unexpected_handler
   #define HAVE_DEPENDENT_EH_ABI 1
+  #ifndef _LIBCPPABI_VERSION
+    using namespace __cxxabiapple;
+    // On Darwin, there are two STL shared libraries and a lower level ABI
+    // shared libray.  The globals holding the current terminate handler and
+    // current unexpected handler are in the ABI library.
+    #define __terminate_handler  __cxxabiapple::__cxa_terminate_handler
+    #define __unexpected_handler __cxxabiapple::__cxa_unexpected_handler
+  #endif  // _LIBCPPABI_VERSION
 #elif defined(LIBCXXRT)
   #include <cxxabi.h>
   using namespace __cxxabiv1;
@@ -29,7 +32,8 @@
   static std::unexpected_handler __unexpected_handler;
 #endif  // __APPLE__
 
-#ifndef LIBCXXRT
+#if !defined(LIBCXXRT) && !defined(_LIBCPPABI_VERSION)
+
 // libcxxrt provides implementations of these functions itself.
 std::unexpected_handler
 std::set_unexpected(std::unexpected_handler func) _NOEXCEPT
@@ -84,13 +88,13 @@
     }
 #endif  // _LIBCPP_NO_EXCEPTIONS
 }
-#endif // LIBCXXRT
+#endif // !defined(LIBCXXRT) && !defined(_LIBCPPABI_VERSION)
 
 bool std::uncaught_exception() _NOEXCEPT
 {
 #if __APPLE__
     // on Darwin, there is a helper function so __cxa_get_globals is private
-    return __cxxabiapple::__cxa_uncaught_exception();
+    return __cxa_uncaught_exception();
 #elif LIBCXXRT
     __cxa_eh_globals * globals = __cxa_get_globals();
     return (globals->uncaughtExceptions != 0);
@@ -103,6 +107,8 @@
 namespace std
 {
 
+#ifndef _LIBCPPABI_VERSION
+
 exception::~exception() _NOEXCEPT
 {
 }
@@ -121,6 +127,8 @@
   return "std::bad_exception";
 }
 
+#endif  // _LIBCPPABI_VERSION
+
 exception_ptr::~exception_ptr() _NOEXCEPT
 {
 #if HAVE_DEPENDENT_EH_ABI
diff --git a/src/new.cpp b/src/new.cpp
index f2987b1..dfeb5a1 100644
--- a/src/new.cpp
+++ b/src/new.cpp
@@ -13,14 +13,19 @@
 
 #if __APPLE__
     #include <cxxabi.h>
-    // On Darwin, there are two STL shared libraries and a lower level ABI
-    // shared libray.  The global holding the current new handler is
-    // in the ABI library and named __cxa_new_handler.
-    #define __new_handler __cxxabiapple::__cxa_new_handler
+
+    #ifndef _LIBCPPABI_VERSION
+        // On Darwin, there are two STL shared libraries and a lower level ABI
+        // shared libray.  The global holding the current new handler is
+        // in the ABI library and named __cxa_new_handler.
+        #define __new_handler __cxxabiapple::__cxa_new_handler
+    #endif
 #else  // __APPLE__
     static std::new_handler __new_handler;
 #endif
 
+#ifndef _LIBCPPABI_VERSION
+
 // Implement all new and delete operators as weak definitions
 // in this shared library, so that they can be overriden by programs
 // that define non-weak copies of the functions.
@@ -129,11 +134,15 @@
     ::operator delete[](ptr);
 }
 
+#endif
+
 namespace std
 {
 
 const nothrow_t nothrow = {};
 
+#ifndef _LIBCPPABI_VERSION
+
 new_handler
 set_new_handler(new_handler handler) _NOEXCEPT
 {
@@ -174,6 +183,8 @@
     return "bad_array_new_length";
 }
 
+#endif
+
 void
 __throw_bad_alloc()
 {
diff --git a/src/typeinfo.cpp b/src/typeinfo.cpp
index 9ca03a1..129998e 100644
--- a/src/typeinfo.cpp
+++ b/src/typeinfo.cpp
@@ -13,6 +13,8 @@
 
 #include "typeinfo"
 
+#ifndef _LIBCPPABI_VERSION
+
 std::bad_cast::bad_cast() _NOEXCEPT
 {
 }
@@ -48,3 +50,4 @@
   void __cxxabiv1::__cxa_bad_cast() { throw std::bad_cast(); }
 #endif
 
+#endif  // _LIBCPPABI_VERSION