-
Notifications
You must be signed in to change notification settings - Fork 702
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
wasm2c in freestanding environment #2460
Comments
Seems like a worthwhile effort. Sounds like we could start by making the inclusion of Is there some way to test that we can build in a freestanding environment? i.e. is there some way we can setup such an environment in our CI when we test? I have to say I'm surprised I didn't know that "freestanding environment" was a thing that was defined by the C standard.. and I've been writing C code for almost 30 years :) |
Indeed.
I'd like to but the nature of the project (assembly, interpreters etc) will unfortunately make it very difficult to obtain legal clearance, but I'm more than happy to test and provide feedback.
gcc and clang have a
So as a compile time check, it can be made to work with empty dummy implem of all libc functions relied on. But anything more than compile time is going to be difficult.
TBH there is little use for it unless you work on embedded things, and even then you only care if you try to setup the build system. After all, C was made to write kernels in the first place so it makes sense the spec is not fully assuming a hosted environment. |
Opening this issue as a narrowed-down version of #1949 to track freestanding-related questions.
I didn't end up using wasm2c in the original use case mentioned there for reasons completely unrelated to wasm, but I very recently considered using it for another task, again in the same environment (kernel out of tree driver, basically identical to embedded development context).
The only remaining issue seems to be:
wasm_trunc()
.Point 1. is relatively easy to deal with by providing custom trapping implementations of the libc functions they rely on, but it would be nice for embedded use case to simply fail to compile floating point opcodes, rather than emitting a call to something.
Headers of point 2. can be removed by editing the C file after generation or providing them with an empty content, but it would be nicer to allow direct customization of the content. As it stands, it's stored in
./src/template/wasm2c.includes.c
which then becomes part of the wasm2c binary itself.In terms of how they are used, it looks like:
wasm_trunc()
)So overall it's looking pretty good.
[1] A C freestanding environment is allowed to only distribute the following headers, which does not contain e.g. math.h: <float.h>, <iso646.h>, <limits.h>, <stdalign.h>, <stdarg.h>, <stdbool.h>, <stddef.h>, <stdint.h>, and <stdnoreturn.h>
https://port70.net/~nsz/c/c11/n1570.html#4p6
The kernel does not even have float.h AFAICT.
The text was updated successfully, but these errors were encountered: