Skip to content

[AUTOMATED] fix(analysis): pe-function-inventory-labels — name a virtual method after the function, not its vftable - #382

Merged
mahaloz merged 1 commit into
mainfrom
feat/re-pe-function-inventory-labels
Sep 4, 2026
Merged

mahaloz merged 1 commit into
mainfrom
feat/re-pe-function-inventory-labels

Conversation

@mahaloz

@mahaloz mahaloz commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

What was broken

RE-friction need pe-function-inventory-labels (round 2, challenge 6547b4d50f4238b24302b588,
1 instance, severity major). The tester wanted "a trustworthy function inventory for triaging
the PE"
and reported:

The inventory includes executable ranges named std::bad_alloc::vftable_1 and numerous
std::basic_stringbuf::vftable_N entries as functions, including ranges hundreds of bytes
long. These names are data-symbol aliases and misleadingly classify routines as vtable
objects.

10 entries on that PE, from 0x140001040 (32 B) to 0x140001de0 (496 B).

The filed hypothesis is overturned; the symptom stands

The hypothesis was "public data aliases near code addresses are winning the canonical-name
selection"
. No data symbol is involved. <Class>::vftable_<i> is a name kuna synthesises:
the MSVC RTTI pass (R3, analyzers/rtti/mod.rs::emit_vftable_methods) walks each recovered
vftable and emits a SymFact{Function} at the address each slot points at — the virtual
method, not the table. All 10 entries are genuine .text routines and classifying them as
functions is correct.

The name is what is wrong, and not merely cosmetically: an MSVC class under multiple
inheritance genuinely owns several vftables, so <Class>::vftable_<i> collides with the
natural reading "this class's i-th vftable". The need's STOP clause — stop if the fix changes
function DISCOVERY rather than labelling — does not fire: which addresses the pass creates is
untouched.

Mechanism

1. The slot function is named after the function. <Class>::vftable_<i> →
<Class>::vfunc_<i>. Only the table itself keeps a vftable name, and it keeps the unindexed
<Class>::vftable Data label it always had.

2. A slot-index name is structural, so a real method name outranks it. The rename alone was
a net regression on one function, and only the whole-corpus sweep found it.
entry_name_rank's tiers are (placeholder, structural, leading-underscore, LENGTH), so
between a recovered method name and a synthetic slot name the reported name was decided by a
one-character length accident:

address before this PR after rename only after both changes
0x140002c2c std::basic_streambuf::showmanyc (30) std::basic_stringbuf::vfunc_5 (29) std::basic_streambuf::showmanyc
0x140002c32 std::basic_streambuf::uflow (27) std::basic_streambuf::uflow std::basic_streambuf::uflow

The fix is not to pick a longer word. A slot-index name is structural in exactly the sense the
existing _FINI_<i> tier already documents — it says which slot the function occupies, not
what the function is called
— so <Class>::vfunc_<i> (MSVC) and <Class>::vtable_<i>
(Itanium) now sort into that tier, and a real method name outranks them at any length. They
still beat sub_/FUN_ placeholders, which lose a tier earlier.

The acceptance probe now passes

$ python -m scripts.repipe.verify --need pe-function-inventory-labels
acceptance suite  sha 74118fd
  PASS   closed         open           pe-function-inventory-labels
total=1 pass=1 fail=0 closed=1 regressed=0 indeterminate=0

"name": "[^"]*::vftable_[0-9]+" count on the recorded PE: 10 → 0.

Promoted to tests/cli/pe-function-inventory-labels.json, re-pointed off the dataset PE onto
the in-repo msvc_rtti_x64.exe, which carried the identical defect (Box::vftable_0) — CI has
no dataset. The acceptance is a single stdout_absent clause, which a dead rtti pass would
also satisfy, so the promoted probe adds a positive "name": "Box::vfunc_0" clause and pins
--mode aggressive instead of relying on auto's 500 KiB threshold to turn the gate on.

Sweep

kuna functions --json --mode aggressive over 19 targets — all 9 in-repo PE fixtures, all 8
C++/ELF fixtures including the stripped Itanium-RTTI .so, the fauxware/aif_gap controls,
and the recorded dataset PE — plus kuna decompile-all --json over the 9 PE fixtures.

  • 3 files changed, 50 lines; residual after normalising ::vftable_<i> → ::vfunc_<i>: 0.
    Every changed line anywhere is exactly that one name.
  • The ELF half of the rank predicate is measured-inert: itaniumrtti_x86_64.so is stripped,
    so its 26 <Class>::vtable_<i> entries only ever face sub_<addr> placeholders, which
    already lose at tier 1. It is carried by unit tests, not by a fixture.

No speed measurement: no pass, decode or analysis step was added or removed. The rtti change is
one format string; the ranking change adds one rsplit_once + prefix test per (name, entry)
pair inside an inventory sort that already compares those strings.

Gates

Gate Result
make test PARITY OK, 675/675 assertions
make test-stages PARITY OK, 600/600 assertions
make rust-test green — 5,317 tests over 343 suites
make check-spec check-spec OK
kuna catalog --check catalog OK: documents exactly the registered kuna options
python -m scripts.repipe.clitests 17/17
new unit tests 3 in kuna-console::engine, 1 in kuna-analysis::rtti, verify_rtti.rs updated

Tooling track: no option, no phases.toml row, no catalog counter, no tests/stages case — so
no counter or file lease was taken.

Left for a follow-up (recorded in the need)

