Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Windows support for the single-pass backend. #347

Closed
losfair opened this issue Apr 12, 2019 · 6 comments
Closed

Add Windows support for the single-pass backend. #347

losfair opened this issue Apr 12, 2019 · 6 comments
Labels
🎉 enhancement New feature! ℹ️ help wanted Extra attention is needed 📦 lib-compiler-singlepass About wasmer-compiler-singlepass project-spacemesh
Milestone

Comments

@losfair
Copy link
Contributor

losfair commented Apr 12, 2019

Currently the single-pass backend assumes a System V calling convention, but Windows has its own one instead of System V.

It shouldn't be hard to support Windows' calling convention on x64. The following changes need to be made:

  1. In machine.rs:

    • Add a Windows version of get_param_location that defines where function arguments should be located.
    • Add Windows definitions for REGS in pick_gpr and pick_temp_gpr.
    • Remove the use of XMM6 and XMM7 in pick_xmm (since Windows requires them to be preserved, while we cannot decide whether this needs to be done in a single pass).
  2. In codegen_x64.rs:

    • Add a Windows version of CONSTRUCT_STACK_AND_CALL_WASM.
    • Rename emit_call_sysv to emit_call.
    • Allocate 32 bytes of "shadow space" before executing call in emit_call.

EDIT: Windows support is more complex to implement than I thought before because the Windows x64 ABI does not guarantee a 128-byte red zone, which the code generator currently uses everywhere. Fixed

@losfair losfair added 🎉 enhancement New feature! ℹ️ help wanted Extra attention is needed 📦 lib-compiler-singlepass About wasmer-compiler-singlepass labels Apr 12, 2019
@CryZe
Copy link
Contributor

CryZe commented Oct 31, 2019

What's the status of this? I'm at least partially blocked by this. (With enough mentoring I could maybe do this, but I already looked at this a while ago and it seems like there's one huge asm block (for setup or something, I don't remember), where I did have absolutely no clue how that would need to be modified for Windows compatibility).

@syrusakbary
Copy link
Member

@CryZe we will be super happy to mentor 🙂

@losfair can you provide some assistance on what would be needed to be modified on the asm block to support Windows, so we can unblock this issue?

@losfair
Copy link
Contributor Author

losfair commented Nov 4, 2019

@CryZe

Thanks for your interest in helping with this issue!

For the CONSTRUCT_STACK_AND_CALL_WASM ASM block, what it does is basically loading the 8-byte arguments from stack_top to stack_base (the names are a bit misleading though) into the corresponding calling convention argument locations (either register or stack), ensuring ABI constraints (on x86_64 Linux for example it is to ensure the stack is 16-byte aligned), and then calling the provided compiled WebAssembly function with a Ctx as the first parameter.

To support windows, what needs to be done is to figure out where each argument should be placed before a function call and what extra ABI constraints need to be satisfied. So instead of mov-ing arguments to rdi, rsi, rdx, rcx, r8, r9 and then to the stack in order, the locations defined by the Windows ABI (https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention?view=vs-2019) must be used. And also, the 32-byte shadow space needs to be allocated.

@repi
Copy link
Contributor

repi commented Jul 3, 2020

Any updates for this? Would be nice to have it available on Windows

@syrusakbary
Copy link
Member

Our work in the refactor will make this much easier to happen

@syrusakbary
Copy link
Member

We have done this in #2574. Closing the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎉 enhancement New feature! ℹ️ help wanted Extra attention is needed 📦 lib-compiler-singlepass About wasmer-compiler-singlepass project-spacemesh
Projects
None yet
Development

No branches or pull requests

5 participants