Case 103: Toolchain flag drift (toolchain_flag_drift)¶
| Field | Value |
|---|---|
| Verdict | ๐ข COMPATIBLE |
| Category | Quality (Compatible) |
| Platforms | Linux |
| Flags | Bad practice |
Detected ChangeKinds |
toolchain_flag_drift |
| Source files | examples/case103_toolchain_flag_drift/ |
Category: quality | Verdict: COMPATIBLE
What happens¶
The public API and every exported symbol are identical between v1 and
v2. The only thing that changed is the set of ABI-affecting compiler flags
used to build the shared library: v2 is compiled with -fshort-enums while
v1 is not.
In this minimal fixture there are no enums, so nothing in the symbol table or type layout actually changes โ but the flag drift is a leading indicator that the two builds were produced under different ABI assumptions. The same drift applied to a library that does expose enums, packed structs, or a different data model would silently change layout. Flag drift is reported on its own so the signal is visible before it turns into a real, harder-to-diagnose break.
Why abicheck catches it¶
abicheck parses DW_AT_producer from the DWARF debug info of each binary and
extracts the ABI-relevant flags (-fshort-enums, -fpack-struct,
-fno-common/-fcommon, -m32/-m64, -mabi=, -fabi-version=,
-D_GLIBCXX_USE_CXX11_ABI=). When the extracted flag sets differ between the
two versions it emits toolchain_flag_drift. This is a compatible
(informational) finding โ by itself it is not a guaranteed break, so it does
not fail a legacy compare, but it surfaces in reports as a quality signal.
Code diff¶
The sources are byte-for-byte identical. The difference lives entirely in the build configuration:
# v1 build
gcc -shared -fPIC -g -fvisibility=default -o libv1.so v1.c
# v2 build
-gcc -shared -fPIC -g -fvisibility=default -o libv2.so v2.c
+gcc -shared -fPIC -g -fvisibility=default -fshort-enums -o libv2.so v2.c
Reproduce manually¶
gcc -shared -fPIC -g -fvisibility=default -o libv1.so v1.c
gcc -shared -fPIC -g -fvisibility=default -fshort-enums -o libv2.so v2.c
# Inspect the recorded producer flags
readelf --debug-dump=info libv1.so | grep -m1 producer
readelf --debug-dump=info libv2.so | grep -m1 producer
# abicheck reports a single toolchain_flag_drift finding
python -m abicheck compare libv1.so libv2.so
How to fix¶
Build every translation unit of a published library โ and every consumer that shares its ABI surface โ with the same ABI-affecting flag set. Pin the flags in the build system and treat any drift as a release-blocking review item rather than relying on it being "harmless" in a given snapshot.
Source files¶
CMakeLists.txtapp.cv1.cv1.hv2.cv2.h
See also: Examples overview ยท All COMPATIBLE cases ยท Category: Quality (Compatible).