C++ Runtime Online

static Logger& getLogger() static Logger instance; // thread‑safe initialization return instance;

| 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 ) |

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. c++ runtime

vtable for B: [0] offset_to_top = 0 [1] typeinfo pointer -> typeinfo for B [2] A::foo() thunk (if overriding) vtable for A: [0] offset_to_top = 0 [1] typeinfo pointer -> typeinfo for A

:

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 .

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); mov x0, :got:globalString bl _ZNSt7__cxx1112basic_string

// Constructor function for global std::string _GLOBAL__sub_I_example.cpp: stp x29, x30, [sp, -32]! mov x0, :got:globalString bl _ZNSt7__cxx1112basic_string...C1E... // std::string::string(char const*) ldr x0, :got:__dso_handle adrp x1, :got:_ZNSt7__cxx1112basic_string...D1E... add x1, x1, :lo12:_ZNSt7__cxx1112...D1E... bl __cxa_atexit // register destructor for atexit ldp x29, x30, [sp], 32 ret // .init_array entry points to this function