Repository navigation
Description
Environment
$ date
r2 -v
uname -ms
Fri 18 Sep 01:14:14 BST 2026
radare2 6.2.2 +37545 abi:142 @ linux-x86_64
birth: git.6.2.2 2026-09-17__17:41:32
commit: ad27058877024389292fddf12e1db6e13824ba34
options: gpl -O? cs:5 cl:2 make
Linux x86_64Description
On x86-16, the default calling convention is fastcall.
If a function is first analysed with af, radare2 recovers a generic BP-relative argument under that convention.
Changing the function to cdecl afterwards and running afva does not reconcile the existing autogenerated variable with the known typed prototype.
The function signature is correct: int typed16 (short value);
but the recovered variable remains generic: arg int16_t arg_4h @ bp+0x4
The expected variable is:
arg short value @ bp+0x4Repeated afva calls leave the stale name and type unchanged.
This was found while testing #26747 after the typed-function recovery change.
Further debugging shows that the 2-byte slot calculation is correct: during cdecl recovery, ptr=4, bp_off=2, and frame_off=2. The problem is that the existing generic variable causes recovery to return before the prototype argument can be applied.
This appears related to, but distinct from, #19595. #19595 reports a false-positive ax register argument in x86-16 analysis; this report is about stale BP-variable metadata after changing the function calling convention.
Potential area of change
When a function's calling convention changes, invalidate or reconcile autogenerated argument variables.
For typed functions, afva could replace a default arg_* name/type when the variable's recovered storage slot matches a
declared prototype argument, while continuing to preserve explicitly renamed or retyped variables.
Test
The test uses a conventional 16-bit frame:
push bp
mov bp, sp
sub sp, 2
mov ax, word [bp+4]
mov word [bp-2], ax
leave
retMinimal reproduction:
r2 -NN -q -a x86 -b 16 malloc://32wx 5589e583ec028b46048946fec9c3
f typed16
td int typed16(short value);
af
afc cdecl
afva
afcf
afvbActual output:
int typed16 (short value);
arg int16_t arg_4h @ bp+0x4
var int16_t var_2h @ bp-0x2Running afva again produces the same result.
Control
If variable recovery is disabled until after the correct calling convention is
selected, the prototype is mapped correctly:
wx 5589e583ec028b46048946fec9c3
f typed16
td int typed16(short value);
e anal.vars=false
af
afc cdecl
e anal.vars=true
afva
afcf
afvbOutput:
int typed16 (short value);
arg short value @ bp+0x4
var int16_t var_2h @ bp-0x2Deleting the recovered variables before retrying also works:
afc cdecl
afv-*
afva
Activity
Fix #26760 - Refresh inferred x86-16 arguments ##analysis
Fix #26760 - Refresh inferred x86-16 arguments ##analysis
trufae commentedon Sep 20, 2026
Can you try now? The pr is merged and took the libeety to extend the thing for 8bit cpua like the gb
andreibelov commentedon Sep 20, 2026
Confirmed on the merged commit
4b3b55103b.The original x86-16 reproducer now reports:
Also:
Repeated recovery is idempotent: repeated
afvacalls, including a 200-pass check, keep the same two variables with no duplicates.Explicit user edits are preserved: renamed and retyped variables remain unchanged after further
afvapasses.db/anal/x86_16_varsanddb/anal/small_register_varspass 6/6 on the merged fix;test_anal_x86passes, as do the adjacent variable/calling-convention/function unit tests exercised by the reviews.The x86-16 tests also pass through Zydis.
Additional spot checks covered overlapping byte-register halves, both overwrite orders, conditional writes, memory base/index reads, XOR/SUB self-zeroing, forwarded calls, and the generalised Game Boy byte/pair register handling.
Results matched the PR's intended behaviour.
One tiny observation: after a default variable has already been reconciled to a prototype, changing that prototype again does not overwrite the now non-default variable.
That is consistent with the user-edit preservation rule, but may be worth documenting or handling explicitly if repeated prototype replacement is intended.
Excellent work extending the solution beyond the original x86-16 case to the small-register analysis shared with 8-bit targets!
Thank you!
trufae commentedon Sep 21, 2026
Beautiful. Thanks for confirming