Skip to content

[AUTOMATED] feat(p1): (NOVEL) itaniumrtti - recover the GCC/Clang C++ RTTI graph and its vtables, the analyzer Ghidra does not have - #267

Merged
mahaloz merged 1 commit into
mainfrom
feat/itaniumrtti
Aug 5, 2026
Merged

mahaloz merged 1 commit into
mainfrom
feat/itaniumrtti

Conversation

@mahaloz

@mahaloz mahaloz commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Recovers the Itanium (GCC/Clang) C++ RTTI graph and the vtables it points at,
behind a new default-off itaniumrtti option.

This is a capability Ghidra does not have at all: its RttiAnalyzer is a
Microsoft-PE analyzer and its GCC class recovery is script-tier
(RecoverClassesFromRTTIScript / RTTIGccClassRecoverer), never auto-analysis — so
on a stripped g++ binary Ghidra leaves the Shape vtable as DAT_00107a80. IDA
Pro does reconstruct it. kuna had zero _ZTV/_ZTI/__class_type_info/
__cxxabiv1 hits anywhere in decompiler/crates before this PR: the MSVC half of
C++ RTTI recovery was ported, the Itanium half never was.

(NOVEL) covers the parts no other decompiler showed us the answer to: naming a
secondary sub-vtable for the base subobject its inheritance displacement
identifies
(Widget_vtable_for_Drawable), and attributing an inherited slot to
the class that defines it
rather than to whichever vtable the scan reached first.

The mechanism — an anchor, not a pattern scan

The MSVC sibling has to guess (byte-search .rdata for .?A, assume ref − 12 is a
CompleteObjectLocator). Itanium does not, because the three __cxxabiv1 typeinfo
vtables live in libstdc++, so every _ZTI… object's leading vptr word is an
undefined-symbol dynamic relocation naming one of them with addend 2 × ptr:

$ readelf -rW probe_O0.stripped | grep cxxabiv
0000000000007bf8  R_X86_64_64  _ZTVN10__cxxabiv121__vmi_class_type_infoE + 10
0000000000007c30  R_X86_64_64  _ZTVN10__cxxabiv117__class_type_infoE     + 10
...

Six relocations, six typeinfo objects, zero false positives — and the symbol names
the flavour, which fixes the object's layout. .rela.dyn is a loader input, so
strip --strip-all cannot remove it.

This is not a convenience, it is the only anchor that works. In a PIE or shared
object the typeinfo's vptr word is 0 in the file (the loader writes it), so the
MSVC pass's own discovery heuristic — "find the vptr value the most TypeDescriptors
agree on" — recovers nothing on a modern dynamically linked C++ binary.

Vtables are then reached from the typeinfo rather than guessed: one scan for
pointer slots holding a typeinfo address, filtered by two exact ABI constraints
(offset-to-top ≤ 0; ≥ 1 slot into an executable section) that reject 4/4
coincidental candidates on the probe. A slot that reads 0 but carries a dynamic
relocation is an imported virtual method (__cxa_pure_virtual), so the walk steps
over it instead of truncating an abstract interface's vtable.

Witness — 23/23 against nm ground truth

Stripped g++ -O0 probe, six classes, every recovered name matching the unstripped
nm -C:

recovered ground truth
Shape::vtable_2 / vtable_3 Shape::area(int) const / Shape::perimeter() const
Circle::vtable_2 Circle::area(int) const
Widget::vtable_2 / vtable_3 Widget::emit(int) / Widget::render(int)
Widget::vtable_for_Drawable_0/1/2 the three non-virtual thunk to … entries

Shape::perimeter sits at slot 3 of Shape's, Circle's and Square's tables;
the recovered base graph attributes it once, to Shape.

The most legible line is a multiple-inheritance constructor:

/* off */                            /* on */
sub_34d4(a0,a1);                     sub_34d4(a0,a1);
sub_356a(&a0[2],a2);                 sub_356a(&a0[2],a2);
*a0 = 0x7a90;                        *a0 = Widget_vptr;
a0[2] = 0x7ac0;                      a0[2] = Widget_vptr_for_Drawable;

The benchmark: this does NOT move leveldb, and here is why

libleveldb.so is built -fno-rtti: 18 _ZTV symbols in .dynsym, zero
_ZTI, zero _ZTS, zero __cxxabiv1 relocations. No anchor exists, so the
pass emits nothing — verified by sweep rather than asserted: leveldb -O0 stripped
3,962 functions, 0 changed; leveldb -O2 stripped 919 functions, 0 changed.
type_match stays at 35/525. No benchmark number is claimed.

