Stream: cranelift

Topic: Windows & JITs & ABIs, Oh My


view this post on Zulip Adam Wick (Sep 19 2023 at 04:06):

Hello!

I'm wondering if anyone has gotten the Cranelift JIT backend working in Windows, and if there was anything special you had to do beyond a std::mem::transmute of the resulting bytes into a function and then calling it. At the moment, I'm running into a problem that smells like an ABI mismatch somewhere, where it could just be that there's some flag I need to pass to Cranelift to put it in some mode, or there may be some way I need to define the function in Rust to make the jump clean.

But, the meat of it is: I get a crash well after exiting my JITed code, because some Rust library is doing a write through RSI, and RSI has been clobbered by the Cranelift-generated code. Looking at ABI docs, RSI is used for an argument register in Linux, but looks like it's defined as callee-saved on Windows (reference). I don't see any generated code to save the register, which is what's making me wonder if there's an ABI mismatch, or possibly a bug in the definition of the register save semantics in Cranelift for Windows.

Any pointers?

-Adam

Learn more about: x64 ABI conventions

view this post on Zulip bjorn3 (Sep 19 2023 at 08:20):

Which call conv do you use for the cranelift jitted function?

view this post on Zulip Chris Fallin (Sep 19 2023 at 16:40):

We correctly denote RSI as callee-saved in Fastcall, so I suspect the issue is that the CLIF body you're generating is marked as SysV or some other convention?

view this post on Zulip Adam Wick (Sep 20 2023 at 03:28):

Chris Fallin said:

We correctly denote RSI as callee-saved in Fastcall, so I suspect the issue is that the CLIF body you're generating is marked as SysV or some other convention?

Ah-hah! You are correct. Thank you for reminding me of the search term; there was a stray, hard-coded CallConv::SystemV in my code.


Last updated: Oct 23 2024 at 20:03 UTC