Repository navigation
[AUTOMATED] Name locals after the library calls they meet (libcnames) - #1102
Merged
Merged
Conversation
mahaloz
force-pushed
the
fix/libcnames-names
branch
3 times, most recently
from
October 14, 2026 22:20
28e2eac to
12c94c3
Compare
A local that holds a library call's result, or that is handed to one whole, kept a vN although kuna's own libc tables type the call: `v1 = open(a0,0); v3 = read(v1,v4,0x200);`. The libc tables now carry glibc's declared parameter names (leading underscores stripped, read from the headers by docs/features/libcnames/gen_names.py) and a conventional result name where the result is one kind of thing (fd, n, len, p, fp, pid, tp, ...), on the prototype they park but outside innames, so the callee's signature and name locks do not change. The new P6 option libcnames (default off, on under --mode aggressive) prints a numbered local under the name of its strongest evidence: a call's return value (when every library result it holds agrees), then a whole argument whose name says what the value is, then a role name (dest/src, s1/s2) only when every such name agrees. Names equal to a printed type or a C or Rust keyword are skipped; clashes take _2, _3 in call order past every printed name. The library name is a second name for the local's number: the walk numbers every local as with the option off, records that numbering, and only then applies the names, so vN identity is the same in every mode. A directive reaches the local by either name and a replay records the number; a local whose library name a rename took prints its number, and a vacated name goes to no one. Tests: tests/stages/kuna-libcnames.xml, kuna-cli library_names (renames, retypes, mode switches, displaced names, globals, keywords, and a compile-and-run of tp beside the typedef tm), the wasm and browser rename and mode-switch flows, and unit tests. Round-trip tests and seven CLI probes of other options read the new names; the ghidra-sim differential runs its CLI side with the option off. Over 14 stripped decbench binaries under --mode aggressive, 968 of 10,106 numbered locals print a library name in 546 of 3,297 functions, only names changing; 0/675 datatest assertions move. Default off because six stage assertions of other features spell a vN it names. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011ib7dvKSnoqFMNwr6Wu6dm
`name fd v9` printed `fd_3`: the naming pass took any number-shaped name for a number to print a library name over, the caller's included. A name a rename gave, or a name-locked Symbol holds, now stays, and a local's prior library name is looked up by the number its instances had, so a rename onto that number leaves it its library name. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011ib7dvKSnoqFMNwr6Wu6dm
…ed under its number too The check that an applied rename or retype is visible looked for a declaration under the number a replay records, and a local printed under its library name never matched: `type fd unsigned int` was applied and reported refused. A declaration under a local's library name now counts for its number as well. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011ib7dvKSnoqFMNwr6Wu6dm
…he spec Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011ib7dvKSnoqFMNwr6Wu6dm
…n with strlenscan Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011ib7dvKSnoqFMNwr6Wu6dm
mahaloz
force-pushed
the
fix/libcnames-names
branch
from
October 14, 2026 22:38
12c94c3 to
6b3c9ca
Compare
…does not read A global the function never reads still owns its name in the printed program, so the printer suffixed the local as fd_1, which no directive can address. Every global the program names is now reserved, and the local takes the next spelling (fd_2) instead. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011ib7dvKSnoqFMNwr6Wu6dm
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.
Part 1 of the #1098 proposal (#1076): a local that holds a library call's result, or is handed to one whole, prints the library's name for it, as a second name for the number it keeps.
What this makes possible
gcc -O2 -fno-inline two.c -o two && kuna decompile ./two copy_fileon main:With this PR (
--mode autopicksaggressivehere, which turns the option on):v4andv5keep the numbers they have with the option off, so a directive reaches the same local in every mode, by either name:name fd srcandname v1 srcboth rename the first descriptor, under--mode reliabletoo.The change
__stripped, read from the headers bydocs/features/libcnames/gen_names.py; 554 of 567 entries) and a result name where the result is one kind of thing (fd,n,len,p,fp,pid,tp, ...; 91 entries). They ride on the parked prototype but outsideinnames, so callee signatures and name locks are unchanged.libcnames. The evidence is a return value first (only when every library result the local holds agrees), then a whole argument whose name says what the value is, then a role name (dest/src,s1/s2), but only when every role name agrees. A name equal to a type the code prints (tm,FILE) or a C or Rust keyword is skipped. Clashes take_2,_3in call order, past every printed name, globals included.name v5 nleaves read's resultv3, andname v3 gotreaches it). A name a rename vacates goes to no one.vNthis names (strlen(v7);becomesstrlen(s);). They are KUNA-CALLPLACEHOLDER Port to Rust #2, elemptr Recover PLT/GOT import names in ELF decompilation #4, fieldtype Recover PLT/GOT import names in ELF decompilation #4, Stage reorg #5 and infra: dev container + cross-arch toolchains #12, and FMTSTATIC Render unknown types as real C types (realtypes, DIV-6) #6.--mode aggressiveturns it on, so the web page and--mode autounder 500 KiB get it.Tests
tests/stages/kuna-libcnames.xml: the shipped default, the option, and three console renames (fd, onto read'sn, then that local by its number).kuna-clilibrary_names, on both output surfaces:type fd unsigned int,type v1 unsigned int), and a rename to a number-shaped name (name fd v9) is kept;pid_2, addressable);access'stypein C and Rust;tpbeside the typedeftm, compiled and run against the source with gcc and clang.lenon the page, rename the displaced local by its number, and switch to Reliable and back with every edit still applied.vNread the new name. The round trips still compile and run the printed C. The ghidra-sim differential runs its CLI side with the option off, as it doesformatstring.--mode aggressive), 968 of 10,106 numbered locals print a library name, in 546 of 3,297 functions. Every changed function differs only in those names, and every other local keeps its number. Of 415 named locals located in the source, 91 carry the source's name and 324 another spelling of the same meaning (fpforinStr,tpfortm); none is misleading.decompile-allmin of 11 interleaved against main 151c35d: +0.00% under--mode aggressive, -0.42% under--mode reliable, and +0.59% under--mode reliablewith directives (noise).🤖 Generated with Claude Code
https://claude.ai/code/session_011ib7dvKSnoqFMNwr6Wu6dm