The separable second capability — independent vtable detection from those 18
surviving _ZTV symbols — was measured before scoping and rejected:

leveldb -O0 stripped, the vtable half measured
total slots across the 17 defined _ZTV objects 126
relocated to __cxa_pure_virtual 59
unrelocated header words 31
naming a real method 36, every one already a .dynsym FUNC symbol
recoverable-but-unnamed virtual methods 0

They are the abstract interface classes; the concrete implementations' vtables
carry no symbol. And an independent code-pointer-run scan of .data.rel.ro reports
37 runs / 231 "functions", none matching any .dynsym symbol — on a PIE that scan
measures relocation residue, which is exactly the mistyping failure mode. It is
deliberately not in this PR.

What an adversarial probe found that the witness could not

A hostile second binary (two template instantiations, a deep namespace, an
anonymous-namespace class) exposed two defects and took recovery there from 7 of 14
virtual methods to 14 of 14
. Both are now in the shipped fixture:

  1. Template instantiations collapsed into one class. Vec<int> and Vec<double>
    both reduce to Vec under the module's name-only demangling; since the symbol
    commit is an idempotent ADD, the second instantiation lost the name race and every
    method stayed sub_<addr>, silently. Template arguments are now folded into the
    identifier (Vec_int, Vec_double) with a depth-aware :: split.
  2. Every TU-local class was invisible. ABI §2.9.1 prefixes an
    anonymous-namespace class's type-name string with * (compare by pointer, not by
    string); that byte is not part of the mangled name, so the class never demangled.
    Not a corner case — an anonymous-namespace class is how most C++ spells a concrete
    implementation of an exported interface (leveldb's PosixEnv).

Sweep

Baseline is now the pre-PR default path (--mode aggressive --option itaniumrtti off) versus the post-PR default path (plain --mode aggressive), restricted to
binaries under the 500 KiB auto threshold — the ones the preset actually applies
to. (mcount_x86_64 at 875 KiB and leveldb at 675 KiB resolve to reliable, so the
preset never reaches them by default; both were swept at the option level anyway.)

  • Plain C: 14 binaries / 357 functions on the real default path — 0 renamed,
    0 body-changed, 0 new errors.
    Structural: a C binary emits no typeinfo, so there
    is no relocation to anchor on.
  • C++: 8 binaries / 364 functions. Changed: the fixture (29 renamed / 40 bodies)
    and the two probes (23/30 and 14/17); plus exactly one hunk anywhere else, in
    cppproto_x86_64, which is strictly better:
    /* off */ *(unsigned long *)this = 0x402028;
    /* on  */ *(code **)this = Shape_vptr;
  • Above the threshold, at the option level: leveldb -O0 stripped 3,962
    functions 0 changed, leveldb -O2 919 0 changed, mcount_x86_64 static C
    1,073 0 changed.
  • 0 new decompile errors anywhere, and the function ENTRY set is byte-identical
    on every binary swept
    — the pass names things, it never discovers them.

Wrongness axis (attaching a wrong class name / naming a non-method), bounded
structurally: a candidate is rejected unless its name string demangles as
_ZTS<name>; every base pointer must resolve to an already-accepted typeinfo; and
the function-symbol commit is an idempotent find_function-gated ADD, so a real
.dynsym/.symtab name is never overwritten.

Speed

Now that the option is a preset member, the number that matters is what it costs on
the binaries where it does not fire — that is the cost every user pays. Baseline
is the pre-PR default path (--mode aggressive --option itaniumrtti off), treatment
is the post-PR default path. Interleaved, minimum of 15 pairs (31 for the fire
row), on a box shared with other agents.

case off on delta
does not fire — functions mcount_x86_64 (static C, 1,969 syms) 171.2 ms 171.6 ms +0.24%
does not fire — functions leveldb-O0 stripped (1,546 relocs) 189.0 ms 189.5 ms +0.26%
does not fire — functions regglobal_fmt_x86_64 (224 KiB C) 180.3 ms 180.8 ms +0.28%
does not fire — decompile-all agg regglobal_fmt_x86_64 (C) 2476.0 ms 2482.1 ms +0.25%
does not fire — decompile-all agg fmt_x86_64 (C) 110.4 ms 109.9 ms -0.38%
does not fire — decompile-all agg fauxware (C) 123.4 ms 123.5 ms +0.06%
does not fire — decompile-all agg cppsig_x86_64.so (C++, no RTTI) 115.1 ms 114.7 ms -0.32%
fires — decompile-all agg itaniumrtti_x86_64.so (n=31) 151.1 ms 152.6 ms +0.99%

Worst no-fire cost +0.28%; worst overall +0.99%; budget 5%. The two rows the
coordinator asked for specifically — the .rela.dyn/symbol scan on a large binary
with no typeinfo at all — are mcount_x86_64 (896 KiB static C, 1,969 symbols) at
+0.24% and stripped leveldb (1,546 dynamic relocations) at +0.26%. The no-fire path
is one relocation-table walk plus one symbol walk, then an early return; discovery
now runs before any other structure is built precisely so that path stays cheap.

The fire row is +0.99% here versus +2.13% measured pre-preset in isolation — same
work, larger denominator, because under aggressive the baseline already carries
listing, aif, funcstart_patterns and the rest. The preset-member figure is the
honest one for a default-path user.

Option + DIV decision

A new option, not a widening of the PE-only rtti. The two paths have different
default-ON trajectories: the MSVC path is a byte-pattern heuristic that will
plausibly stay opt-in forever, while this one is relocation-anchored and exact with a
measured 0-change footprint on 14 plain-C binaries. Sharing one flag would chain the
sound recovery to the unsound one permanently. Secondarily the two are mutually
exclusive by format anyway (MSVC RTTI only in PE, Itanium only in ELF).

DIV-64 (#268 took DIV-63). The option diverges from nothing — its default is
off and --mode reliable is byte-identical. But preset membership makes it the
default rendering on ELF C++ with RTTI, and mode presets are not a datatest
surface
, so that is a default-output change no parity oracle can see. That is
exactly why DIV-43 exists for the symmetric case (removing dwarf_lines from the
same preset). Without preset membership this would correctly carry no DIV row.

Gates

gate result
make test PARITY OK (675/675) — no re-pin, no per-test opt-out
make test-stages PARITY OK
make rust-test green
make check-spec OK (lenient and --strict)
kuna catalog --check catalog OK

Structural, because the XML <binaryimage> datatest bootstrap never runs the
analyzer tier and so cannot reach this pass.

Testing

decompiler/crates/kuna-console/tests/verify_itaniumrtti.rs — 7 two-pass e2e
assertions over a new strip --strip-allped, -fvisibility=hidden fixture (hidden
visibility is load-bearing: without it every implicit class method is emitted WEAK and
exported, so .dynsym alone would name them and the test would prove nothing).
Plus 9 hermetic unit tests. No stage XML — the XML datatest bootstrap never
produces an AnalysisOutput, the same reason cppsig / cppproto / fdeinterior /
cppcallnames all use Rust integration tests.

Catalog counts were read off a fresh green build, never computed: settables 92 → 93,
tiers (20, 41, 31) → (20, 41, 32), catalog JSON rows 91 → 92, and
phase_catalog.json recaptured from a fresh release decomp_dbg rather than
hand-edited.

Full bundle: docs/features/itaniumrtti/{analysis,plan}.md + record.json.

Reachability — this feature was first written INERT, and that is now fixed

A default-off option is only half a decision. auto selects aggressive for
anything under 500 KiB (DIV-40), which is the default path for decompile-all, the
kuna CLI, the web front-end and the benchmark — so an option outside
AGGRESSIVE_OVERRIDES never runs for anyone. Measured on the shipped fixture:

decompile-all invocation before after
default (auto → aggressive) 0 recovered 29 recovered
--mode aggressive 0 29
--mode reliable 0 0 (shipped defaults — unchanged, by design)
explicit --option itaniumrtti on 29 29

So itaniumrtti joins the preset. This is not a judgement call: the preset's own
doc-comment already reads "every off-by-default option flipped ON except
v850indirectbranch and dwarf_lines"
, and names the format-gated no-ops
(rtti/pdb = PE, objc/macho-arm64e = Mach-O, sparcstructret = SPARC) as the
safe class. itaniumrtti is that shape with a strictly narrower firing condition
than rtti's: ELF and a .rela.dyn carrying __cxxabiv1 typeinfo relocations.

The invariant was sampled, not enforced — and four other options are in the same trap

aggressive_excludes_v850_and_dwarf_lines_but_includes_the_rest only checks five
representative members, so it passes whether or not a newly added option was ever
put in the list. That is exactly how this shipped inert.
aggressive_carries_every_default_off_option now enforces the real contract — and
immediately found four further default-off options that are equally unreachable:
cortexmvectors, ptrentry, tailcallentry, paramcopyhoist.

They are recorded in an explicit UNEVALUATED list rather than silently flipped on:
preset membership changes emitted C on the binaries an option fires for, so each
needs its own sweep and PR (paramcopyhoist's own catalog row already records that
its flip regresses a stage assertion and was deferred). Shrinking that list is a
follow-up; the test makes each one a deliberate decision instead of an oversight.

No _LOADTIME_GATE_ENV entry is needed — verified, not assumed

#268 added that table because typedepth's DWARF types are consumed inside
load file, upstream of every console option line, so both arms of a demo rendered
identically. itaniumrtti computes its facts at load too, but commits them at
read symbols (commit_pending_analysis → engine.rs::analysis_pass_enabled), and
scripts/decompile.py emits every option line before read symbols. The
generated demo below renders sub_14b8 off and shapes::Shape::vtable_2 on, so the
console line does reach the gate. The rule is now documented next to the table:
consumed at load ⇒ needs an entry; committed at read symbols ⇒ does not.

Rebase note — the counter collision with #268

main moved to d4a3fd2c (#268 typedepth) mid-review. Both PRs add an option and
both made the identical 92 → 93 edit to the same assertions. git auto-merged
catalog_bytecompat.rs and phase_catalog.json with no conflict
, leaving every
counter short by one; kuna_phases/tests.rs conflicted only on the comment lines,
with the assert_eq! numbers sitting outside the markers. Every counter was
re-derived from a fresh green build rather than incremented:

counter value derived from
settables 94 kuna catalog --json
tiers (20 core, 41 transform, 33 analysis) same
catalog JSON rows (},\n) 93 recaptured phase_catalog.json
fixture "option"/"tier"/"symptoms" 94 each recaptured phase_catalog.json

phase_catalog.json was recaptured from a fresh release decomp_dbg, not
hand-edited.


Before / after — shapes::Shape::vtable_2 in itaniumrtti_x86_64.so

Real captured kuna output on the function this feature was built for, with option itaniumrtti flipped. Ported from kuna — Itanium C++ ABI 2.9.5 / 2.5.2 (type_info + vtable layout); IDA Pro's GCC RTTI reconstruction. Ghidra has no equivalent analyzer -- this is NOVEL, not a port..

metric itaniumrtti off (default) itaniumrtti on
gotos 0 0
labels 0 0
loc 4 4
switches 0 0
speed 151.1 ms 152.6 ms — Δ 0.99% (budget 5.0%)
kuna — before (option itaniumrtti off)
int4 sub_14b8(int8 a0,int4 a1)
{
  return *(int4 *)(a0 + 8) * a1;
}
kuna — after (option itaniumrtti on)
int4 shapes::Shape::vtable_2(int8 a0,int4 a1)
{
  return *(int4 *)(a0 + 8) * a1;
}

… RTTI graph and its vtables, the analyzer Ghidra does not have (DIV-64)

Ghidra has NO Itanium RTTI analyzer at all: its `RttiAnalyzer` is a Microsoft-PE
analyzer and its GCC class recovery is script-tier (RecoverClassesFromRTTIScript /
RTTIGccClassRecoverer), never auto-analysis, so on a stripped g++ binary it leaves
the Shape vtable as DAT_00107a80. IDA Pro does reconstruct it. kuna had ZERO
_ZTV/_ZTI/__class_type_info/__cxxabiv1 hits anywhere in decompiler/crates: the MSVC
half of C++ RTTI recovery was ported, the Itanium half never was, and the mechanism
does not transfer.

Discovery here is EXACT rather than a byte-pattern scan. The three __cxxabiv1
typeinfo vtables live in libstdc++, so every _ZTI object's leading vptr word is an
undefined-symbol dynamic relocation naming __class_type_info / __si_class_type_info /
__vmi_class_type_info with addend 2*ptr -- the relocation's r_offset IS the typeinfo
address and its symbol IS the flavour, and .rela.dyn is a loader input that
`strip --strip-all` cannot remove. This is not a convenience: in a PIE or shared
object the typeinfo's vptr word is 0 in the file, so the MSVC pass's own discovery
heuristic ("find the vptr the most TypeDescriptors agree on") recovers nothing on a
modern dynamically linked C++ binary.

Vtables are reached FROM the typeinfo rather than guessed -- one scan for pointer
slots holding a typeinfo address, filtered by two exact ABI constraints
(offset-to-top <= 0; at least one slot into an executable section) that reject 4/4
coincidental candidates on the probe. A slot reading 0 that carries a dynamic
relocation is an imported virtual method (__cxa_pure_virtual), so the walk steps over
it instead of truncating an abstract interface's vtable.

(NOVEL) covers the two things no other decompiler showed us the answer to: naming a
SECONDARY sub-vtable for the base subobject its inheritance displacement identifies
(Widget_vtable_for_Drawable, read off the __vmi base list -- the datum the MSVC path
discards with its pmd fields), and attributing an inherited slot to the class that
DEFINES it rather than to whichever vtable the scan reached first.

Witness: stripped g++ -O0 probe, 23 of 23 virtual methods across six classes, every
name matching the unstripped `nm -C` ground truth -- including the three
`non-virtual thunk to ...` entries, recovered as Widget::vtable_for_Drawable_0/1/2.

REACHABILITY (the reason for DIV-64). A default-off option is only half a decision:
`auto` selects `aggressive` below 500 KiB, which is the default path for
decompile-all, the kuna CLI, the web front-end and the benchmark, so an option
outside AGGRESSIVE_OVERRIDES never runs for anyone. This feature was first written in
exactly that state -- measured 0 recovered names under `--mode aggressive`, 29 with
an explicit `--option`. It now joins the preset, which is the preset's own documented
contract ("every off-by-default option flipped ON except v850indirectbranch and
dwarf_lines", with the format-gated no-ops rtti/pdb/objc/macho-arm64e/sparcstructret
named as the safe class); itaniumrtti has a strictly narrower firing condition than
rtti's PE gate. `--mode reliable` stays at 0, so the shipped defaults are untouched.

That invariant turned out to be only SAMPLED by a test, never enforced, which is why
the omission was silent. modes.rs::aggressive_carries_every_default_off_option now
enforces it and immediately found four further default-off options in the same trap
(cortexmvectors, ptrentry, tailcallentry, paramcopyhoist), recorded as an explicit
UNEVALUATED list rather than silently flipped -- each changes emitted C on the
binaries it fires for and needs its own sweep and PR.

No _LOADTIME_GATE_ENV entry is needed in scripts/decompile.py, verified rather than
assumed: #268 added that table because typedepth's DWARF types are CONSUMED inside
`load file`, while itaniumrtti commits its facts at `read symbols`, which every
`option` line precedes. The rule is now documented next to the table.

This does NOT move leveldb and cannot: libleveldb.so is built -fno-rtti (18 _ZTV
symbols, zero _ZTI, zero _ZTS, zero __cxxabiv1 relocations), so the pass emits
nothing -- verified by sweep, 3,962 functions at -O0 and 919 at -O2, 0 changed. The
separable vtable-only half was measured before scoping and rejected: of 126 slots in
the 17 defined _ZTV objects, 59 are __cxa_pure_virtual, 31 are unrelocated header
words, and every one of the remaining 36 already carries a .dynsym name -- zero
recoverable-but-unnamed methods. No benchmark number is claimed.

An adversarial probe (two template instantiations, a deep namespace, an
anonymous-namespace class) found two defects the good-citizen witness could not, and
fixing them took recovery there from 7 of 14 virtual methods to 14 of 14:
Vec<int>/Vec<double> collapsing to one class under name-only demangling (the second
then loses the idempotent name race and stays sub_<addr>, silently), and every
TU-local class being undemangleable because the ABI (2.9.1) prefixes its type-name
string with `*`. Both are now in the shipped fixture.

Sweep (pre-PR default path `--mode aggressive --option itaniumrtti off` vs post-PR
`--mode aggressive`, restricted to the <500 KiB binaries the preset applies to):
plain C 14 binaries / 357 functions 0 changed; C++ 8 binaries / 364 functions,
changed only the fixture and the two probes plus ONE hunk in cppproto_x86_64 that is
strictly better (`*(unsigned long *)this = 0x402028` -> `*(code **)this =
Shape_vptr`). Above the threshold at the option level: leveldb -O0 3,962 / -O2 919
and mcount_x86_64 1,073, all 0 changed. 0 new decompile errors, and the function
ENTRY set is byte-identical everywhere -- the pass names things, it never discovers
them.

Speed (interleaved, minimum of 15 pairs; 31 for the fire row). The number that
matters is the cost where it does NOT fire, which every user pays: +0.24% on
mcount_x86_64 (896 KiB static C, 1,969 symbols), +0.26% on stripped leveldb (1,546
dynamic relocations), +0.28% on regglobal_fmt_x86_64, and -0.38%..+0.25% end-to-end
under `--mode aggressive`. Where it does fire, +0.99% (vs +2.13% pre-preset in
isolation -- same work, larger denominator). Worst no-fire +0.28%, worst overall
+0.99%, budget 5%.

A NEW option rather than a widening of the PE-only `rtti`: the two paths have
different default-ON trajectories -- the MSVC path is a byte-pattern heuristic that
will plausibly stay opt-in forever, while this one is relocation-anchored and exact
with a measured 0-change footprint on 14 plain-C binaries. DIV-64 records the preset
membership, not the option default: `--mode reliable` is byte-identical, but mode
presets are not a datatest surface, so a membership change alters default rendering
where no parity oracle can see it -- exactly why DIV-43 exists for the symmetric
removal of dwarf_lines from the same preset.

Rebased onto d4a3fd2 (#268 typedepth), which added an option and made the identical
`92 -> 93` counter edit. git auto-merged catalog_bytecompat.rs and phase_catalog.json
with no conflict, leaving every counter short by one, and kuna_phases/tests.rs
conflicted only on the comment lines. Every counter was RE-DERIVED from a fresh green
build: settables 94, tiers (20 core, 41 transform, 33 analysis), catalog JSON rows 93;
phase_catalog.json recaptured from a fresh release decomp_dbg rather than hand-edited.

Gates: make test PARITY OK (675/675, no re-pin), make test-stages PARITY OK, make
rust-test green, make check-spec OK (lenient + strict), kuna catalog --check OK.

Covered by kuna-console/tests/verify_itaniumrtti.rs (7 two-pass e2e assertions over a
new stripped hidden-visibility fixture) plus 9 hermetic unit tests and the new
modes.rs preset invariant. No stage XML: the XML <binaryimage> datatest bootstrap
never produces an AnalysisOutput and cannot reach the analyzer tier, the same reason
cppsig / cppproto / fdeinterior / cppcallnames all use Rust integration tests.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01McQC7imaNfzj5k5AVumSYN
@mahaloz
mahaloz merged commit 2831e35 into main Aug 5, 2026
9 checks passed
@mahaloz
mahaloz deleted the feat/itaniumrtti branch August 5, 2026 17:28
mahaloz added a commit that referenced this pull request Aug 5, 2026
…, preset decision

Rebase onto #267 (`itaniumrtti`), which claimed DIV-64 and added an option.

DIV-64 -> DIV-65. The counters are NOT arithmetic: `catalog_bytecompat.rs`
auto-merged to 94 with no conflict, because #267 and this branch had each made
the identical 93 -> 94 edit, so the committed value was silently short by one.
Re-derived by capturing `phase_catalog.json` from a fresh release build and
COUNTING it: 95 settables, tiers (20, 41, 34), 94 JSON rows -- and
`docs/options.md` independently reports 95 option headings. The two generated
artifacts (`phase_catalog.json`, `docs/options.md`) did merge line-by-line
correctly; the trap was only in the hard-coded `.rs` counts.

Preset decision, stated rather than left implicit: `libcsigs` is deliberately NOT
in AGGRESSIVE_OVERRIDES. It ships default-ON, so #267's
`aggressive_carries_every_default_off_option` invariant is out of scope for it --
and the liveness was measured, not assumed. On dircolors (55,680 bytes, so `auto`
resolves to `aggressive`), default vs `--option libcsigs off` differs in 57/184
functions under auto, 57/184 aggressive, 58/183 reliable, 58/184 fast. Adding it
would be worse than redundant: the preset OWNS an option it lists, and every
benchmark and sweep number in this PR was produced by `--option libcsigs off` on
sub-500 KiB binaries, i.e. straight through auto -> aggressive -- membership would
silently re-enable it there and destroy the ablation hook.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01McQC7imaNfzj5k5AVumSYN
mahaloz added a commit that referenced this pull request Aug 5, 2026
…n (C type_match perfects 143 -> 165 over 2,092 functions, 137 improved / 3 worse) (DIV-65) (#269)

* [AUTOMATED] feat(p1): libcsigs - the measured libc signature extension, 27 -> 233 prototypes

kuna's built-in libc prototype table carries 27 entries. Its own header calls the
shortfall a documented LOSS: Ghidra applies parsed C headers shipped as binary
`.gdt` archives, that format is not vendored, and the table is "a faithful,
minimal stand-in". The constraint is that no header archive exists in the tree,
not licensing - so the table is small because nobody has grown it.

Every libc callee outside those 27 leaves its callers' arguments an inferred
`unsigned long`, and half of the 1587 cases where IDA scores a perfect C
`type_match` and kuna does not have an integer-typed kuna parameter where IDA has
a concrete type.

`analyzers/protos/kuna_libcsigs.rs` adds the measured remainder: 206 further
signatures, chosen by frequency rather than intuition (a PLT call-site histogram
over the 547 frozen-decbench C binaries, plus a per-callee ranking of those 1587
cases; the rule is >= 100 sites or >= 3 cases). Every signature is reduced from a
machine-readable declaration - `gcc -aux-info` over the platform headers with
_GNU_SOURCE + _FORTIFY_SOURCE=2 for the bulk, GCC's builtin types for the FORTIFY
`_chk` family, the `<stdio.h>` `__REDIRECT` for the `__isoc99_*` aliases - and a
declaration whose every slot is not width-stable across ILP32/LP64 is REJECTED
rather than approximated (`lseek`, `time`, `strtoll`, `fseeko`, `mmap`, `signal`,
`qsort`), because a wrong prototype asserts a false type where `unsigned long` was
merely uninformative.

The same principle drives the one novel rule: an entry applies only to a name the
image IMPORTS and does not itself define. zlib's `minigzip` declares
`void error(const char *msg)` where glibc's is `void error(int,int,const char*,...)`,
and typing that call `error(0,0,...)` would be strictly worse than what it
replaces. The 27-entry base table's defined-or-imported matching is untouched.

Behind `--option libcsigs on|off`, default ON; `off` renders exactly what the base
table alone renders.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01McQC7imaNfzj5k5AVumSYN

* [AUTOMATED] docs(libcsigs): DIV-64 row and the feature record

The measured C `type_match` delta (decbench origin/main @325046f,
DECBENCH_NO_CACHE=1, all three optimisation levels, option off vs on):
grep 33 -> 37 perfects, diffutils 24 -> 35, gzip 57 -> 62, bzip2 mean
0.2617 -> 0.2712, findutils 21 -> 23. Pooled n=2,092: perfects 143 -> 165
(+22), mean 0.2272 -> 0.2501 (+10.1%), 137 functions improved against 3
worse.

Renumbered to DIV-64 on the rebase onto #268, which claimed DIV-63.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01McQC7imaNfzj5k5AVumSYN

* [AUTOMATED] fix(libcsigs): DIV-65, counters re-derived from a capture, preset decision

Rebase onto #267 (`itaniumrtti`), which claimed DIV-64 and added an option.

DIV-64 -> DIV-65. The counters are NOT arithmetic: `catalog_bytecompat.rs`
auto-merged to 94 with no conflict, because #267 and this branch had each made
the identical 93 -> 94 edit, so the committed value was silently short by one.
Re-derived by capturing `phase_catalog.json` from a fresh release build and
COUNTING it: 95 settables, tiers (20, 41, 34), 94 JSON rows -- and
`docs/options.md` independently reports 95 option headings. The two generated
artifacts (`phase_catalog.json`, `docs/options.md`) did merge line-by-line
correctly; the trap was only in the hard-coded `.rs` counts.

Preset decision, stated rather than left implicit: `libcsigs` is deliberately NOT
in AGGRESSIVE_OVERRIDES. It ships default-ON, so #267's
`aggressive_carries_every_default_off_option` invariant is out of scope for it --
and the liveness was measured, not assumed. On dircolors (55,680 bytes, so `auto`
resolves to `aggressive`), default vs `--option libcsigs off` differs in 57/184
functions under auto, 57/184 aggressive, 58/183 reliable, 58/184 fast. Adding it
would be worse than redundant: the preset OWNS an option it lists, and every
benchmark and sweep number in this PR was produced by `--option libcsigs off` on
sub-500 KiB binaries, i.e. straight through auto -> aggressive -- membership would
silently re-enable it there and destroy the ablation hook.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01McQC7imaNfzj5k5AVumSYN

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant