This allows building libcxxabi with GCC on my system.

http://reviews.llvm.org/D5604

Files:
  src/cxa_default_handlers.cpp
  src/cxa_handlers.cpp
Index: src/cxa_default_handlers.cpp
===================================================================
--- src/cxa_default_handlers.cpp
+++ src/cxa_default_handlers.cpp
@@ -101,19 +101,29 @@
 unexpected_handler
 set_unexpected(unexpected_handler func) _NOEXCEPT
 {
-	if (func == 0)
-		func = default_unexpected_handler;
-	return __sync_swap(&__cxa_unexpected_handler, func);
+    if (func == 0)
+        func = default_unexpected_handler;
+#ifdef __clang__
+    return __sync_swap(&__cxa_unexpected_handler, func);
+#else
+    return __atomic_exchange_n(&__cxa_unexpected_handler, func,
+                               __ATOMIC_SEQ_CST);
+#endif
 //  Using of C++11 atomics this should be rewritten
 //  return __cxa_unexpected_handler.exchange(func, memory_order_acq_rel);
 }
 
 terminate_handler
 set_terminate(terminate_handler func) _NOEXCEPT
 {
-	if (func == 0)
-		func = default_terminate_handler;
-	return __sync_swap(&__cxa_terminate_handler, func);
+    if (func == 0)
+        func = default_terminate_handler;
+#ifdef __clang__
+    return __sync_swap(&__cxa_terminate_handler, func);
+#else
+    return __atomic_exchange_n(&__cxa_terminate_handler, func,
+                               __ATOMIC_SEQ_CST);
+#endif
 //  Using of C++11 atomics this should be rewritten
 //  return __cxa_terminate_handler.exchange(func, memory_order_acq_rel);
 }
Index: src/cxa_handlers.cpp
===================================================================
--- src/cxa_handlers.cpp
+++ src/cxa_handlers.cpp
@@ -102,14 +102,18 @@
     __terminate(get_terminate());
 }
 
-extern "C" new_handler __cxa_new_handler = 0;
+new_handler __cxa_new_handler = 0;
 // In the future these will become:
 // std::atomic<std::new_handler>  __cxa_new_handler(0);
 
 new_handler
 set_new_handler(new_handler handler) _NOEXCEPT
 {
+#ifdef __clang__
     return __sync_swap(&__cxa_new_handler, handler);
+#else
+    return __atomic_exchange_n(&__cxa_new_handler, handler, __ATOMIC_SEQ_CST);
+#endif
 //  Using of C++11 atomics this should be rewritten
 //  return __cxa_new_handler.exchange(handler, memory_order_acq_rel);
 }
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to