Repository navigation
[AUTOMATED] feat(p1): cppsig - apply the demangled C++ signature (leveldb type_match 9 -> 35 of 525, +26 with 0 lost) - #266
Merged
Merged
Conversation
…eldb type_match 9 -> 35 of 525, +26 with 0 lost) kuna applied no demangled C++ signature at all. The demangler reduces a mangled symbol to its qualified NAME only - a hard requirement of the `::`-scope splitter - and `demangle_raw`, the full c++filt form, had shipped with NO production caller since the demangler landed, its own header recording the signature application as "a deferred follow-up". The cost is a STRIPPED C++ shared library, where the exported `.dynsym` mangled name is the only signature source left. On stripped google/leveldb -O0, functions whose first parameter is a named pointer ran ghidra 188 / ida 150 / binja 60 / angr 0 / kuna 0 across 527 functions. New `analyzers/demangle/kuna_cppsig.rs` parses the demangled STRING, the same shape as upstream's GnuDemanglerParser, and parks a prototype by entry address. A C++ reference maps to a pointer; a by-value aggregate, array, function pointer or overloaded operator refuses the whole signature. The return type is deliberately NOT applied - Itanium encodes one only for a template function, so upstream returns null and keeps what the analysis recovered; kuna expresses that as `outtype: None`, read as "lock the INPUT half only". Three-valued because Itanium mangles a static member function exactly like a non-static one: `proven` (the default) applies only what the mangling entails and measures precision 1.0000 / recall 0.7093 on 1329 symbols with DWARF ground truth; `inferred` decides the rest from class evidence at precision 0.9278 / recall 1.0000. Ghidra 12.1's own `this` decision on the same binary is 0.85. Benchmark, decbench leveldb O0 (n=525) with the fixed scorer (decbench origin/main @325046f, PR #60): type_match perfects 9 -> 35 at the default (+26, zero lost), 38 under `inferred`. Rivals on the same scorer: ghidra 44, ida 35, binja 11, angr 8 - kuna moves from last to second. Plain C is untouched: 11 binaries / 1,351 functions, 0 changed. Gated `cppsig`, default `proven` (DIV-62); the pass runs at load, so both certainty tiers are stashed apart and the mode applies at the analysis commit. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01McQC7imaNfzj5k5AVumSYN
…d + plan.md The standing requirement is a docs/features/<slug>/ bundle of analysis.md, plan.md and record.json; only record.json was written. Content is the measured material from the PR body: the leveldb type_match standing, the precision/recall table behind the three-valued `this` rule, the three defects the whole-binary sweep found, and the refusals. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01McQC7imaNfzj5k5AVumSYN
This was referenced Aug 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
kuna applied no demangled C++ signature. The demangler reduces a mangled symbol to its qualified NAME only — a hard requirement of kuna's
::-scope splitter, which nests on every::and would otherwise build junk scopes out of a signature tail — anddemangle_raw, the full c++filt form, had shipped with no production caller since the demangler landed. Its own header recorded the gap: "It does NOT apply the demangled signature (parameter / return types) … a deferred follow-up."The cost is a stripped C++ shared library, where the exported
.dynsymmangled name is the only signature source that survives. On strippedgoogle/leveldb-O0, functions whose first parameter is a NAMED pointer type, across 527 functions:37 of ghidra's 42 outright wins are
.dynsym-exported; on the 112 non-exportedthis-shaped functions ghidra gets 1. So the lever is the demangler, not type inference — which the plain-C control corpus confirms, kuna's type recovery there being ordinary rather than weak.The whole problem is the implicit object parameter
Itanium mangles a static member function exactly like a non-static one, and like a namespaced free function:
leveldb::Status::OK(),leveldb::TableBuilder::WriteBlock(…)andleveldb::NewMemEnv(Env*)share one_ZN…Eshape. Guessing wrong does not cost precision — it shifts every following parameter, which is binja's bug in the other direction (it applies the declared parameters and OMITSthis).Both tiers were measured on 1329 mangled
.dynsymsymbols with DWARF ground truth (915 really takethis) before either was written:proven— ctor/dtor + cv-qualified (shipped default)inferred— + class evidenceFor calibration, Ghidra 12.1's own
thisdecision on the same binary runs at precision 0.85 (34 right / 6 wrong of 40 applications). Upstream resolves the ambiguity inDemangledFunction.isThisCallby comparing the mangled parameter count against the count its analysis recovered — information kuna does not have at the analysis tier, which is why the split above is the substitute.provenis what the mangling entails: constructors (C1/C2/C3), destructors (D0/D1/D2), cv-/ref-qualified members (_ZNK), unqualified globals, and the MSVC forms — which state the access specifier,staticand the calling convention outright.inferreddecides the rest from class evidence mined out of the binary's own symbols (a scope owning a ctor/dtor/cv-member or a_ZTV/_ZTI/_ZTSsymbol is a class). Ininferredboth directions need positive evidence: a scope with no witness at all is DECLINED, not assumed to be a namespace — that refinement takes recall 0.9978 → 1.0000 at unchanged precision.Measured benchmark delta
decbench leveldb O0, n=525 scored functions, scored with decbench
origin/main@325046f (PR #60 — the C++type_matchartifact fixes),cache_version5,DECBENCH_NO_CACHE=1. Theoffarm reproduces the pre-PR tree exactly, so it is a real control.cppsig inferredcppsig proven(shipped default)cppsig off(baseline)9 → 35 at the default: +26, and ZERO lost. Mean 0.1277 → 0.1784 (
proven) / 0.1920 (inferred); 28 / 44 functions improved and 0 worse in either mode. kuna moves from last place to second, tied with ida at the default and 6 short of ghidra.The 26 newly perfect functions are exactly the set decbench's own improvement miner nominated:
~Cache ~Comparator ~DB ~Env ~EnvWrapper ~FileLock ~FilterPolicy ~Handler ~Logger ~RandomAccessFile ~Rep ~SequentialFile ~Snapshot ~Table ~TableBuilder ~WritableFile ~WriteBatch+ApproximateSize Env FileSize Iterator NumEntries Options Rep TableBuilder WriteBatch.inferredaddsChangeOptions NewErrorIterator NewMemEnv.Note on the target: the brief's "7 → ~33 = parity with ghidra" sizing was computed on the pre-#60 scorer and is stale. Against the corrected scorer the baseline is 9 and parity is 44; this lands at 35, a large win that is honestly short of ghidra by 6. C++ references are rendered as pointers, which is what the fixed ground truth now expects.
The return type is deliberately not applied
Itanium encodes a return type only for a template function, so upstream's
resolveReturnTypereturns null andApplyFunctionSignatureCmdkeeps whatever the analysis recovered — which is why ghidra still printsundefined8 leveldb::TableBuilder::NumEntries(TableBuilder *this). kuna expresses that as aPrototypePieceswith noouttype, read byFuncProto::seed_locked_from_piecesas "lock the INPUT half only". Inventingvoidwould DELETE every recovered return value.Complementary to
cppproto(#264), with a stated precedenceDWARF is ground truth and wins on an unstripped binary; the mangled symbol is what survives
strip. The commit appliescppsigfirst so the DWARF prototype overwrites it wherever both reach a function — asserted inverify_cppsig::dwarf_wins_over_the_demangled_signature, whose witness is the parameter NAME (amount), which only DWARF carries.Gates
make testmake test-stagesmake rust-testmake check-spec--strict)kuna catalog --checkStructural, not lucky: the XML
<binaryimage>datatest bootstrap never runs the analyzer tier, so neither corpus can reach this pass.Sweep — every changed function classified
decompile-alloff vs on, both arms on this tree.Plain C is untouched on every axis — 11 binaries / 1,351 functions, 0 changed in either mode (coreutils
fmt-O2 -g,fmt_x86_64,dwarf_globals,fauxware, staticmcount_x86_64at 1,073 functions,stripped_dynamic,switchtab,noreturn_propagate,fmt_aarch64,fmt_arm, and the Rust-mangledrust_hello). That is structural: a C symbol is not C++-mangled, so the pass emits nothing.proveninferredcppsig_x86_64.socppproto_x86_64(-g)cpp_mangled_x86_64cpp_noreturn_x86_64eh_lsda_x86_64The wrongness axis, measured rather than argued
Raw arity change is not the harm signal — an arity decrease is often kuna over-recovering, with the demangled list right. The signal is a NEW read-before-write of an argument register (
int8 *v1; // rsi): the symptom of a locked parameter list shorter than the ABI uses. Over leveldb-O0stripped, 3,962 functions:proven(default)inferredBoth remaining
provencases are one mechanism, the SysV hidden return pointer: a function returning a class by value takes an sret pointer in slot 0, which the mangling does not mention, so the declaredthisbinds to it.Ghidra gets these wrong too, and worse: its parameter-count heuristic sees 3 recovered vs 1 mangled, concludes "not a thiscall", and emits
Handler * leveldb::WriteBatch::Iterate(Handler *param_1)—thisdropped entirely and slot 0 mis-typed. Closing it properly needs the recovered parameter count, i.e. a decompile pass; recorded as a follow-up.Three defects the sweep found that the witness could not
outtype: Nonecrashed the CALLER-side rebuild. Handled atFuncdata::apply_locked_prototypeinstead ofFuncProto::seed_locked_from_pieces, it leftActionDefaultParams— which reconstructs a callee's prototype to type a call's arguments — hittingassign_map'sexpect("outtype null"), killing everymainthat called such a function.cpp_demangledrops a parameter on explicit function-template specializations:_ZNSt4pairI…EC1IRS1_S4_Lb1EEEOT_OT0_is a two-parameter forwarding constructor rendered with ONE. Those are now refused outright — which also sidesteps the module's knownmaxof<int>/maxof<double>collision, and alone cut the measured harm from 8 functions to 2.Speed
The pass walks the symbol table once at load and demangles each C++ name, so load is the metric. Interleaved off/on, minimum of 13 pairs (the box runs concurrent agents):
proveninferredfunctionsleveldb-O0 stripped (load only)functionsregglobal_fmt_x86_64(plain C)decompileleveldb~Cachedecompile-allcppproto_x86_64decompile-allcppsig_x86_64.so(n=31)Worst delta +0.48%, budget 5%. An n=13 run of that last 108 ms case reported +4.01% and did not reproduce at n=31.
offstill pays the demangle (the facts are computed then dropped at the commit), so the C rows are flat because a C binary has no mangled symbol to walk.Option / DIV
cppsig, valuesoff|proven|inferred, defaultproven, tieranalysis,change_kindanalysis-enablement. It changes emitted C on C++ binaries by default, so it takes DIV-62. Catalog counts derived from a fresh green build, never by arithmetic: settables 91 → 92, tiers (20, 41, 30) → (20, 41, 31), catalog rows 90 → 91,phase_catalog.jsonrecaptured.Tests
decompiler/crates/kuna-console/tests/verify_cppsig.rs— 7 two-pass e2e assertions over a newstrip --strip-allpedcppsig_x86_64.sofixture (no DWARF, no.symtab), including the DWARF-precedence check and one that pinsinferred's known static-member cost so it cannot drift silently. Plus 19 hermetic parser /this-decision unit tests.No stage XML: the XML datatest bootstrap builds its program from a
<binaryimage>element and never produces anAnalysisOutput, so nokuna_analysispass can fire there — the same reasonverify_cppproto/verify_cppcallnames/verify_fdeinteriorexist.Two
verify_cppprotobaseline arms now setcppsig offexplicitly: with the sibling recovery at its default the "gate off = the bug" baseline stopped reproducing, because aconstmember and an unqualified global are both PROVEN shapes.Deliberately not in this PR
__thiscallselection. [AUTOMATED] feat(p4): cspecprotos - register the compiler spec's named prototype models (registry 1 -> 5 models, __thiscall resolves) #265 registered the model on all 294 language:compiler pairs and listed assigning it as a follow-up; it still is.PrototypePiecescarries no model back-pointer (the C++ field was dropped precisely because kuna had no registry) andArchContextexposes onlydefaultfp. Not needed for the win either: every ABI in the corpus passesthisas ordinary argument 0. The one that does not — 32-bit MSVC__thiscall,thisin ECX — is REFUSED rather than mis-placed.this->fieldon a stripped binary; all five decompilers emit*(long *)this + 0x1d0.Before / after —
sig::Account::~Accountincppsig_x86_64.soReal captured kuna output on the function this feature was built for, with
option cppsigflipped. Ported from kuna — Ghidra DemangledFunction.applyTo / GnuDemanglerAnalyzer "Apply Function Signatures"; the string-parsing shape is GnuDemanglerParser, which likewise consumes the c++filt text rather than an AST.cppsig offcppsig on(default)kuna — before (
option cppsig off)kuna — after (
option cppsig on)