Factory.ai

Open-Source Wikis

/

LLVM

/

Subprojects

/

libcxxabi

llvm/llvm-project

libcxxabi

libcxxabi/ is libc++abi — the LLVM project's implementation of the C++ ABI runtime. It implements the low-level "Itanium C++ ABI" routines that the language and the standard library expect from a runtime: __cxa_throw, __cxa_begin_catch, RTTI types, the array new/delete personalities, dynamic-cast support, thread-safe-statics initialization, and friends.

Purpose

A C++ implementation has roughly three layers — the language as compiled by the front end, the C++ standard library, and the language runtime. libc++abi is the third layer: the runtime that the front end (Clang) emits calls into for things like throw expr; and that the standard library (libc++) calls into for things like terminate(). Most users encounter it indirectly — it ships transparently as part of the toolchain.

Directory layout

libcxxabi/
├── include/        # Public ABI headers (cxxabi.h, __cxxabi_config.h)
├── src/            # Implementation
│   ├── cxa_*       # Itanium ABI entry points
│   ├── stdlib_*    # std-library-side helpers (typeinfo, exception, ...)
│   ├── demangle/   # Demangler — also exposed to llvm
│   ├── private_typeinfo.cpp / .h  # The fast-path RTTI implementation
│   └── ...
├── test/           # lit regression tests
├── cmake/
├── lib/            # ABI version files
├── docs/
├── fuzz/
└── CMakeLists.txt

What's implemented

The Itanium C++ ABI surface includes (this is a partial list):

Function Purpose
__cxa_throw / __cxa_rethrow throw and throw;
__cxa_begin_catch / __cxa_end_catch catch-block prologue/epilogue
__cxa_allocate_exception / __cxa_free_exception exception object lifetime
__cxa_get_exception_ptr / __cxa_current_exception_type introspection
__cxa_pure_virtual, __cxa_deleted_virtual called when a vcall reaches an abstract or deleted virtual
__cxa_guard_acquire / __cxa_guard_release / __cxa_guard_abort thread-safe-statics
__cxa_atexit, __cxa_thread_atexit_impl atexit for objects with non-trivial destructors
__cxa_demangle symbol demangling — also used by c++filt, llvm-symbolizer, lldb
dynamic_cast / __cxxabiv1::__dynamic_cast RTTI-based downcast
typeid / std::type_info virtuals RTTI value type
Array-new/array-delete cookies new T[] cleanup
Thread-local-storage helpers per-platform glue

Implementation files map to these names: src/cxa_exception.cpp, src/cxa_handlers.cpp, src/cxa_personality.cpp, src/cxa_guard.cpp, etc.

How it works

graph LR
    code["throw foo;"] -->|emit| call1["__cxa_allocate_exception<br/>__cxa_throw"]
    call1 --> personality[__gxx_personality_v0]
    personality --> unwinder[libunwind / system unwinder]
    unwinder --> handler[catch block found]
    handler --> bcatch[__cxa_begin_catch]
    bcatch --> user[user catch body]
    user --> ecatch[__cxa_end_catch]

When a program throws, the compiler emits a call to __cxa_allocate_exception to get a buffer for the thrown object, copies the object in, then calls __cxa_throw with the buffer and a pointer to its destructor. __cxa_throw invokes the unwinder, which walks frames calling each frame's personality function (__gxx_personality_v0 for the Itanium ABI) until it finds a matching catch. The catch dispatches through __cxa_begin_catch/__cxa_end_catch.

Integration points

  • libc++ (libcxx) — the paired standard library. libc++abi declares the type-info classes that libc++ uses for <typeinfo> and <exception>.
  • libunwind (libunwind) — the unwinder libc++abi calls into. Other unwinders work too on platforms that have their own (e.g., the OS-supplied Mach unwinder on macOS).
  • Clang — emits the calls. The __cxa_* symbol names and signatures are the ABI contract.
  • llvm core demangler (llvm/lib/Demangle/) shares code with libc++abi's demangler. They're kept in sync.

Entry points for modification

  • ABI changes here are very rare and require a release-note flag; the ABI is the contract.
  • Implementation tuning (e.g., faster RTTI matching) goes in private_typeinfo.cpp and the matching test under libcxxabi/test/.
  • Demangler updates typically also touch llvm/lib/Demangle/; the two trees share most of the implementation.

Reference

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

libcxxabi – LLVM wiki | Factory