Skip to content

Commit

Permalink
Tweak wasm_base target spec to indicate linker is not GNU and update …
Browse files Browse the repository at this point in the history
…linker inferring logic for wasm-ld.
  • Loading branch information
luqmana committed Jun 2, 2021
1 parent 625d5a6 commit f667aca
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Expand Up @@ -1005,6 +1005,8 @@ fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
|| stem.ends_with("-clang")
{
LinkerFlavor::Gcc
} else if stem == "wasm-ld" || stem.ends_with("-wasm-ld") {
LinkerFlavor::Lld(LldFlavor::Wasm)
} else if stem == "ld" || stem == "ld.lld" || stem.ends_with("-ld") {
LinkerFlavor::Ld
} else if stem == "link" || stem == "lld-link" {
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_codegen_ssa/src/back/linker.rs
Expand Up @@ -472,21 +472,23 @@ impl<'a> Linker for GccLinker<'a> {
// eliminate the metadata. If we're building an executable, however,
// --gc-sections drops the size of hello world from 1.8MB to 597K, a 67%
// reduction.
} else if self.sess.target.linker_is_gnu && !keep_metadata {
} else if (self.sess.target.linker_is_gnu || self.sess.target.is_like_wasm)
&& !keep_metadata
{
self.linker_arg("--gc-sections");
}
}

fn no_gc_sections(&mut self) {
if self.sess.target.is_like_osx {
self.linker_arg("-no_dead_strip");
} else if self.sess.target.linker_is_gnu {
} else if self.sess.target.linker_is_gnu || self.sess.target.is_like_wasm {
self.linker_arg("--no-gc-sections");
}
}

fn optimize(&mut self) {
if !self.sess.target.linker_is_gnu {
if !self.sess.target.linker_is_gnu && !self.sess.target.is_like_wasm {
return;
}

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/wasm_base.rs
Expand Up @@ -102,6 +102,7 @@ pub fn options() -> TargetOptions {
// we use the LLD shipped with the Rust toolchain by default
linker: Some("rust-lld".to_owned()),
lld_flavor: LldFlavor::Wasm,
linker_is_gnu: false,

// No need for indirection here, simd types can always be passed by
// value as the whole module either has simd or not, which is different
Expand Down

0 comments on commit f667aca

Please sign in to comment.