Skip to content

[AUTOMATED] Name a jump thunk after its target (option thunknames, default on) - #1879

Merged
mahaloz merged 12 commits into
Noelo-Lab:mainfrom
coleleavitt:fix/armthunk
Nov 22, 2026
Merged

mahaloz merged 12 commits into
Noelo-Lab:mainfrom
coleleavitt:fix/armthunk

Conversation

@coleleavitt

@coleleavitt coleleavitt commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

[AUTOMATED] A function whose whole body is one b <target> (a linker branch island, an identical-code-folding forwarder, an outlined tail call) keeps the placeholder name sub_<addr>, so every call through it is anonymous although its target is named. arm64 Swift images have hundreds of these.

cat > t.S <<'EOF'
	.text
	.globl release_box
	.type release_box,%function
release_box: ldr x8, [x0]
	sub x8, x8, #1
	str x8, [x0]
	ret
.Lthunk:  b release_box
.Lthunk2: b .Lthunk
	.globl drop_box
	.type drop_box,%function
drop_box: stp x29, x30, [sp, #-16]!
	bl .Lthunk
	bl .Lthunk2
	ldp x29, x30, [sp], #16
	ret
EOF
clang --target=aarch64-linux-gnu -nostdlib -static -fuse-ld=lld -Wl,-e,drop_box -o t t.S
kuna decompile t drop_box
  sub_210130();
  sub_210134();

Fix (option thunknames, default on, any architecture)

  • While committing the discovered entries, the engine decodes each entry's first instruction and keeps every direct unconditional branch to another address.
  • After every other name source has run, a thunk still named sub_<addr> becomes j_<target> when the target's function has a real name; a thunk to a thunk becomes j_j_<target> (at most four hops). A taken name gets the first free _<n> suffix.
  • A renamed thunk also takes its target's prototype, prototype model and Swift self classification (where it has none of its own), so calls through it print the target's argument and return types. A thunk with a name of its own keeps its own prototype recovery.
  • With lazyfuncs, only thunks whose chain ends at a named entry are made functions eagerly, so the lazy inventory stays lazy.
  • Indirect import stubs (adrp; ldr; br, arm64e braa) are left to the stub passes.

After: j_release_box(); and j_j_release_box();; with a DWARF prototype on release_box, a caller passing its argument through now prints long drop_box(long *a0) instead of (unsigned long a0). On the Perplexity iOS 26.46.0 main binary 618 functions are renamed (e.g. j_swift_release_x1, j_Foundation.UUID.init()), reached by 1,211 bl sites in 935 functions, and 179 of them take a prototype or prototype model from their target; 160 more across the frameworks. decompile-all on DeviceKit: 2.60 s on vs 2.45 s off (noise).

Tests: stage test tests/stages/kuna-thunknames.xml with fixture thunknames_aarch64 (source beside it) asserts the sub_ calls and untyped callers with the option off, and j_release_box( / j_j_release_box( and the long * parameter with it on; the "on" assertions fail without the change. Datatests 675/675 and the stage baseline unchanged apart from the four new keys.

Model: anthropic/claude-opus-5-5:high

coleleavitt and others added 7 commits November 22, 2026 02:43
…default on)

A function that loads a memory cell, returns it when set, and otherwise
computes the value, stores it into the cell and returns it was recovered
void: at the RETURN the return register is the cell's load on one path and the
stored value on the other, and ancestorOpUse refuses both because the load is
also branched on and the stored value is also stored. Swift's lazy
witness-table accessors, metadata caches and
__swift_instantiateConcreteTypeFromMangledName are this shape, and their
callers read a result the function did not have.

ActionReturnRecovery now takes the trial when every value reaching each live
RETURN is a LOAD of one cell or a value a STORE writes into it (same space,
same pointer), at least one of each. Stage test kuna-cachereturn.xml.
…fault on)

A function whose first instruction is a direct unconditional branch is a
jump thunk (a linker branch island, an ICF forwarder, an outlined tail call;
one `b <target>` on arm64). Nothing named it, so it stayed `sub_<addr>` and
every call through it was anonymous although its target is named. While
committing the discovered entries, the engine now decodes each entry's first
instruction, and after every other name source renames a placeholder thunk
`j_<target>` when the target has a real name; a thunk to a thunk becomes
`j_j_<target>`. Under lazyfuncs only thunks whose chain ends at a named entry
are made functions eagerly. Stage test kuna-thunknames.xml with the fixture
thunknames_aarch64.
A call through a renamed thunk printed the target's name but was typed as a
call to an unknown function. After every prototype stream has run, each
renamed thunk now takes its chain's target's parked prototype and bound prototype
model (where it has none of its own) and its Swift `self` classification,
so the call is typed as a call to the target. A thunk with a name of its
own keeps its own prototype recovery. The fixture is now built from
C with DWARF so the stage test can see the prototype carried into the
callers.
…esult and a non-stack cell

As submitted the rule also turned void functions into returning ones:
- gcc AArch64, clang ARM32 and gcc MIPS compile `void init(void) { if (!g) g = make(); }`
  to the accessor's exact bytes; in gcc -O2 AArch64 bash and coreutils 10 of the 11
  functions it changed are void (initialize_aliases, phash_create, add_temp_dir, ...).
- A value updated in place (`x = *p; if (x) *p = x - n;`) left the cell's value in the
  return register of void functions (sqlite selectRefLeave, an ARM firmware routine).
- Go's morestack path spills x0 to [sp+8] and reloads it, so 37 Go runtime functions
  on arm64 changed signature, most of them void ones now returning their first argument.

The rule now needs the image's source language to be Swift (the sourcelang fact),
takes a stored value only when it is a call's result (the CALL's output or the
INDIRECT a call creates), and refuses a cell whose pointer is computed from the
stack pointer. Swift lazy witness-table accessors on arm64 Mach-O are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
…on a C image

The phases.toml row, the spec section and the stage test now say the rule acts on
Swift images only and why (gcc AArch64 compiles a void initializer to an
accessor's bytes). The stage test forces `option sourcelang swift` for its
off/default passes and adds a `sourcelang c` pass where every function stays void.
Stage baseline: the five CACHERETURN keys renamed, count unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
…h alone

A delay slot is decoded as part of its branch, so MIPS `j release_box` with
`addiu $a0,$a0,16` in its slot (a `this` adjustor) classified as an
unconditional branch and was renamed `j_release_box_1` and given release_box's
prototype. A thunk now needs the decoded instruction's p-code to be the single
BRANCH; `j f; nop` still qualifies. inherit_prototypes also returns before
cloning the prototype-model map when nothing was renamed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
New fixture thunknames_mips (1 KB, source and recipe beside it): two symbol-less
`j release_box` entries, one with a nop in its delay slot and one with
`addiu $a0,$a0,16`. Stage passes 3-4 assert the first is renamed and the second
keeps sub_4000e8 with the option on (THUNKNAMES #7, #8; #8 fails before the
fix). The phases.toml row and the spec say a thunk's branch does nothing else.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
@mahaloz

mahaloz commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

[AUTOMATED] Pushed b3c6268 and 0b17d4b on top of your head.

A MIPS j release_box with addiu $a0,$a0,16 in its delay slot (a this adjustor) was renamed j_release_box_1 and given release_box's prototype. The delay slot decodes into the branch instruction, and classify still reports an unconditional branch. A thunk's first instruction must now lift to a single BRANCH op; j f; nop still counts, and so do AArch64 b, Thumb b.w and x86 jmp. New fixture thunknames_mips (source and recipe beside it) and stage assertions THUNKNAMES #7/#8 cover both cases. Also, inherit_prototypes now returns early when nothing was renamed.

mahaloz and others added 5 commits November 22, 2026 13:45
cachereturn joins switchmerge from main: 234 settables, tiers 50/125/59,
87 live fields, 233 catalog records, KUNA-CATALOG Noelo-Lab#15 242.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
thunknames joins cachereturn and switchmerge from main: 235 settables,
tiers 50/125/60, 234 catalog records, KUNA-CATALOG Noelo-Lab#15 243 (thunknames
has no live field: 87 unchanged).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKNhsvezm24JAGcKtoV
@mahaloz
mahaloz merged commit 9cdc5c3 into Noelo-Lab:main Nov 22, 2026
@coleleavitt
coleleavitt deleted the fix/armthunk branch November 22, 2026 20:13
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