rustc: Stop passing --allow-undefined on wasm targets by alexcrichton · Pull Request #149868 · rust-lang/rust (original) (raw)
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})
This commit updates how the linker is invoked on WebAssembly targets
(all of them) to avoid passing the --allow-undefined flag to the
linker. Historically, if I remember this correctly, when wasm-ld was
first integrated this was practically required because at the time it
was otherwise impossible to import a function from the host into a wasm
binary. Or, at least, I'm pretty sure that was why this was added.
At the time, as the documentation around this option indicates, it was known that this was going to be a hazard. This doesn't match behavior on native, for example, and can easily paper over what should be a linker error with some sort of other obscure runtime error. An example is that this program currently compiles and links, it just prints null:
unsafe extern "C" {
static nonexistent: u8;
}
fn main() {
println!("{:?}", &raw const nonexistent);
}This can easily lead to mistakes like rust-lang/libc/4880 and defer what
should be a compile-time link error to weird or unusual behavior at link
time. Additionally, in the intervening time since wasm-ld was first
introduced here, lots has changed and notably this program works as
expected:
#[link(wasm_import_module = "host")]
unsafe extern "C" {
fn foo();
}
fn main() {
unsafe {
foo();
}
}Notably this continues to compile without error and the final wasm binary indeed has an imported function from the host. What this change means, however, is that this program:
unsafe extern "C" {
fn foo();
}
fn main() {
unsafe {
foo();
}
}this currently compiles successfully and emits an import from the env
module. After this change, however, this will fail to compile with a
link error stating that the foo symbol is not defined.
rustbot added A-run-make
Area: port run-make Makefiles to rmake.rs
Status: Awaiting review from the assignee but also interested parties.
Relevant to the compiler team, which will review and decide on the PR/issue.
labels
rust-bors bot added a commit that referenced this pull request
rustc: Stop passing --allow-undefined on wasm targets
try-job: dist-x86_64-linux try-job: dist-various-*