Repository navigation
[AUTOMATED] Preserve declared indirect-call prototypes and ABI - #804
Conversation
…ed prototypes - An unregistered calling convention on a function-pointer declarator now falls back to the default model, as upstream TypeDeclarator::getModel does, instead of failing the parse. The grammar unit tests now build a factory with models registered and check the convention the code type carries. - The type factory's default and named models are re-shared whenever the extrapop or defaultprototype option replaces one, so they cannot go stale. - Function-pointer code types no longer carry parameter names (as upstream): code types compare equal without them, so a name could leak from another declaration into local variable naming. - ActionDeindirect reports the forced-prototype change so the stackstall loop folds the committed inputs (no more `(int)1` constant casts). - Single override lookup in build_call_specs; temp dirs removed by the CLI test; spec 04 describes the forced-prototype arm, the saved FuncProto override and the kept conventions. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
|
[AUTOMATED] Thanks for this fix. I merged main into the branch and added one commit on top:
|
…reused A parameter in a register pair (a join of registers) got an unlimited use point, so its per-piece map entries linked any later write of one of the pair's registers to a piece of the parameter. On 32-bit ARM, MIPS and PowerPC a call that reused one of the registers printed a write into half of the parameter, then passed the modified parameter. Limit the join's entries to the function input, as for a single register. Also port the calculated-bool arm of commitNewOutputs, which forced prototypes now reach. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
|
[AUTOMATED] I pushed one more commit (ff8c7e4) on top of a merge of current main. On 32-bit ARM, MIPS and PowerPC, a typed indirect call that takes a The same commit makes a forced |
…oat convention A function-pointer prototype that passes or returns a float was forced under the default model, which puts floats in FP registers. On a soft-float image that printed uninitialized d0/s0/f1 locals as the arguments and dropped the ones the caller set. The loader now reports what the container states about float argument passing (ARM attributes and header flags, MIPS abiflags and GNU attributes, PowerPC GNU attributes, RISC-V header flags). A soft-float ARM image gets the prototype rebuilt under __stdcall_softfp; other soft-float images keep the recovered arguments; an image that states nothing gets the declared prototype only when the function computes with the model's float registers. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
A float the default model already passes in integer registers or on the stack (a MIPS double after an int, a variadic argument) has the same storage under the soft-float convention, so that prototype is still forced. Only a prototype that puts a parameter or its return value in a floating-point entry of its model waits for the image's evidence. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
|
[AUTOMATED] I merged current main and pushed two commits on top (ad58ba0, 9e452d7). On soft-float images (ARM
I added |
…e-precision convention A single-float image (RISC-V lp64f/ilp32f, MIPS fp_abi 2, PowerPC single-precision) passes doubles in integer registers, and an image that states no convention may be ARM softfp, single-float or soft-float code that still computes in floating-point registers, so counting FP-register use as hard-float evidence forced double storage the caller never set. Both now keep the arguments model recovery finds; hard-float images and the ARM soft-float rebuild are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
|
[AUTOMATED] Narrowed the floating-point gate and merged main again.
|
…nd unextended narrow returns A declared variadic prototype whose return or a fixed parameter sits in a floating-point register or a register pair is no longer forced at an indirect call: ARM passes every variadic value in core registers, a locked variadic prototype with a floating-point return drops the floating-point arguments past its fixed ones (x86-64, AArch64), and a register-pair fixed parameter printed a stale word (32-bit ARM, PowerPC, RISC-V, MIPS). A return value narrower than its register is forced only where the caller extends it (x86, AArch64) or the model extends it by type (inttype). MIPS states no extension (the rest of v0 printed as an unassigned piece) and RISC-V states zero extension (a negative char/short, or int on RV64, became a large positive value). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
|
[AUTOMATED] Merged current main (#793, #798) and added cf20ba7, which narrows when a declared prototype is forced at an indirect call:
Both cases print main's output again. Direct calls on main have the same two defects; they are filed as #816 and #817. Two tests were added to |
…arm64 An Apple arm64 callee extends a signed char or short return to 32 bits and its caller reads w0 as it is, so forcing the declared prototype applied the AArch64 model's zero extension to a sign-extended value and printed a negative result as a large positive one. A Mach-O arm64 image (and the AppleSilicon language) now counts as caller-extended only from 32 bits up; narrower typed returns keep the recovered call, and an int or wider return is still forced. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
The same caller bytes (a blr read as w0, no sxtb) are correct only when the callee extended a narrow return, so a raw AArch64 image or one the Ghidra front-end supplies now keeps the recovered call for a typed return narrower than 32 bits, as a Mach-O one does. Only an ELF or PE arm64 image, whose AAPCS64 caller extends, still gets a narrow return forced. The container fact moves to its own loader module and becomes tri-state. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU
|
[AUTOMATED] One more change on top, for narrow typed returns on arm64.
|
…d the stack is printed as overwritten (#863) ## The problem On ARM, MIPS and RISC-V, a by-value struct parameter whose fields span registers and the stack is printed as assigned to when the function reuses one of its registers, and copying its register fields to memory is dropped. ```sh cat > d.c <<'EOF2' struct s3 { int x, y, z; }; extern int take3(struct s3, int); extern int use3(struct s3 *); int d1(int *k, int a, struct s3 s) { return take3(s, *k) + a; } int d4(int a, int b, struct s3 s) { return use3(&s) + a; } EOF2 clang --target=armv7-linux-gnueabihf -O2 -c d.c kuna decompile-all d.o --assert-strict \ --assert 'typedef struct s3 { int x; int y; int z; };' \ --assert 'prototype take3 int take3(struct s3 s, int k)' \ --assert 'prototype use3 int use3(struct s3 *p)' \ --assert 'prototype d1 int d1(int *k, int a, struct s3 s)' \ --assert 'prototype d4 int d4(int a, int b, struct s3 s)' ``` ``` s.z = s.z; s.y = *k; v2 = s.y; v1 = s.x; v3 = CONCAT44(v2,v1); s.x = s.z; return take3((s3)CONCAT48(s.x,v3),s.y) + a; ... s.z = s.z; v1.z = s.z; return use3(&v1) + a; ``` `d1` passes `s` unchanged in r0-r2 and `*k` in r3. `d4` stores `s.x` and `s.y` next to `s.z` before passing `&v1`. With this change they print `k_00 = *k; return take3(s,k_00) + a;` and `v1.z = s.z; v1.y = s.y; v1.x = s.x;`. ## The fix - A struct parameter split between registers and the stack binds to its symbol only at the function input, as a register pair has since #804 and as upstream does for every join. A later write of one of its registers is a new value. - Heritage splits a join into its pieces on the first pass that heritages any of them. On little-endian targets the first piece is the stack word, so the split waited for the stack pass; by then every read of the register fields was a bare input that nothing kept alive, so the stores of them were removed as dead. Not fixed: when the function stores the register fields just below the stack part and passes pointers into the result to a call (gcc and clang do this when the parameter's address is taken), the stack part still prints as a separate local, and a value the call writes through a pointer is read back from that local (#861). AArch64 should never split such a struct (#859). ## Tests `split_struct_params.rs` decompiles the two functions above for ARM and MIPS o32, and a RISC-V lp64d struct held in `a7` and the stack whose `a7` is reloaded for a call. All five fail on main. `decompile-all` over 14 stripped binaries (4,315 functions) is byte-identical. Over 10 unstripped ARM firmware images, where DWARF supplies the prototypes, 3 functions change: `fopencookie` and `_fopencookie_r` lose `functions.seek = functions.seek;` lines and a field-by-field copy, and `gyroReadSensorTemperature` is the case above. Decompile-all time, interleaved min of 15: +0.9% (chibios with DWARF), -2.7% (nuttx), +0.7% (cat). Fixes #814 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_012UUBmGqZTcD5N8LxpVsiQt
Problem
Accepted function-pointer fields lose their receiver, float argument and float
return type when called through an object's vtable. This synthetic ELF needs
only Python's standard library to reproduce it:
The setter currently emits
(*node->vtable->set_scale)();despite strictacceptance. It should emit
(*node->vtable->set_scale)(node,scale);.Fix
output commitment after late restriction.
retain explicitly named calling conventions when parsing pointer fields.
to the function input, so reusing one of its registers no longer prints as a
write into the parameter. Direct calls had this on main too:
v._0_4_ = *o; return wide3(v,(int)v) + 1;is nowk = *o; return wide3(v,k) + 1;.where the ELF states a double-precision hard-float convention (x86 and
AArch64 always). On soft-float ARM it is rebuilt under
__stdcall_softfp:main's
(*o->f)(0,0x40040000,k + 1)becomes(*o->f)(2.5,k + 1).Soft- or single-float MIPS, PowerPC and RISC-V, and images that state no
convention (raw images, clang PowerPC or attribute-less ARM objects), keep
the arguments kuna recovers without the declaration.
or a fixed parameter is floating-point or a register pair, and for a return
narrower than its register where neither the caller (x86, ELF or PE arm64)
nor the model (ARM, PowerPC) extends it:
char/short/boolon MIPS,RISC-V, Apple arm64 and arm64 images that state no platform, and
intonRV64. Forcing those printed a dropped
0.5, a stale register-pair word,CONCAT31(v1,(*v2)(k))withv1unset, or a negative result zero-extended(
(unsigned int)(unsigned char)(*v1)(k) * 3on Apple arm64).Not fixed here: direct calls and a function's own prototype on soft-float ARM
(#813), struct parameters split between registers and the stack (#814), and
direct calls with the narrow returns (#816, Apple arm64 included) or variadic
prototypes (#817) above.
Tests
typed_vtable_cli.rs: SysV receiver and float, explicit MSABI on a SysVimage, and an untyped control.
register_pair_params.rs: direct and typed calls on ARM and big-endianPowerPC. All four fail on main.
soft_float_typed_calls.rs: soft-, single-, hard- and unstated-conventionARM, PowerPC and RISC-V, plus variadic calls on hard-float ARM and narrow
returns on RISC-V, MIPS, Apple arm64 and a raw arm64 image.
Fixes #802
🤖 Generated with Claude Code
https://claude.ai/code/session_01Ps66ZCFPLywq9AKHBuDXNU