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

Function arguments when returning a struct #2726

Closed
willygroup opened this issue Mar 14, 2021 · 3 comments
Closed

Function arguments when returning a struct #2726

willygroup opened this issue Mar 14, 2021 · 3 comments

Comments

@willygroup
Copy link

Hi,
I'm pretty new to the whole rust/wasm world.
I'm passing to rust host from rust wasm function that returns a simple struct.
I'm compiling with cargo and the target wasm32-unknown-unknown.
I saw that when I check the module exports this function get an extra arguments... making some guessing I find out that is the memory pointer for the return struct...

I cannot find out some documentation for this behaviour... someone can please address me to the right direction?
Thanks a lot ☺

@bjorn3
Copy link
Contributor

bjorn3 commented Mar 14, 2021

making some guessing I find out that is the memory pointer for the return struct...

Correct

I cannot find out some documentation for this behaviour... someone can please address me to the right direction?

Apart from reading the source of rustc and LLVM there isn't really for wasm32-unknown-unknown. Probably the best description is rust-lang/rust#81388 (comment). For wasm32-unknown-emscripten and wasm32-wasi, the official C abi for wasm is followed, but for wasm32-unknown-unknown this is not the case. By accident LLVM was allowed to do it's own abi adjustments and now it can't be changed anymore without breaking wasm-bindgen. (source: I broke it by accident a while ago by doing something that prevented LLVM from doing it's own abi adjustments.)

@alexcrichton
Copy link
Member

The C ABI for the wasm32 target is currently documented at https://github.com/WebAssembly/tool-conventions/blob/master/BasicCABI.md, although the Rust ABI for wasm32-unknown-unknown differs from Clang for historical reasons. Using the wasm32-wasi target, however, the ABIs will be the same.

@willygroup
Copy link
Author

Ok!
Thanks a lot for your work!! :-)

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