-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
How to call functions where args must be passed at the stack #1108
Comments
what is |
Yes I think it should be And I think the problem is if you call an external C function which receives a large struct by value the calling function will pass the struct by pushing it on the stack directly before calling the function (e.g. it will not explicitly put a pointer to the data into a register or so no it will just push it on the stack). int take_a(S s) {
return s.a;
} will compile to (without frame pointers): mov rax, QWORD PTR [rsp+8]
ret So it's important to control whats on the stack before calling the function (e.g. spilling some values would ruin it) |
Yeah, with sysv you can't transparently explode a struct into its members and pass those. There is a grouping going on: either all the members fit in registers, or the whole struct is passed on the stack. There is no partial situation where some members are passed in registers and some are passed on the stack. Cranelift isn't equipped to reason about this, since it doesn't have any concept of structs. So for now at least, the ir producer would have to take on the responsibility of a bunch of ABI / calling convention concerns and do a funky legalization pass before even giving cranelift any ir. The division of responsibilities here is pretty murky... |
So how do I actually pass something on the stack? |
Using |
That is not what the System-V abi requires. SysV requires you to put the values at specific stack offsets. The callee then loads the args from those offsets, not from a pointer passed in a register. |
For example:
When calling
take_a
the argument must be put in the input argument area of the stack.cc https://github.com/bjorn3/rustc_codegen_cranelift/issues/10#issuecomment-523136265
The text was updated successfully, but these errors were encountered: