Skip to content

[AUTOMATED] Give the built-in libc table the C++ allocation operators - #1931

Open
kanonl125 wants to merge 29 commits into
Noelo-Lab:mainfrom
kanonl125:cxx-allocation-operator-prototypes
Open

kanonl125 wants to merge 29 commits into
Noelo-Lab:mainfrom
kanonl125:cxx-allocation-operator-prototypes

Conversation

@kanonl125

Copy link
Copy Markdown
Contributor

An imported C++ operator delete prints with no argument. No prototype table lists the Itanium allocation operators, and cppsig refuses operator names.

$ kuna decompile decompiler/crates/kuna-analysis/tests/fixtures/cxx_alloc_x86_64 drop_array
void drop_array(long *a0)
{
  if (a0) {
    operator delete[](); // tail-call
    return;
  }
}
  • The built-in libc table now lists the 44 replaceable global allocation and deallocation functions by their mangled names:
    • new and new[] take a size_t and return void *;
    • delete and delete[] take the pointer, and perhaps the size;
    • each also comes with std::nothrow_t const & and std::align_val_t;
    • in the m, j and y (MinGW-w64) size_t spellings.
  • A table entry is needed because mangling encodes no return type. cppsig couldn't give new its result even if it accepted the names.

Tests.

  • the_cxx_allocation_operators_take_and_return_what_the_abi_says derives each operator's signature from its mangled name and checks every entry.
  • cxx_allocation_operators decompiles the new cxx_alloc_x86_64 fixture, whose operators are PLT imports, and requires operator delete[](a0). It fails on the current tree.

Model: anthropic/claude-opus-5-5

kanonl125 and others added 8 commits November 24, 2026 05:11
[AUTOMATED] An imported operator delete[] printed with no argument:
Itanium mangling encodes no return type, cppsig refuses operator names,
and no table listed _Znwm, _ZdlPv and the rest. The built-in libc table
now lists the 32 global allocation and deallocation functions by their
mangled names: new and new[] take a size_t and return void *, delete
and delete[] take the pointer and perhaps the size, each also with
std::nothrow_t and std::align_val_t, in the m and j size_t spellings.

A unit test pins the signatures. cxx_allocation_operators decompiles a
new cxx_alloc_x86_64 fixture, whose operators are PLT imports, and
requires drop_array's delete[] to keep its pointer.
[AUTOMATED] MinGW-w64 x64 mangles size_t as y (unsigned long long), so
_Znwy, _ZdlPvy and their aligned and nothrow forms join the table, for 44
entries. The unit test derives each operator's signature from its mangled
name and checks every entry, and that no name is listed twice. The CLI
test also checks drop_array's own signature.
[AUTOMATED] The previous commit's rewrite of the operator block deleted
the three entries between it and the ptrace comment. The block now
follows memset, so the change only adds entries.
…ototypes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
The new table rows lock operator new/delete's parameters. On an i386 PE the
default model is __stdcall with an unknown extrapop, so a locked one-argument
operator was read as popping its own argument, and in a GCC fixed frame every
later [esp+k] moved by 4: calls after operator new[] took the wrong locals and
a caller grew a phantom parameter. LibProtoPass now reports every operator name
the image imports or defines alongside the C runtime imports, and the commit
boundary declares them __cdecl. Inert wherever the default model states its
extrapop (x86-64, every ELF, every RISC spec).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
…ment both fixtures

tests/stages/kuna-cxxalloc.xml decompiles the x86-64 fixture's drop_array
(operator delete[](a0)) and a clean-room i386 PE, cxx_alloc_pe_i386.exe
(nasm, from cxx_alloc_pe_i386.asm), whose GCC fixed frame imports _Znwj, _Znaj,
_ZdlPvj and _ZdaPv from libstdc++-6.dll; it pins every argument there. The
fixtures README gets a row with the build line and SHA-256 for each fixture,
and the table's comment block becomes a one-line section label (the spec
carries the explanation).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
…ototypes

