callconv(.Fastcall) broken on i386-windows #10363
Labels
arch-x86
32-bit x86
backend-llvm
The LLVM backend outputs an LLVM IR Module.
bug
Observed behavior contradicts documented or intended behavior
os-windows
Milestone
Zig Version
0.9.0-dev.1945+efdb94486
Steps to Reproduce
test.zig:
test.c:
Build with:
zig build-exe --strip -OReleaseSmall -target i386-windows test.zig test.c
(stripped and made small because IDA Pro likes to crash when loading a PDB generated by zig)Expected Behavior
This should produce test.exe which prints "56, 1337" when ran.
Actual Behavior
This will not link:
zig will correctly mangle call_zig's name with a leading @ to mean fastcall, but it miscalculates the number of (stack) bytes needed for arguments, as the first argument should be present in the ecx register and not in a stack location. It seems to be handling arguments as if it were stdcall but still doing name mangling for fastcall.
Removing
__fastcall
andcallconv(.Fastcall)
from call_zig will link but yield an incorrect (undefined) output (ex. 0, 0) becausefastcall()
will read the argumentsecx
andedx
from stack locations--call_zig()
in test.c will instead correctly pass them in their corresponding registers, ecx and edx.When not used in a situation where link errors are involved - I ran into this while using MS Detours - it either causes something to crash because it pops too many arg bytes off the stack or it just behaves incorrectly. Conveniently for me it turned out the C code being replaced only used __fastcall to emulate __thiscall, which works correctly with callconv(.Thiscall).
The text was updated successfully, but these errors were encountered: