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

What about the calling convention? #8

Open
bjorn3 opened this issue Oct 28, 2020 · 2 comments
Open

What about the calling convention? #8

bjorn3 opened this issue Oct 28, 2020 · 2 comments

Comments

@bjorn3
Copy link

bjorn3 commented Oct 28, 2020

They are a mess and are highly architecture specific. In addition many parts of the calling convention can only be implemented as part of the actual codegen backend like LLVM. This includes register assignment. The Rust ABI builds on top of the native C calling convention, but only uses part of it's functionality. For example #[repr(C)] struct A(u32, u32) would be passed in a single register for the x86_64 System-V call conv, while Rust passes it in memory as pointer. If there is no #[repr(C)] it uses two registers. #[repr(C)] struct BigType([u8; 1024]) would be stored at a fixed stack offset for the x86_64 System-V call conv, while Rust passes a pointer to wherever it exists. Then there are special rules for mixing integers and floating points in a single struct. And another thing is that Rust currently forces vector types to be passed in memory in certain conditions as a workaround for bugs when mixing functions without simd enabled and with simd enabled.

@robinmoussu
Copy link

Just to add some oil on the fire:

rust-lang/rust-bindgen#778

MakeFoo and MakeBar look very similar, however in C++ they use different ABIs, at least on Linux.
Here's a quote from System V AMD64 ABI spec (page 20):

If a C++ object has either a non-trivial copy constructor or a non-trivial
destructor, it is passed by invisible reference (the object is replaced in the
parameter list by a pointer that has class POINTER)

@FranchuFranchu
Copy link

What about platforms where multiple return values are part of the "standard" ABI, like RISC-V's a0-a7 registers? When returning a tuple of <8 elements, do we push them to the stack or do we place each element in a different register?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants