Skip to content

Analysis-tier: MIPS PLT/stub import-name recovery - #23

Merged
mahaloz merged 2 commits into
mainfrom
mips-plt
Jun 24, 2026
Merged

mahaloz merged 2 commits into
mainfrom
mips-plt

Conversation

@mahaloz

@mahaloz mahaloz commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Analysis-tier: MIPS PLT/stub import-name recovery (Increment 27)

Recovers MIPS libc import names so calls render puts/printf, not sub_<addr>.

What the toolchain produces (investigated, not assumed)

mips-linux-gnu-gcc -O0 on a main calling puts/printf produces a classic .MIPS.stubs + $gp-relative GOT layout (task brief option b), NOT a regular .plt + R_MIPS_JUMP_SLOT:

  • readelf -r → "There are no relocations in this file." — no R_MIPS_JUMP_SLOT, no .plt.
  • .MIPS.stubs PROGBITS section of lw $t9,-32752($gp); move $t7,$ra; jalr $t9; li $t8,<dynidx> lazy resolver stubs.
  • DT_MIPS_LOCAL_GOTNO=6, DT_MIPS_GOTSYM=5, DT_PLTGOT=0x411020.

This is a clean port, not a documented seam — the names ARE recoverable statically. Calls are indirect through a GOT slot (lw $t9, off($gp); jalr $t9); the stub→name correspondence is the dynamic-symbol GOT layout: got_index(i) = LOCAL_GOTNO + (i - GOTSYM). Each FUNC import's GOT slot holds its .MIPS.stubs stub address (= the dynsym st_value). Cross-checked on the fixture: puts (dynidx 7 → GOT slot 0x411040 → stub 0x400800), printf (dynidx 8 → GOT slot 0x411044 → stub 0x4007f0).

The port — two halves, both faithful to MIPS_ElfExtension

  1. Naming (elf_plt::resolve_mips_imports, the fixupGot analog): walks the external-symbol GOT window and names each import's stub address (the slot's static contents = Ghidra's refAddr). Gated on Mips | Mips64, runs before the relocation-driven path (which would early-return on MIPS's empty reloc map). No-op off-MIPS.
  2. Folding the indirect call (elf_plt::mips_got_const_ranges + ObjectLoadImage::const_ranges → get_readonly, the setConstant analog): marks the GOT external slots constant so the engine folds the lw $t9, off($gp) load (address already $gp-constant from Increment 17) to the stub address; bootstrap_from_elf enables readonlypropagate for MIPS only so ActionVarnodeProps::fillinReadOnly + ActionDeindirect resolve the call to the named stub. option readonly off restores the raw GOT-load rendering.

BEFORE / AFTER (kuna decompile plt_mips32 main)

before:  (*(code *)(dat_411040 & 0xfffffffe))("hello");
         (*(code *)(dat_411044 & 0xfffffffe))(0x400888,v1);
after:   puts("hello");
         printf(0x400888,v1);

(The printf format-string pointer not rendering as a string literal is a separate string-rendering concern, independent of import naming; puts's "hello" already renders.)

elf_plt.rs additions

  • resolve_mips_imports — MIPS arm of resolve_plt_imports, gated Mips | Mips64.
  • mips_got_const_ranges — the GOT external slots to mark constant.
  • mips_external_got_entries — shared GOT-window walk.
  • read_mips_dynamic_tags — DT_MIPS_LOCAL_GOTNO/DT_MIPS_GOTSYM/DT_PLTGOT from .dynamic.
  • read_word_at_vma + endianness helpers.

Plus ObjectLoadImage::const_ranges (threaded through get_readonly/adjust_vma) and the MIPS-only readonlypropagate toggle in bootstrap_from_elf.

Tests

  • Fixture plt_mips32 (linked BE MIPS32, -O0 for plain puts/printf) + source + README provenance.
  • e2e kuna-console/tests/verify_mips_plt.rs (modeled on verify_riscv64_plt.rs) — ran, not skipped (mips32be.sla built; asserts a real decode of main + puts(/printf( named, dat_411040/dat_411044 gone).
  • Two loadimage_object unit tests (mips_stub_imports_resolve_to_named_functions, mips_got_const_ranges_cover_external_slots).

Gate results

  • make test — 675/675 PARITY OK
  • make test-stages — 158/158 PARITY OK
  • make rust-test — green (exit 0)

Purely additive on the real-ELF path; the XML datatest oracle (which never constructs an ObjectLoadImage or reaches bootstrap_from_elf) is structurally untouched.

NOTE: elf_plt.rs is also touched by the open SPARC PR #20 and the PPC64 branch — a trivial merge conflict (distinct per-arch arms) is expected and fine.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb

mahaloz and others added 2 commits June 23, 2026 18:58
MIPS o32 emits no .plt and no R_MIPS_JUMP_SLOT relocations: libc imports are
called indirectly through a $gp-relative GOT slot (lw $t9, off($gp); jalr $t9),
with the stub->name correspondence carried by the dynamic-symbol GOT layout
(DT_MIPS_LOCAL_GOTNO/DT_MIPS_GOTSYM/DT_PLTGOT, got_index(i)=LOCAL_GOTNO+(i-GOTSYM)).
This is layout (b) from the task brief (classic .MIPS.stubs), and the names ARE
recoverable statically -- a clean port, not a documented seam.

elf_plt::resolve_mips_imports (the analog of MIPS_ElfExtension.fixupGot /
processMipsStubsSection) walks the external-symbol GOT window and names each
import's .MIPS.stubs stub address (the GOT slot's static contents). To resolve
the indirect call, mips_got_const_ranges marks the GOT external slots constant
(ObjectLoadImage::const_ranges -> get_readonly, the setConstant analog) and
bootstrap_from_elf turns on readonlypropagate for MIPS only so the engine folds
the GOT load to the stub address and ActionDeindirect resolves the call to the
named import. Scoped to MIPS; option readonly off restores the raw GOT load.

BEFORE: (*(code *)(dat_411040 & 0xfffffffe))("hello");
AFTER:  puts("hello"); printf(0x400888,v1);

Fixture plt_mips32 (linked BE MIPS32, -O0, plain puts/printf) + e2e
verify_mips_plt.rs (ran, not skipped) + two loadimage_object unit tests.

Gates: make test 675/675 PARITY OK; make test-stages 158/158 PARITY OK;
make rust-test green. Purely additive on the real-ELF path; the XML datatest
oracle (which never reaches bootstrap_from_elf) is structurally untouched.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb
@mahaloz
mahaloz merged commit e09023d into main Jun 24, 2026
@mahaloz
mahaloz deleted the mips-plt branch July 29, 2026 08:01
mahaloz added a commit that referenced this pull request Sep 19, 2026
… every target the vararg rule admits

A closed format prototype also changes how P4 scores the argument trials of
the calls around it. On AArch64 and ARM32 firmware that added more wrong
arguments to neighbouring calls than it removed (an x8 of 0 ahead of the real
arguments; iproute2 ip's parse_rtattr losing its len), while on x86 every such
change removed a phantom. static now resolves at load on x86 only; full still
resolves on every target VarargAbi admits. Stage passes 24-26 pin AArch64
default == off and full typed; #13/#19/#23/#28 pin ARM the same way.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
mahaloz added a commit that referenced this pull request Sep 19, 2026
… every target the vararg rule admits

A closed format prototype also changes how P4 scores the argument trials of
the calls around it. On AArch64 and ARM32 firmware that added more wrong
arguments to neighbouring calls than it removed (an x8 of 0 ahead of the real
arguments; iproute2 ip's parse_rtattr losing its len), while on x86 every such
change removed a phantom. static now resolves at load on x86 only; full still
resolves on every target VarargAbi admits. Stage passes 24-26 pin AArch64
default == off and full typed; #13/#19/#23/#28 pin ARM the same way.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01YFCA715QE6ZBSnTn7bwabG
mahaloz added a commit that referenced this pull request Oct 2, 2026
…ter load

A MULTIEQUAL on the global only joins what reaches it, so the load walks
pass through one. New fixture functions e_calc, e_two, e_long, e_loop and
e_after, stage assertions #23-#30 and the spec prose for the change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012UUBmGqZTcD5N8LxpVsiQt
mahaloz added a commit that referenced this pull request Oct 2, 2026
…ter load

A MULTIEQUAL on the global only joins what reaches it, so the load walks
pass through one. New fixture functions e_calc, e_two, e_long, e_loop and
e_after, stage assertions #23-#30 and the spec prose for the change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012UUBmGqZTcD5N8LxpVsiQt
mahaloz added a commit that referenced this pull request Oct 2, 2026
…ter load

A MULTIEQUAL on the global only joins what reaches it, so the load walks
pass through one. New fixture functions e_calc, e_two, e_long, e_loop and
e_after, stage assertions #23-#30 and the spec prose for the change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012UUBmGqZTcD5N8LxpVsiQt
mahaloz added a commit to borancar/kuna that referenced this pull request Nov 14, 2026
…dows x86, and type its target

On main calleereginputs is on by default, so the virtual-dispatch case
now runs on every x86-32 image. Gate it to x86-32 Windows like the
direct case (Borland and other x86-32 specs stay inert). A call the
caller cleans up after (add esp,4: a C table of __cdecl function
pointers reached through ECX) keeps the default, since a __thiscall
callee removes its own arguments; a COM call whose interface is pushed
from the register ECX was copied from keeps it too. Lay out the target
type of a __thiscall-modeled indirect call under that model, so the
call prints through a function pointer instead of an uncallable void *.
Fixture gains ctable/comcopy (rebuilt from its recipe); stage Noelo-Lab#23-Noelo-Lab#25.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
mahaloz added a commit that referenced this pull request Nov 22, 2026
pushan_vm2_x86_64 gets a SEL handler that computes the next VPC
arithmetically from the low bit of the top of stack and from a comparison
below it (no flag test, as VMProtect's vJCC), and f_sel: x = a0 < 5 stored as
1 or 0 on two paths that join, then SEL on x and a1 < 3. The join merges x
into a symbol recorded as {0, 1}; without the symbol split the VPC stays an
ite over a byte of it and the next dispatch is unresolved (bin before
5e1e0ab0a: "incomplete: 1 unresolved computed jump"); with it all three
returns are recovered. New opcode and program are appended so every other
program's bytes, the data symbols and the existing outputs are unchanged.
Stage kuna-pushan-sound #23 pins the three returns, #20 now counts 17
devirtualized functions; baseline-stages re-recorded (4955 passing keys).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQR2hseBprKvbvZRUv
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