C++ Runtime Online
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 Logger& getLogger() static Logger instance; // thread‑safe initialization return instance;
done: return instance_memory;
| Component | Responsibility | Typical Implementation | |-----------|----------------|------------------------| | | Program startup, atoi , printf , heap base (malloc/free) | libc.so / msvcrt.dll | | C++ ABI Runtime | Constructor/destructor calling conventions, RTTI structures, exception personality routines | libstdc++ (GCC), libc++abi (LLVM), msvcrt + VCRuntime (MSVC) | | C++ Standard Library Runtime | std::vector , std::string , std::cout , std::thread | libstdc++.so , libc++.so , MSVC STL | | Language Support Library | new / delete operators, __cxa_* exception APIs, __gxx_personality_v0 | Part of ABI runtime | | Compiler‑Generated Helpers | Thunk functions for virtual calls, dynamic cast helpers, guard variables for static locals | Injected by compiler (e.g., __cxa_guard_acquire ) |
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. c++ runtime
When dynamic_cast<B*>(a_ptr) is performed, the runtime reads the vtable of the object to obtain the type_info of the most derived type and checks if it derives from B .