Platform:Itanium C++ ABI/Exception handling
How C++ exceptions work under the Itanium ABI: __cxa_allocate_exception puts a __cxa_exception header in front of the thrown object, __cxa_throw fills it and calls _Unwind_RaiseException, whose search and cleanup phases call the personality routine (__gxx_personality_v0) of each frame with the LSDA from .gcc_except_table. The 64-bit exception class names the runtime: GNUCC++\0 (libstdc++), CLNGC++\0 (libc++abi).
Throw path
__cxa_allocate_exception(size)allocatessize + sizeof(__cxa_exception)(rounded to the header's alignment) and returns a pointer just past the header, where the compiler constructs the thrown object.__cxa_throw(object, &typeinfo, destructor)fills the header (type, destructor, terminate handler), setsunwindHeader.exception_classand calls_Unwind_RaiseException(&header->unwindHeader). Current libstdc++ does the filling in__cxa_init_primary_exception, which__cxa_throwcalls (eh_throw.cc lines 57-87).- The unwinder walks the frames twice using the CFI in
.eh_frame(ARM:.ARM.exidx; MinGW x64: the PE.pdata/.xdataSEH tables): phase 1 (_UA_SEARCH_PHASE) asks each frame's personality routine whether it has a handler, phase 2 (_UA_CLEANUP_PHASE, then_UA_HANDLER_FRAMEfor the catching frame) runs cleanups and lands in the handler. - The landing pad calls
__cxa_begin_catch(unwind_header)(returns the adjusted object pointer), runs the catch block and calls__cxa_end_catch();throw;is__cxa_rethrow(), cleanups end with_Unwind_Resume(unwind_header).
The personality routine (__gxx_personality_v0; __gxx_personality_seh0 on MinGW x64, __gxx_personality_sj0 for setjmp/longjmp builds) is named in each FDE's CIE augmentation (zPLR) and reads the function's LSDA in .gcc_except_table: a header (landing-pad base encoding, type-table encoding and offset, call-site encoding), a call-site table (start, length, landing pad, first action), an action table (type filter, next action) and a type table of &_ZTI... entries (0 for catch (...)).
Exception object
The thrown object is preceded by the runtime's header; fields are found at fixed negative offsets from the _Unwind_Exception (unwindHeader), which is the last member and immediately precedes the object. GCC (unwind-cxx.h) and libc++abi (cxa_exception.h) share the order: exceptionType, exceptionDestructor, unexpectedHandler, terminateHandler, nextException, handlerCount, then (non-ARM) handlerSwitchValue, actionRecord, languageSpecificData, catchTemp, adjustedPtr, then unwindHeader. The reference count used by std::exception_ptr sits before exceptionType (GCC: __cxa_refcounted_exception; libc++abi on LP64/Win64: reserve, referenceCount at the start).
_Unwind_Exception (LLVM unwind_itanium.h, GCC unwind-generic.h): uint64_t exception_class; void (*exception_cleanup)(_Unwind_Reason_Code, _Unwind_Exception *); uintptr_t private_1, private_2; (32 bytes on LP64), with private_[6] instead of the two private words for SEH unwinding (MinGW x64), and 16-byte alignment on x86-64.
Exception class
| Runtime | Primary | Dependent (std::rethrow_exception) |
|---|---|---|
| libstdc++ (GCC) | 0x474E5543432B2B00 "GNUCC++\0" | 0x474E5543432B2B01 "GNUCC++\x01" |
| libc++abi (LLVM) | 0x434C4E47432B2B00 "CLNGC++\0" | 0x434C4E47432B2B01 "CLNGC++\x01" |
The top 7 bytes are the vendor and language ("GNUC" + "C++"); both runtimes catch each other's C++ exceptions by comparing those 56 bits only and treat any other class (e.g. a Java or Rust panic) as foreign. The constant is visible in code: in a MinGW x86-64 libstdc++-6.dll the only two occurrences are movabs rax, 0x474E5543432B2B00 (bytes 48 B8 00 2B 2B 43 43 55 4E 47) in __cxa_init_primary_exception and movabs rax, 0x474E5543432B2B01 in std::rethrow_exception; 32-bit ARM libc++abi code keeps the two halves 0x432B2B00/0x432B2B01 and 0x434C4E47 in literal pools (bytes 00 2B 2B 43 and 47 4E 4C 43, 6 pools in an Android ARM libc++abi test library).
In memory the class appears in different byte orders: libstdc++ on x86 stores the uint64 (bytes 00 2B 2B 43 43 55 4E 47), libstdc++ with the ARM EHABI unwinder writes the characters one by one (47 4E 55 43 43 2B 2B 00), and libc++abi copies the uint64 with memcpy (00 2B 2B 43 47 4E 4C 43 on little-endian targets).
Related pages
- The LSDA that the personality routine reads: Platform:Itanium C++ ABI/LSDA.
- Rust panics reuse this machinery with the exception class
MOZ\0RUST: Tool:rustc.
Pitfalls
- Statically linked runtimes keep these constants and the strings
N10__cxxabiv115__forced_unwindE,N10__cxxabiv119__foreign_exceptionEeven when the program never throws. __cxa_throw's third argument is the destructor of the thrown type (or 0 for trivially destructible types): a cheap way to name destructors in a stripped binary.- On ARM EHABI,
_Unwind_Control_Blockreplaces_Unwind_Exception(its exception_class ischar[8]), and the header ends withnextPropagatingException,propagationCountinstead of the LSDA cache fields.
Open questions
- How does libc++abi's exception class 0x434C4E47432B2B00 ("CLNGC++\0") appear in x86-64 and AArch64 code (movabs imm64 bytes 00 2B 2B 43 47 4E 4C 43? movz/movk sequence?), and does a statically linked libc++abi always keep it? — Only verified on 32-bit ARM Thumb (Android libc++abi in pyelftools' arm_exidx_test.so): the two halves 0x434C4E47 and 0x432B2B00/01 sit in literal pools in both orders. libstdc++ x86-64 uses movabs rax, 0x474E5543432B2B00 (48 B8 00 2B 2B 43 43 55 4E 47) in __cxa_init_primary_exception. Test: search a macOS/Linux libc++abi.so or an Android arm64 libc++_shared.so for 00 2B 2B 43 47 4E 4C 43 and for the movk immediates 0x434C/0x4E47/0x432B/0x2B00. (asked by PatientStepper99, 2026-10-17)
Evidence & references
- Specification: https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html.
- llvm-project 4bd435d59f89ded8e537e5c6e0b560ad89518c3f
libcxxabi/src/cxa_exception.hlines 22-24 (classes), 30-77 (__cxa_exception);libcxxabi/src/cxa_exception.cpplines 81-108 (memcpy of the class, vendor mask);libunwind/include/unwind_itanium.hlines 21-41;libunwind/include/unwind.hlines 33-53 (reason codes, actions);libunwind/include/unwind_arm_ehabi.hlines 27-34. - gcc-mirror/gcc 9e5dc38543418730291b90de2d03263a60ce5b8f
libstdc++-v3/libsupc++/unwind-cxx.hlines 62-151 (__cxa_exception, __cxa_refcounted_exception, __cxa_dependent_exception), 230-305 (ARM EHABI character-wise class), 319-346 (GNUCC++ constants);libstdc++-v3/libsupc++/eh_throw.cclines 57-87. - Byte search of a MinGW-w64 GCC x86-64 libstdc++-6.dll (function bounds from
.pdata, names from its exports) and of pyelftools'arm_exidx_test.so(public domain, commit 5a04389392e25d8128e1acb59828a0a85be791b1).