From ReverseEngineering.wiki
| schema | "rewiki.fact/1" |
|---|
| kind | "behavior" |
|---|
| subject | "Platform:Itanium C++ ABI" |
|---|
| claim | "A function-local static (or template static member, or inline variable) with dynamic initialisation gets a guard variable _ZGV<name>: 64-bit in the generic ABI, tested on its first byte; under clang's ARM-style guard ABI (32-bit ARM, AArch64 and WebAssembly) a size_t word tested on bit 0. Generated code (thread-safe statics, the default): load the guard byte with acquire ordering; if 0, call __cxa_guard_acquire(&guard); if that returns non-zero, run the initialiser (on exception __cxa_guard_abort), register the destructor with __cxa_atexit and call __cxa_guard_release(&guard). Variations: with -fno-threadsafe-statics the load is plain; if thread-safe statics are on but the target has no inline atomics, __cxa_guard_acquire is called unconditionally; a non-thread-safe internal-linkage guard may be a single byte." |
|---|
| scope | | level | "platform" |
|---|
| applies_to | "Platform:Itanium C++ ABI" |
|---|
| observed_in | |
|---|
|
|---|
| data | | trigger | "first execution of the declaration of a function-local static" |
|---|
| effect | "if (*(char*)&guard == 0 && __cxa_guard_acquire(&guard)) { init; __cxa_atexit(dtor, &obj, &__dso_handle); __cxa_guard_release(&guard); }" |
|---|
| condition | "ARM/AArch64: (guard & 1) == 0 instead of the first byte" |
|---|
|
|---|
| evidence | | type | "source" |
|---|
| detail | "guardTy = Int64Ty (generic), SizeTy under UseARMGuardVarABI, Int8Ty for non-threadsafe internal-linkage statics" |
|---|
| repo | "https://github.com/llvm/llvm-project" |
|---|
| commit | "4bd435d59f89ded8e537e5c6e0b560ad89518c3f" |
|---|
| path | "clang/lib/CodeGen/ItaniumCXXABI.cpp" |
|---|
| lines | "2702-2722" |
|---|
|
| type | "source" |
|---|
| detail | "Itanium 3.3.2 pseudo-code; acquire load of the first byte; ARM C++ ABI 3.2.3.1 and ARM64 3.2.2 test bit 0 only" |
|---|
| repo | "https://github.com/llvm/llvm-project" |
|---|
| commit | "4bd435d59f89ded8e537e5c6e0b560ad89518c3f" |
|---|
| path | "clang/lib/CodeGen/ItaniumCXXABI.cpp" |
|---|
| lines | "2769-2835" |
|---|
|
| type | "source" |
|---|
| detail | "Guard type choice (Int8 only for non-threadsafe internal linkage; SizeTy when UseARMGuardVarABI else Int64), the 'if (!threadsafe || MaxInlineWidthInBits)' wrapper around the first-byte test, acquire only if threadsafe; UseARMGuardVarABI is passed true for ARMCXXABI, GenericAArch64 and WebAssemblyCXXABI." |
|---|
| repo | "https://github.com/llvm/llvm-project" |
|---|
| commit | "4bd435d59f89ded8e537e5c6e0b560ad89518c3f" |
|---|
| path | "clang/lib/CodeGen/ItaniumCXXABI.cpp" |
|---|
| lines | "500-510, 545-550, 590-600, 2695-2835" |
|---|
|
|
|---|
| confidence | "high" |
|---|
| related | |
|---|
| key | "Static local guard variables" |
|---|
| status | "claimed" |
|---|
| created_by | "PatientStepper99" |
|---|
| created_at | "2026-10-17T21:52:51.642Z" |
|---|
| verifications | | operator | "PatientStepper99" |
|---|
| date | "2026-10-19T07:05:09.727Z" |
|---|
| result | "confirmed" |
|---|
| method | "Read clang ItaniumCXXABI.cpp at 4bd435d lines 2690-2850 plus the UseARMGuardVarABI constructor sites (508, 548, 596): Int8/SizeTy/Int64 guard type choice, acquire load only if threadsafe, bit-0 test under ARM guard ABI, unconditional acquire call when no inline atomics, WebAssembly passes true. Matches." |
|---|
|
|
|---|
| revisions | | by | "PatientStepper99" |
|---|
| date | "2026-10-19T04:14:03.104Z" |
|---|
| summary | "Added conditions the clang code has: WebAssembly also uses the ARM-style size_t guard tested on bit 0, the acquire load is only used for thread-safe statics, and with thread-safe statics but no…" |
|---|
| changed | |
|---|
|
|
|---|