The MSVC pass has no defining-class attribution, so a slot shared by a base and its derivatives
is named once per class and the canonical pick among them is arbitrary
(std::bad_alloc::vfunc_0 canonical over std::exception::vfunc_0 on lexicographic order
alone). The Itanium sibling already attributes an inherited slot to the class that defines
it. The Itanium pass's own vtable_<i> stem carries the same naming defect and was left alone
deliberately: renaming it edits the itaniumrtti row in phases.toml, which is leased to
another builder this round.

🤖 Generated with Claude Code

…ual method after the function, not its vftable

The MSVC RTTI pass (rtti R3) walks each recovered vftable and emits a
Function symbol at the address every slot POINTS AT — the virtual method.
It named that function `<Class>::vftable_<i>`, so `kuna functions` reported
executable ranges as vtable objects: 10 of them on the round-2 challenge PE,
up to 496 bytes of `std::basic_stringbuf` code. Under multiple inheritance an
MSVC class genuinely owns several vftables, so the indexed form also collides
with the natural reading "this class's i-th vftable". Renamed to
`<Class>::vfunc_<i>`; only the table itself keeps the unindexed
`<Class>::vftable` Data label.

The filed hypothesis ("public data aliases are winning the canonical-name
selection") is overturned: no data symbol is involved, the name is one kuna
synthesises, and function discovery is untouched.

The rename alone regressed one function, and only the whole-corpus sweep
found it. entry_name_rank's tiers are (placeholder, structural,
leading-underscore, LENGTH), so a real method name and a synthetic slot name
were separated by a one-character length accident:
`std::basic_streambuf::showmanyc` (30) beat `vftable_5` (31) and lost to
`vfunc_5` (29), while its neighbour `uflow` kept its name either way. A
slot-index name is structural in exactly the sense the existing `_FINI_<i>`
tier documents — it says which slot the function occupies, not what the
function is called — so `<Class>::vfunc_<i>` and the Itanium sibling's
`<Class>::vtable_<i>` now sort into that tier and a real method name outranks
them at any length. They still beat `sub_`/`FUN_` placeholders.

Sweep: `kuna functions --json --mode aggressive` over 19 targets (9 in-repo
PE fixtures, 8 C++/ELF fixtures incl. the stripped Itanium-RTTI .so, the
fauxware/aif_gap controls, the recorded dataset PE) plus `decompile-all
--json` over the 9 PEs. Residual after normalising `::vftable_<i>` ->
`::vfunc_<i>`: 0 lines. Nothing else moved on any target.

Tooling track: no option, no phases.toml row, no catalog counter, no
tests/stages case.

Acceptance probe flips 10 -> 0 and is promoted to
tests/cli/pe-function-inventory-labels.json, re-pointed onto the in-repo
msvc_rtti_x64.exe (CI has no dataset) with an added positive clause so a dead
rtti pass cannot satisfy it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@mahaloz mahaloz added the full-ci Run the full cargo workspace suite on this PR before merge (internal PRs skip it by default) label Sep 4, 2026
@mahaloz
mahaloz merged commit fed78ec into main Sep 4, 2026
10 of 11 checks passed
@mahaloz
mahaloz deleted the feat/re-pe-function-inventory-labels branch September 4, 2026 15:22
mahaloz added a commit that referenced this pull request Sep 4, 2026
B_DONE bookkeeping for wave 7 of round 2. Acceptance a-d6666365cbb6 (kuna
functions --json must not name any executable range <Class>::vftable_<i>)
FAILED when the need was filed and PASSES on the gated build fed78ec, so the
need flips open -> closed with closing_pr 382 / closed_in_round 2.

Gate evidence: /tmp/b_verify_fed78ec3.{rc,log,acceptance.json} at HEAD-pinned
fed78ec -- all four gates plus catalog/clitests/acceptance rc=0, 2x PARITY OK,
tests/cli 17/17, acceptance suite closed=[pe-function-inventory-labels]
regressed=[].

No probe promotion needed: PR #382 vendored tests/cli/pe-function-inventory-labels.json
itself (the 16 -> 17 step the gate run confirms).

Backlog is now 17 closed / 18 open of 35.

Co-Authored-By: Claude Opus 5 <[email protected]>
stefan-siebert added a commit to stefan-siebert/kuna that referenced this pull request Nov 16, 2026
…s vtable

itaniumrtti emits a Function symbol at the address each sub-vtable slot
points at and named it `<C>::vtable_<i>` (`<C>::vtable_for_<Base>_<i>` in a
secondary sub-vtable), so `kuna functions` and call sites showed routines
under vtable names. The MSVC sibling pass dropped that stem in Noelo-Lab#382 for the
same reason. The slot functions are now `<C>::vfunc_<i>` and
`<C>::vfunc_for_<Base>_<i>`; the data labels (`<C>_vtable`, `<C>_vptr`,
`<C>_vtable_for_<Base>`) are unchanged.

is_vtable_slot_name now recognises the secondary-sub-vtable form as a
structural slot-index name too, so a real method name at a thunk's address
outranks it. The bare `vtable_<i>` form is no longer emitted by any pass and
is no longer treated as a slot name.

Tests: tests/stages/kuna-itaniumvfunc.xml (off: sub_ names; on: the
Drawable thunk is Widget::vfunc_for_Drawable_2 and tail-calls
Widget::vfunc_3, and no `::vtable_<i>` appears; the pre-change code fails
the four on-pass asserts), tests/cli/elf-function-inventory-vfunc-labels.json,
verify_itaniumrtti and engine ranking tests updated. Stages baseline gains
the six new assertions. Speed: decompile-all on the fixture 133.6 ms ->
130.5 ms median (noise).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-ci Run the full cargo workspace suite on this PR before merge (internal PRs skip it by default)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant