[compiler-rt] [asan] Build the asan_new_delete.cpp C++ slice with -frtti (PR #213077)

David Justo via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 23 14:58:16 PDT 2026


================
@@ -188,6 +188,16 @@ if(COMPILER_RT_ASAN_ENABLE_EXCEPTIONS AND COMPILER_RT_HAS_FEXCEPTIONS_FLAG)
   list(APPEND ASAN_CXX_CFLAGS -fexceptions)
   list(REMOVE_ITEM ASAN_DYNAMIC_CXX_CFLAGS -fno-exceptions)
   list(APPEND ASAN_DYNAMIC_CXX_CFLAGS -fexceptions)
+  # The throwing operator new throws std::bad_alloc. Under -fno-rtti clang emits a
+  # private type_info copy a user `catch` can't match on Mach-O. ELF avoids this
+  # only via linker coalescing of the weak copies, which is not guaranteed
+  # (e.g. defeated by `-Bsymbolic`). Build with -frtti to use libc++abi's copy.
----------------
davidmrdavid wrote:

nit - please consider this alternative. I try to simplify the technicalities, while providing a 3rd-party reference that documents this issue with catching exceptions under RTTI in Mach-O.

```suggestion
  # The throwing operator new throws std::bad_alloc.
  # On Mach-O with -fno-rtti, clang may emit a separate type_info object for
  # std::bad_alloc instead of referring to the type_info object for `bad_alloc` in the chosen standard library.
  # If the objects remain distinct, a user's catch (const std::bad_alloc&)
  # may fail to match. See this example:
  # https://stackoverflow.com/questions/21737201/problems-throwing-and-catching-exceptions-on-os-x-with-fno-rtti
  # To avoid this, we enable RTTI, when available, for asan_new_delete.cpp
  # (listed in ASAN_CXX_SOURCES).
```

https://github.com/llvm/llvm-project/pull/213077


More information about the llvm-commits mailing list