Repository navigation
Add ArchMIPSN32 for 64-bit MIPS with 32-bit pointers - #375
Conversation
|
Corpus decompilation diffs can be found at angr/dec-snapshots@master...angr/archinfo_375 |
|
THIS MESSAGE WAS GENERATED BY AN AUTOMATED PROCESS Validation record for head
Caveats: this is archinfo's own suite only — no workspace-wide gate, and no consumer repository was rebuilt or retested. Merge order, and what an incomplete chain doesThe four pull requests in this chain are Merging the loader and the architecture definition ahead of the lifter is the dangerous The figures below were measured at archinfo Measured 2026-08-28, at the heads named in the table, one process per object:
Population: 16 ELF objects, every one Over the fourteen MIPS III objects, of 261,039 line addresses:
Method notes: each arm asserts the resolved Objects, Public reproducer for the ordering, on the fixtures in
|
|
Can ArchPCode express that? |
|
THIS MESSAGE WAS GENERATED BY AN AUTOMATED PROCESS Partly — Ghidra models n32 as a first-class language and The language exists. And 32-bit pointers over the 64-bit register file — structurally the same thing But the semantics are not 32-bit. And it is unreachable regardless. What it would cost. To make it the right answer you'd need pypcode to apply One thing your question did surface in this patch: |
|
THIS MESSAGE WAS GENERATED BY AN AUTOMATED PROCESS Corrected, in Nothing downstream moves. Engine selection is The corpus and fixture figures therefore stand at the new head; the validation record is re-keyed to it in place, with the local results and the argument for the carry-over. Merge order is unchanged: archinfo 375, then pyvex 576, then cle 795, then angr 6982. Merging the loader and the architecture definition ahead of the lifter still drops recovery to zero blocks on MIPS-III objects. |
|
THIS MESSAGE WAS GENERATED BY AN AUTOMATED PROCESS Reading Before — archinfo masterAfter — with this change |
|
THIS MESSAGE WAS GENERATED BY AN AUTOMATED PROCESS Heads-up from the angr/mono#3 rollup: this pull request was skipped during assembly, and the four pull requests stacked on it were not. #365 and #375 both rewrite the signature and the opening docstring paragraph of which takes out all five Nothing here is wrong with the change itself — merged at head session: sharpen |
Both ABIs put a 64-bit MIPS instruction stream in an ELFCLASS32 container: the registers and the instructions are the 64-bit architecture's, while pointers, GOT slots, relocation entries and symbol table entries stay 32-bit. Measured on real n32 objects, .rel.dyn carries an sh_entsize of 8 (Elf32_Rel), .dynsym 16 (Elf32_Sym) and .got a 4-byte slot, so every ELF structure in the file is an Elf32_* one. That is why this is a new architecture rather than a reuse of ArchMIPS64. `bits` is what decides how wide a word CLE reads out of and writes back into a relocation slot; at 64 the loader reads an 8-byte implicit addend out of a 4-byte REL slot, writes 8 bytes back over the neighbouring word, and strides the GOT by 8. So `bits` stays 32 and only the decoding side -- the VEX guest, the capstone mode and the 64-bit register file -- is inherited from ArchMIPS64. The class is not registered with register_arch: the ABI is not recoverable from a machine name, only from the ELF e_flags, and ArchMIPS32's catch-all pattern already claims every 32-bit MIPS identifier. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
`bits` here is the width of a pointer and nothing else. The register file is 64-bit, inherited from ArchMIPS64, and nothing in this class says so out loud -- which is how a consumer ends up deriving a register's width from `bits // 8` and describing `a0`, an eight-byte register, as four bytes. angr's SimCC did exactly that, and on big-endian n32 it placed every 32-bit argument at offset 0 of the argument register, the sign-extension half the callee never reads. The docstring now states the separation, and a test pins the argument and return registers at eight bytes while `bytes` stays four, so the two cannot silently converge. Little-endian hides the whole question: there the two widths disagree only about which half of the register a value occupies, and offset 0 is right either way. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
archinfo declares no dependencies, so its bare matrix job installs no pyvex and Arch.__init__ leaves the register file empty. Two of the new tests read arch.registers and died with KeyError there while passing everywhere pyvex happens to be installed. Mirrors the pyvex/pypcode guards the other test modules already use.
ArchMIPSN32 inherited pcode_id from ArchMIPS64, so it named
MIPS:{BE,LE}:64:default -- the language whose ram space is 8 bytes wide and
whose compiler specs are the 64-bit ones. Ghidra ships MIPS:{BE,LE}:64:64-32addr
for exactly this ABI: size="32", a truncate_space of 4 on ram, an n32 compiler
spec, and an opinion constraint on EF_MIPS_ABI2.
Nothing dispatches on this today -- angr picks its engine on
isinstance(arch, ArchPcode), which ArchMIPSN32 is not, and no production code in
angr, cle or pyvex reads pcode_id -- so the only difference is what an explicit
ArchMIPSN32.pcode_arch() returns: an ArchPcode with bits 32 rather than 64.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
39bab86 to
20aa6f2
Compare
|
Dear agent, your docstring for the |
|
Adding this new arch def looks good to me. |
|
I'm fixing it. |
THIS MESSAGE WAS GENERATED BY AN AUTOMATED PROCESS
Problem
MIPS n32 and O64 put a 64-bit MIPS instruction stream in an ELFCLASS32 container: 64-bit instructions, 32-bit pointers and Elf32_* structures throughout. No architecture in archinfo can say that, because
bitsis both the pointer width and, throughvex_arch, the instruction set.On the n32 object
tests/mipsn32/n32_el_dynamic(e_flags0x80000027,EF_MIPS_ABI2set) the two candidates each get one half right:ArchMIPS32cannot decode the 64-bitsdthe prologue spills$gpwith.ArchMIPS64strides that object's.got—sh_entsize4, at0x10a30— by eight, so its first four slots read0x8000000000000000 0x00010a10000006c0 0x000008b0000109f0 0x00010a2400010000, each one two real slots glued together.Root cause
Arch.__init__derivesself.bytesfrombits, andArchMIPS64setsbits = 64as a class attribute, so the width used to read and write pointers is the same number that selects the VEX guest. There is no separate knob and nothing between the two classes.Fix
archinfo/arch_mips64.pygainsArchMIPSN32, subclassingArchMIPS64and settingbits = 32. It inherits the VEX guest, the capstone mode and the 8-byte register file, and narrows the pointer,sizeof["long"]and the TLS head to the 32-bit MIPS shape:bitsis the pointer width here and nothing else: the argument registers stay eight bytes, and a consumer that needs a register width reads it from the register file.It is deliberately not registered for name-based lookup.
ArchMIPS32already claims every 32-bit MIPS name, and an ABI is not recoverable from a name — detection belongs to the loader, which readse_flags.Testing
tests/test_mips.pyasserts the 32-bit word size and>I/<Iformat, the 64-bit VEX guest, thatsp,ra,pcand the eight argument registers stay 8 bytes and equalArchMIPS64's, bothpcode_ids and the C type sizes. It fails to import on master, which has noArchMIPSN32. The fixture above comes from the binaries half of this work.These four must land together: with the loader and the architecture definition ahead of the lifter,
MIPSN32reaches a lifter with no entry for it and recovery on these objects drops to zero blocks. Merge order: archinfo 375, then pyvex 576, then cle 795, then angr 6982.Validation: #375 (comment)
session: mega-corpus