Add calling convention options for output #119
Merged
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.
Rust allows specifying different ABI calling conventions on extern functions. The default is
"C"which translates to the compiler's default (almost alwayscdecl), but valid values likethiscallandfastcallexist, as well as some platform-specific options and the special"system"option. It's special in that its allowed everywhere, and almost always translates to"C"with the exception of 32-bit Windows binaries, where it defaults tostdcall.Considering the still rather large portion of Windows code and programs stuck to using 32-bit binaries there's sometimes reasons to prefer the system's default over the compiler's. For example when calling into system libraries or using ancient 32-bit DLLs.
MS Learn on native interop and calling conventions explicitly outlines the differences on Win32
Defaulting to
Stdcallwould not be an option however, as this would break any Rust code not usingextern "system"for the ABI specification (e.g. code usingCexplicitly on 32-bit). Using the special-cased WinApi also wouldn't work for the same reason.This PR also adds support for explicit use of
stdcall,thiscall¹,win64²,cdecl,sysv64³, andaapcs⁴ extern ABIs. It also causes build failures onRust,fastcall, andefiapi.It does not add any tests, as it'd require adding workflow runs for every allowed combination of targets and ABIs, as well as some tests to verify (implicit) disallows abort correctly.
If tests are to be added, some of them will need to be limited to specific targets to prevent compiler errors (e.g. using
thiscallon AMD64 is disallowed by rustc).It also does not consider
vectorcall. The previously linked page (and further links from there) do not mention vectorcall, and they do mention fastcall (which vectorcall is based on) is not supported in .NET.¹:
thiscallis only allowed on x86 by the compiler, as it's the 32-bit MSVC member function convention.²: only allowed on x86_64 Windows
³: not allowed on windows
⁴: A warning is emitted and the special value
WinApiis used to go with the system default as ARM is a rather special beast to deal with