Case 55: Type Kind Changed (struct โ union)¶
| Field | Value |
|---|---|
| Verdict | ๐ด BREAKING |
| Category | Breaking |
| Platforms | Linux, macOS |
| Flags | ABI break, API break |
Detected ChangeKinds |
type_kind_changed |
| Source files | browse on GitHub |
Category: Type Layout | Verdict: BREAKING
What this case is about¶
v1 defines Data as a struct with two fields x and y laid out
sequentially (sizeof = 8). v2 changes Data to a union where x and y
overlap at offset 0 (sizeof = 4).
This is a fundamental ABI break: the memory layout, size, and semantics all change when a struct becomes a union.
What breaks at binary level¶
- sizeof changes:
sizeof(Data)shrinks from 8 to 4. Consumers that allocateDataon the stack or in arrays use the old size. - Field offsets change:
ymoves from offset 4 to offset 0 (overlappingx). - Semantic break: Writing to
yno longer preservesxโ they share storage.
What abicheck detects¶
TYPE_KIND_CHANGED: abicheck detects thatDatachanged from struct to union via DWARFDW_TAG_structure_typeโDW_TAG_union_type.
Overall verdict: BREAKING
How to reproduce¶
gcc -shared -fPIC -g bad.c -include bad.h -o libbad.so
gcc -shared -fPIC -g good.c -include good.h -o libgood.so
# Verify size difference
pahole libbad.so -C Data # โ struct, size 8
pahole libgood.so -C Data # โ union, size 4
python3 -m abicheck.cli dump libbad.so -o /tmp/v1.json
python3 -m abicheck.cli dump libgood.so -o /tmp/v2.json
python3 -m abicheck.cli compare /tmp/v1.json /tmp/v2.json
# โ BREAKING: TYPE_KIND_CHANGED
References¶
Source files¶
See also: Examples overview ยท All BREAKING cases ยท Category: Breaking.