[libcxxabi] r311045 - [libcxxabi] When built with ASan, __cxa_throw calls __asan_handle_no_return

Petr Hosek via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 16 14:58:09 PDT 2017

Author: phosek
Date: Wed Aug 16 14:58:09 2017
New Revision: 311045

URL: http://llvm.org/viewvc/llvm-project?rev=311045&view=rev
[libcxxabi] When built with ASan, __cxa_throw calls __asan_handle_no_return

The ASan runtime on many systems intercepts cxa_throw just so it
can call asan_handle_no_return first. Some newer systems such as
Fuchsia don't use interceptors on standard library functions at all,
but instead use sanitizer-instrumented versions of the standard
libraries. When libc++abi is built with ASan, cxa_throw can just
call asan_handle_no_return itself so no interceptor is required.

Patch by Roland McGrath

Differential Revision: https://reviews.llvm.org/D36599


Modified: libcxxabi/trunk/src/cxa_exception.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_exception.cpp?rev=311045&r1=311044&r2=311045&view=diff
--- libcxxabi/trunk/src/cxa_exception.cpp (original)
+++ libcxxabi/trunk/src/cxa_exception.cpp Wed Aug 16 14:58:09 2017
@@ -19,6 +19,10 @@
 #include "cxa_handlers.hpp"
 #include "fallback_malloc.h"
+#if __has_feature(address_sanitizer)
+#include <sanitizer/asan_interface.h>
 // +---------------------------+-----------------------------+---------------+
 // | __cxa_exception           | _Unwind_Exception CLNGC++\0 | thrown object |
 // +---------------------------+-----------------------------+---------------+
@@ -217,6 +221,12 @@ __cxa_throw(void *thrown_object, std::ty
     globals->uncaughtExceptions += 1;   // Not atomically, since globals are thread-local
     exception_header->unwindHeader.exception_cleanup = exception_cleanup_func;
+#if __has_feature(address_sanitizer)
+    // Inform the ASan runtime that now might be a good time to clean stuff up.
+    __asan_handle_no_return();

More information about the cfe-commits mailing list