main → foo() → bar() → throw MyException(); → __cxa_throw (sets unwind info, calls _Unwind_RaiseException) → _Unwind_RaiseException → _Unwind_RaiseException_Phase1 (walks .eh_frame) → _Unwind_RaiseException_Phase2 (calls personality, destructors) → __gxx_personality_v0 (calls destructors of locals in bar, foo) → land on catch in main On Linux: readelf -S a.out (look for .init_array , .eh_frame , .gcc_except_table ) On Windows: dumpbin /HEADERS myapp.exe (look for .pdata for x64 exception tables) This report is based on the Itanium C++ ABI (version 1.2), Microsoft C++ ABI (x64), and publicly available documentation for GCC 13, Clang 17, and MSVC 2022.
:
Report ID: CPP-RT-2024-01 Date: April 14, 2026 Author: Systems Software Research Division Subject: Structure, Execution Flow, and Overhead of the C++ Runtime Environment 1. Executive Summary The C++ runtime is the set of software components that support the execution of a compiled C++ program beyond the raw machine code generated by the compiler. Unlike C, which has a relatively minimal runtime, C++ requires substantial behind‑the‑scenes machinery to implement core language features: dynamic initialization of globals, exception handling, run‑time type information (RTTI), new / delete operators, and stack unwinding. This report dissects the C++ runtime into its constituent parts, traces the execution flow from _start to main and beyond, analyzes the cost of each runtime feature, and examines implementation variations across major compilers (GCC/Clang, MSVC) and operating systems. 2. Components of the C++ Runtime The C++ runtime is not monolithic. It consists of several logical layers:
static char instance_memory[sizeof(Logger)]; static uint8_t guard = 0; // 0 = uninitialized, 1 = initializing, 2 = done if (guard == 2) goto done; if (__cxa_guard_acquire(&guard)) new (instance_memory) Logger(); __cxa_guard_release(&guard); __cxa_atexit(destroyer, instance_memory, __dso_handle);
static Logger& getLogger() static Logger instance; // thread‑safe initialization return instance;
must return a pointer to the start of the most derived object. The runtime computes this by following a “offset to top” field stored in the vtable.