Stage corpus count 901 (main's kuna-calloverlap-floatret plus kuna-cxxalloc);
docs/baseline-stages.json is main's 5290 assertions plus the 9 CXXALLOC ones.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
@mahaloz

mahaloz commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

[AUTOMATED] Pushed three commits on top of your branch (no force-push):

$ kuna decompile decompiler/crates/kuna-analysis/tests/fixtures/cxx_alloc_pe_i386.exe 0x401000
# before: sub_401090(v2,a1,a2);  v3 = sub_4010b0(v2,a2,v1);   (copy3 is handed b, cmp3 is handed n)
# now:    sub_401090(v2,a0,a2);  v3 = sub_4010b0(v2,a1,v1);
  • On an i386 PE the default convention is __stdcall with an unknown pop, so a locked operator new[](size_t) imported from libstdc++-6.dll was read as popping its own argument. In a GCC fixed frame every later [esp+k] then moved by 4. The operator names are now declared __cdecl the way C runtime imports are; this is inert on x86-64, ELF and the other targets.
  • Added tests/stages/kuna-cxxalloc.xml with a small nasm-built fixture (cxx_alloc_pe_i386.exe from cxx_alloc_pe_i386.asm), README rows with the build line and SHA-256 for both fixtures, and a one-line label in place of the comment block inside the table.
  • Merged current main.

[AUTOMATED] The corpus count is upstream's 908 plus this branch's stage
test, 909, and the stages baseline is upstream's with this branch's nine
CXXALLOC assertions added.
[AUTOMATED] The corpus count is upstream's 909 plus this branch's stage
test, 910, and the stages baseline is upstream's with this branch's nine
CXXALLOC assertions added.
[AUTOMATED] The corpus count is upstream's plus this branch's stage
test, and the stages baseline is upstream's with this branch's nine
CXXALLOC assertions added.
[AUTOMATED] The stage corpus count is main's 913 plus kuna-cxxalloc, 914.
The stages baseline is main's plus this branch's 9 CXXALLOC assertions
(neither side removed one): 5379.
[AUTOMATED] The stage corpus count is main's 917 plus kuna-cxxalloc, 918.
The stages baseline is main's 5419 assertions plus this branch's 9
CXXALLOC ones; main's armshiftguard change replaced 10 ARM shift
assertions, which this branch does not touch.
[AUTOMATED] The stage corpus count is main's 922 plus kuna-cxxalloc, 923.
The stages baseline is main's 5441 assertions plus this branch's 9
CXXALLOC ones (neither side removed one): 5450.
[AUTOMATED] The stage corpus count is main's 926 plus kuna-cxxalloc, 927;
the stages baseline is main's plus this branch's 9 CXXALLOC assertions.
[AUTOMATED] The stage corpus count is main's 927 plus kuna-cxxalloc, 928; the stages baseline is main's plus this branch's 9 CXXALLOC assertions.
[AUTOMATED] The stage corpus count is main's plus kuna-cxxalloc; the stages baseline is main's plus this branch's 9 CXXALLOC assertions.
[AUTOMATED] The stage corpus count is main's plus kuna-cxxalloc; the stages baseline is main's plus this branch's 9 CXXALLOC assertions.
[AUTOMATED] The stage corpus count is main's plus kuna-cxxalloc; the stages baseline is main's plus this branch's 9 CXXALLOC assertions.
[AUTOMATED] The stage corpus count is main's plus kuna-cxxalloc; the stages baseline is main's plus this branch's 9 CXXALLOC assertions.
[AUTOMATED] The stage corpus count is main's plus kuna-cxxalloc; the stages baseline is main's plus this branch's 9 CXXALLOC assertions.
[AUTOMATED] The stage corpus count is main's plus kuna-cxxalloc; the stages baseline is main's plus this branch's 9 CXXALLOC assertions.
[AUTOMATED] The stage corpus count is main's plus kuna-cxxalloc; the stages baseline is main's plus this branch's 9 CXXALLOC assertions.
[AUTOMATED] The stage corpus count is main's plus kuna-cxxalloc; the stages baseline is main's plus this branch's 9 CXXALLOC assertions.
[AUTOMATED] The stage corpus count is main's plus kuna-cxxalloc; the stages baseline is main's plus this branch's 9 CXXALLOC assertions.
[AUTOMATED] The stage corpus count is main's plus kuna-cxxalloc; the stages baseline is main's plus this branch's 9 CXXALLOC assertions.
[AUTOMATED] The stage corpus count is main's plus kuna-cxxalloc; the stages baseline is main's plus this branch's 9 CXXALLOC assertions.
[AUTOMATED] The stage corpus count is main's plus kuna-cxxalloc; the stages baseline is main's plus this branch's 9 CXXALLOC assertions.
[AUTOMATED] The stage corpus count is main's plus kuna-cxxalloc; the stages baseline is main's plus this branch's 9 CXXALLOC assertions.

This branch has not been deployed

No deployments
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.

2 participants