-
Notifications
You must be signed in to change notification settings - Fork 256
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
Compute layout of datatypes according to C ABI #181
Conversation
Dan pointed out the following spec exists to describe the C ABI: https://github.com/WebAssembly/tool-conventions/blob/master/BasicCABI.md#data-representation I would still like to somehow test that the layout calculations match what llvm does. I tested the version of this algorithm that lived in lucet-idl against clang by randomly generating specs and rendering them to C, and adding static assertions about layout. That is probably too heavy-weight for this repo, because it would add a lot of testing deps, so I'll generate some weird types elsewhere and check in a small sample of tests that assert these calculations match how llvm lays them out. |
Struct layout should be fine, but be aware that for calling conventions Rust only uses the official documented C ABI with its Emscripten targets and not with its WASI or wasm32-unknown-unknown targets. See WebAssembly/tool-conventions#88 for more information. |
That incompatibility is only for the call ABI, not the memory ABI. |
Can this be used to re-instate the We used to have stuff like this that we no longer have:
|
@sbc100 I actually hadn't thought to do that, but its a great idea. I'll add those assertions to the wasi-libc code generator as part of my work to show that this code is actually correct. |
I went and added those assertions back to wasi-libc and fixed bugs in the process. Still working on adding some local tests to this repo that check whether the calculations are correct. |
I added static assertions to the wasi-libc code generator to check if these calculations align with LLVM (WebAssembly/wasi-libc#149), and created a randomized witx spec generator to search for cases that the current wasi spec doesn't cover (https://github.com/pchickey/witx-test), and check those using the wasi-libc generator. That randomized search found a bug I had accidentally left in union size calculation (fixed in 3857728), and has increased my confidence that this code is correct. I think we should try to move that sort of testing into this repo and run it as part of CI, but that is a bigger step than just adding this layout code and having some external evidence of its correctness. If that is enough for the rest of y'all, lets review and merge this PR as is. I think the I also think that, if we're going to move wasi-libc into the WebAssembly github org, that perhaps we should also move its However, I don't want to make either of those questions part of this PR. So, I propose we merge this PR and then discuss those questions afterwards. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plan sounds good; let's discuss those other steps separately. This is a really cool development!
Based on #164
This is useful for validating pointers, enums, and flags in host code.