-
Notifications
You must be signed in to change notification settings - Fork 59
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
Support for emitting custom sections #30
Comments
I doubt that LLVM can emit custom sections. Maybe @sunfishcode knows better. |
It can't currently. It would be possible to add ways to do it. Another option would be to have rustc just append custom sections to the output wasm files itself after LLVM is done. |
Ah, I completly forgot about it is so easy to just slap a section to a wasm file. I actually like this approach! |
Sounds good! |
There's a patch for this in review upstream: https://reviews.llvm.org/D43097 |
While we wait for support in LLVM/LLD (it'd take us awhile to update LLVM as well) I've opened rust-lang/rust#48883 to implement this |
This is now in nightly! |
can rust code "read" the custom section in which the wasm file build by itself? @koute |
There should be a way to emit custom wasm sections from inside Rust code.
There are many potential uses for custom sections. For example, currently the the
js!
macro instdweb
takes JavaScript code, stringifies it, and assigns it to a normal constant. Thencargo-web
scans the.wasm
file, extracts those JavaScript snippets, and deletes the (now useless) corresponding data section entries.Ideally instead of mucking around with the data section (which often creates holes in memory at runtime since you can't really move the entries' offsets around, and is harder to process) it'd just read a custom section which
stdweb
would emit for it, and then easily nuke it afterwards.One potential way we could support custom sections would be like this: have a built-in macro, say,
append_to_custom_section!
, which would take two arguments: (1) a string with the name of the section, (2) a blob of bytes it would append to that section. It would also be a purely compile-time construct and would expand into nothing after macro expansion.For example this Rust code:
would result in a custom wasm section with the name
js-snippets
containing\x12\x00\x00\x00console.log('...')\x0c\x00\x00\x00alert('...')
. The blobs of bytes would be concatenated in the order of their appearance within one.rs
file, and with an unspecified order between different.rs
files.This would allow a procedural macro to put arbitrary information in a custom section of its choice, which then could be easily consumed by external tools.
The text was updated successfully, but these errors were encountered: