Skip to content

Commit f667aca

Browse files
committed
Tweak wasm_base target spec to indicate linker is not GNU and update linker inferring logic for wasm-ld.
1 parent 625d5a6 commit f667aca

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,8 @@ fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
10051005
|| stem.ends_with("-clang")
10061006
{
10071007
LinkerFlavor::Gcc
1008+
} else if stem == "wasm-ld" || stem.ends_with("-wasm-ld") {
1009+
LinkerFlavor::Lld(LldFlavor::Wasm)
10081010
} else if stem == "ld" || stem == "ld.lld" || stem.ends_with("-ld") {
10091011
LinkerFlavor::Ld
10101012
} else if stem == "link" || stem == "lld-link" {

compiler/rustc_codegen_ssa/src/back/linker.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -472,21 +472,23 @@ impl<'a> Linker for GccLinker<'a> {
472472
// eliminate the metadata. If we're building an executable, however,
473473
// --gc-sections drops the size of hello world from 1.8MB to 597K, a 67%
474474
// reduction.
475-
} else if self.sess.target.linker_is_gnu && !keep_metadata {
475+
} else if (self.sess.target.linker_is_gnu || self.sess.target.is_like_wasm)
476+
&& !keep_metadata
477+
{
476478
self.linker_arg("--gc-sections");
477479
}
478480
}
479481

480482
fn no_gc_sections(&mut self) {
481483
if self.sess.target.is_like_osx {
482484
self.linker_arg("-no_dead_strip");
483-
} else if self.sess.target.linker_is_gnu {
485+
} else if self.sess.target.linker_is_gnu || self.sess.target.is_like_wasm {
484486
self.linker_arg("--no-gc-sections");
485487
}
486488
}
487489

488490
fn optimize(&mut self) {
489-
if !self.sess.target.linker_is_gnu {
491+
if !self.sess.target.linker_is_gnu && !self.sess.target.is_like_wasm {
490492
return;
491493
}
492494

compiler/rustc_target/src/spec/wasm_base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ pub fn options() -> TargetOptions {
102102
// we use the LLD shipped with the Rust toolchain by default
103103
linker: Some("rust-lld".to_owned()),
104104
lld_flavor: LldFlavor::Wasm,
105+
linker_is_gnu: false,
105106

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

0 commit comments

Comments
 (0)