Skip to content

Add MSVC demangler correctness fixes and generated test corpus#8140

Open
plafosse wants to merge 2 commits into
devfrom
test_ms_demangler_fixes
Open

Add MSVC demangler correctness fixes and generated test corpus#8140
plafosse wants to merge 2 commits into
devfrom
test_ms_demangler_fixes

Conversation

@plafosse
Copy link
Copy Markdown
Member

@plafosse plafosse commented Apr 30, 2026

This should be considered a ground up re-write and so you probably won't get any value out of looking at diffs of the actual demangler. It pretty much solves all known demangler accuracy issues. And lays the ground work for more performance unlocks when we get the new simplifier integrated.

Major changes:

  • Demangling now is backed by the DemangledTypeNode like gnu3 is. The purpose is
    to provide an abstraction layer between c++ features and binary
    ninja's type objects.
  • Substantial performance increase I think around 3x what it was before
    this is due to cutting down on extraneous string copies and type object allocations
  • Substantial accuracy fixes. The most substantial of which is accurate scoping
    of back references.
  • Lots and lots of other small fixes. This commit could have been about 100 commits but
    I didn't feel that adding all those commits would be helpful in understanding what's
    actually going on here.
  • The msvc code roughly twice as fast even while bailing out way less than the previous version.

Fixes:

@plafosse plafosse self-assigned this Apr 30, 2026
@plafosse plafosse force-pushed the test_ms_demangler_fixes branch 3 times, most recently from 4b906ea to 15dd98a Compare May 6, 2026 19:34
@plafosse plafosse marked this pull request as ready for review May 7, 2026 14:48
@plafosse
Copy link
Copy Markdown
Member Author

I realized that bb9e720 and 7bfbb87 have regressed performance. And this needs some more changes so I'm converting it back to a draft :\

@plafosse plafosse marked this pull request as draft May 11, 2026 13:18
@plafosse plafosse force-pushed the test_ms_demangler_fixes branch 2 times, most recently from 1cd85f5 to 02cebd9 Compare May 21, 2026 19:43
plafosse added 2 commits June 5, 2026 21:42
Split MSVC symbol parsing from finalization by carrying the parsed qualified name in DemangleContext instead of using mutable demangler-wide name state. Function parsing now returns a DemangledFunction with the parsed DemangledTypeNode plus optional decoded thunk adjustor metadata, and the symbol-context callers finalize name-dependent work such as thunk suffixes and implicit this parameter synthesis.

Expand DemangledTypeNode into the shared representation used by the MSVC path for delayed type construction, platform-aware widths, calling convention resolution, member pointers, postfix forms, and explicit implicit-this parameters. This lets MSVC parsing produce structured type/name data first and defer Binary Ninja Type construction until finalization has the platform and view context.

Also route MSVC string literals, raw type-info names, vtables, RTTI, dynamic init/fini stubs, local guards, and referenced-symbol template values through explicit DemangledTypeNode/name flow.

Extensively tested with the MSVC demangler unit suite and a 199,500-symbol regression corpus with zero output changes or failures.
Update the GNU3 parser to use shared DemangledTypeNode references for substitutions, template substitutions, and nested type/name construction so backrefs preserve structure instead of copying stale formatted strings.

Fix template argument parsing for non-type template parameter declarations, expression arguments, argument packs, and generic lambda auto parameters while preserving enclosing template substitution state.

Carry platform context through GNU3 demangling/finalization so rendered and finalized types use the same delayed DemangledTypeNode representation as the other demangler paths.
@plafosse plafosse force-pushed the test_ms_demangler_fixes branch from 02cebd9 to 7862d28 Compare June 6, 2026 01:51
@plafosse plafosse marked this pull request as ready for review June 6, 2026 03:27
@plafosse plafosse requested a review from CouleeApps June 6, 2026 03:40
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