Reference
ABI fingerprints
How CPM decides when a built library can be shared.
Compiled artifacts can be reused only by consumers whose toolchain and settings produce compatible binaries. CPM captures those settings in an ABI fingerprint:
a set of key=value inputs and their SHA-256. The first 16 hex characters of the hash name the store directory lib/<abi16>/ and the registry binaries key.
1. Inputs
Inputs marked "always" are present for every toolchain. Values are lowercase ASCII.
| Key | When | Values / source |
|---|---|---|
abi.scheme |
always | 1. Bumped whenever this table changes meaning, which invalidates every cached binary. |
os |
always | windows, linux, macos, freebsd (CPM's compile-time platform, cross-checked with the target triple) |
arch |
always | x86_64, aarch64, x86, arm (from the target triple) |
target |
always | The compiler's target triple: -dumpmachine (GCC/Clang). For MSVC: <arch>-pc-windows-msvc |
compiler |
always | gcc, clang, apple-clang, msvc, clang-cl |
compiler.version |
always | GCC: -dumpfullversion (13.2.0). Clang: __clang_major__.__clang_minor__.__clang_patchlevel__. MSVC: _MSC_FULL_VER (194435207) |
stdlib |
always | libstdc++, libc++, msvc-stl (from __GLIBCXX__, _LIBCPP_VERSION, _MSVC_STL_VERSION) |
stdlib.abi |
always | libstdc++: cxx11 if _GLIBCXX_USE_CXX11_ABI = 1, else cxx98. libc++: v<_LIBCPP_ABI_VERSION>. msvc-stl: <_MSVC_STL_VERSION> |
crt |
always | MinGW: ucrt (if _UCRT is defined) or msvcrt. Linux: glibc (__GLIBC__) or musl. macOS: libsystem. MSVC: ucrt |
eh |
GCC/Clang | Exception model: seh (__SEH__), dwarf, sjlj (__USING_SJLJ_EXCEPTIONS__), itanium (everything non-Windows) |
threads |
MinGW | posix, win32 or mcf (from -v → Thread model:) |
std |
always | The root package's std (c++23) |
runtime |
always | dynamic or static (profile runtime) |
debug-runtime |
MSVC | true or false (profile debugRuntime) |
pic |
always | true on Linux, macOS and FreeBSD (dependencies are always built PIC there). false on Windows |
sanitizers |
always | Sorted, comma-separated effective sanitizers, or empty |
defines.abi |
always | Sorted, comma-separated ABI-affecting definitions from the root profile and manifest (§2), or empty |
exceptions |
always | on, or off when the root's cxxflags contain -fno-exceptions (MSVC: no /EHsc) |
rtti |
always | on, or off when the root's cxxflags contain -fno-rtti / /GR- |
Not included, because these settings do not affect binary compatibility of static code: optimisation level, debug info, warnings, werror, LTO (dependencies are never LTO-compiled), and non-ABI definitions.
2. ABI-affecting definitions
A definition counts toward defines.abi if its name (the part before =) is in this list:
_GLIBCXX_DEBUG _GLIBCXX_DEBUG_PEDANTIC _GLIBCXX_USE_CXX11_ABI _GLIBCXX_FULLY_DYNAMIC_STRING
_LIBCPP_ABI_VERSION _LIBCPP_ABI_UNSTABLE _LIBCPP_HARDENING_MODE
_ITERATOR_DEBUG_LEVEL _HAS_ITERATOR_DEBUGGING _SECURE_SCL _HAS_EXCEPTIONS
or if it starts with _LIBCPP_ABI_. The list is part of abi.scheme 1.
3. Canonical encoding and hash
- Collect the inputs into a map. Every key in §1 that applies to the toolchain MUST be present; its value may be empty.
- Serialise as UTF-8 lines
key=value\n, sorted by key (byte-wise). Keys never contain=(a line is split at its first=), and values never contain\n; an input that would break this is rejected. Values may contain=, as indefines.abi=_GLIBCXX_USE_CXX11_ABI=0. hash= lowercase hex SHA-256 of the serialised bytes (64 characters).abi16= the first 16 characters ofhash. This nameslib/<abi16>/in the store and thebinarieskeys in the registry.- The full inputs are stored in
meta.jsonand compared on every use (store.md §2.2). A 64-bit prefix is collision-safe in practice, and the comparison catches any collision that does happen.
Example for this host (MinGW-w64 g++ 13.2.0, UCRT, posix threads, SEH, std: c++23, debug profile):
abi.scheme=1
arch=x86_64
compiler=gcc
compiler.version=13.2.0
crt=ucrt
defines.abi=
eh=seh
exceptions=on
os=windows
pic=false
rtti=on
runtime=dynamic
sanitizers=
std=c++23
stdlib=libstdc++
stdlib.abi=cxx11
target=x86_64-w64-mingw32
threads=posix
4. Probing
Fingerprint inputs are gathered without compiling or linking anything:
| Probe | Gives |
|---|---|
<cxx> -dumpfullversion and -dumpmachine |
compiler.version, target → arch, os |
<cxx> -v (stderr) |
Thread model: → threads; confirms the family (gcc version, clang version, Apple clang) |
<cxx> -std=<std> -x c++ -E -dM <probe.cpp> |
predefined and library macros: __clang__, __GNUC__, __GLIBCXX__, _GLIBCXX_USE_CXX11_ABI, _LIBCPP_VERSION, _LIBCPP_ABI_VERSION, _UCRT, __GLIBC__, __SEH__, __USING_SJLJ_EXCEPTIONS__ |
MSVC (post-MVP): cl /nologo /EP /Zc:preprocessor /TP probe.cpp |
_MSC_FULL_VER, _MSVC_STL_VERSION, _M_X64 / _M_ARM64 |
probe.cpp is generated in $CPM_HOME/tmp/ and contains only #include <version> and #include <cstdlib>. Probe results, minus the profile-dependent keys (std, runtime, debug-runtime, sanitizers, defines.abi, exceptions, rtti), are cached in toolchains.json (build.md §1.3). Building the fingerprint after the first run costs no subprocesses.
5. Where the fingerprint is used
- Store:
store/<entry>/lib/<abi16>/. - Registry binaries:
versions[v].binaries[<abi16>]. - Dependency builds: the sandbox build uses exactly the settings encoded in the fingerprint (build.md §5), so artifacts always match their directory.
- cpm_modules:
.cpm-modules.json→abirecords which ABI theliblinks point to.
On GCC and Clang the debug and release profiles normally produce the same fingerprint, because optimisation and debug info are excluded. Switching profiles therefore rebuilds no dependency. Sanitizers, runtime, ABI definitions, and on MSVC debugRuntime, do produce a new fingerprint.
From CPM's repository: docs/spec/abi.md