WebAssembly / tool-conventions

Conventions supporting interoperatibility between tools working with WebAssembly.
Artistic License 2.0
298 stars 65 forks source link

Document function signatures in C ABI #161

Closed tlively closed 3 years ago

tlively commented 3 years ago

Fixes #160.

tlively commented 3 years ago

@RReverser I made it a table, ptal.

sunfishcode commented 3 years ago

Would it make sense to mention the upcoming multivalue ABI here, so that people building tools that know about C ABIs are aware that this change is coming?

RReverser commented 3 years ago

the upcoming multivalue ABI here, so that people building tools that know about C ABIs are aware that this change is coming?

I suspect multivalue ABI will be an additional ABI, rather than a replacement for the current one? (we'll still need this one for compatibility with older browsers / engines)

sunfishcode commented 3 years ago

Multivalue is standardized and widely supported now, so I'm hoping multivalue will become the default, even if we also retain the pre-multivalue ABI for compatibility.

RReverser commented 3 years ago

Multivalue is standardized and widely supported now, so I'm hoping multivalue will become the default, even if we also retain the pre-multivalue ABI for compatibility.

Right, that's my point - we'll still retain this ABI for compatibility.

Given that it already has "As mentioned in README, it's not the only possible C ABI. It is the ABI that the clang/LLVM WebAssembly backend is currently using, [...]" in the disclaimer, that seems sufficient and we can reword once we create a doc for multivalue C ABI.

dschuff commented 3 years ago

This section should probably also mention varargs. They work similarly (https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp#L950) to byval: the caller assigns each argument an offset according to its alignment and size, creates a buffer in its stack frame (at compile time), and then at runtime copies each argument into its place and passes a pointer to the buffer (as the last argument).

RReverser commented 3 years ago

@dschuff Good idea, yeah. So, if I understand correctly, varargs are laid out as if they were fields in an extra struct passed to the function?

tlively commented 3 years ago

How does that extra detail look, @RReverser?

RReverser commented 3 years ago

How does that extra detail look, @RReverser?

LGTM. I, obviously, can't speak for its correctness / completeness, especially in light of me being confused by the 3 * sizeof(varargs) allocation that Clang seems to be doing, but if you think this description is sufficiently correct, I'm happy to go with it.

RReverser commented 3 years ago

@tlively Thanks for documenting this!