Rust's WebAssembly targets are soon going to experience a change which has a
risk of breaking existing projects, and this post is intended to notify users of
this upcoming change, explain what it is, and how to handle it. Specifically, all
WebAssembly targets in Rust have been linked using the --allow-undefined flag
to wasm-ld, and this flag is being removed.
What's wrong with --allow-undefined?
By passing --allow-undefined on all WebAssembly targets, rustc is introducing
diverging behavior between other platforms and WebAssembly. The main risk of
--allow-undefined is that misconfiguration or mistakes in building can
result in broken WebAssembly modules being produced, as opposed to compilation
errors. This means that the proverbial can is kicked down the road and lengthens
the distance from where the problem is discovered to where it was introduced.
Some example problematic situations are:
If
mylibrary_initwas typo'd asmylibraryinitthen the final binary would
import themylibraryinitsymbol instead of calling the linked
mylibrary_initC symbol.
If
mylibrarywas mistakenly not compiled and linked into a final
application then themylibrary_initsymbol would end up imported rather than
producing a linker error saying it's undefined.
If external tooling is used to process a WebAssembly module, such as
wasm-bindgenorwasm-tools component new, these tools don't know what to do with"env"imports by default and they are likely to provide an error message of some form that isn't clearly connected back to the original source code and where the symbols was imported from.
For web users if you've ever seen an error along the lines of
Uncaught TypeError: Failed to resolve module specifier "env". Relative references must start with either "/", "./", or "../".this can mean that"env"leaked into the final module unexpectedly and the true error is the undefined symbol error, not the lack of"env"items provided.
All native platforms consider undefined symbols to be an error by default, and
thus by passing --allow-undefined rustc is introducing surprising behavior on
WebAssembly targets. The goal of the change is to remove this surprise and
behave more like native platforms.
When is this change being made?
Removing --allow-undefined on wasm targets is being done in
.
SOCIAL SHARE CARD GENERATOR