[WIP] Add support for Windows x32 ABI #1742
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As it stands the patch in this PR is as minimal as it is hair-raising, and it's really not going to be merged in the current state. However, with it and #1740 I can actually run simple programs on x32!
(The
-Cpanic=abort
, plus a dummy#[no_mangle] pub extern fn _Unwind_Resume() { unimplemented!() }
, are there to work around the fact that Linux distributions all build MinGW with SjLj exceptions, but Rust expects a MinGW toolchain with DWARF exceptions.)Let me explain the reasons this PR looks like it does.
First, currently target-lexicon considers Windows as always using
fastcall
. However that's not the case on x32, where C code usescdecl
by default, and Win32 APIs usestdcall
by default. This is why Windows x32 is special-cased in cranelift in this PR. To fix this, I believe thatdefault_calling_convention
for Windows x32 should returncdecl
so that it matches the behavior of the Rustc
calling convention, but that's where we get to the second issue...Second, there is actually no way to express "Windows
cdecl
" in either target-lexicon or cranelift. AFAICT this calling convention is functionally identical to the System V one; LLVM calls itccc
to avoid naming it in either a *nix-specific way ("System V") or a Windows-specific way ("cdecl
"). The way this should be handled is purely subjective though (the options being "rename SystemV to Ccc", "rename SystemV to Cdecl", "add Cdecl as an alias of SystemV for Windows alone", and "do nothing and just use SystemV on Windows x32") so I'm going to implement whatever the maintainers ask me to.