diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 1f691d14c53..6939674ce9d 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -3127,7 +3127,13 @@ fn add_lld_args( // 2. Implement the "linker flavor" part of this feature by asking `cc` to use some kind of // `lld` as the linker. - cmd.arg("-fuse-ld=lld"); + // + // Note that wasm targets skip this step since the only option there anyway + // is to use LLD but the `wasm32-wasip2` target relies on a wrapper around + // this, `wasm-component-ld`, which is overridden if this option is passed. + if !sess.target.is_like_wasm { + cmd.arg("-fuse-ld=lld"); + } if !flavor.is_gnu() { // Tell clang to use a non-default LLD flavor. diff --git a/compiler/rustc_target/src/spec/targets/wasm32_wasip2.rs b/compiler/rustc_target/src/spec/targets/wasm32_wasip2.rs index 5ff3f07daae..1259969ac36 100644 --- a/compiler/rustc_target/src/spec/targets/wasm32_wasip2.rs +++ b/compiler/rustc_target/src/spec/targets/wasm32_wasip2.rs @@ -18,7 +18,7 @@ use crate::spec::crt_objects; use crate::spec::LinkSelfContainedDefault; -use crate::spec::{base, Target}; +use crate::spec::{base, RelocModel, Target}; pub fn target() -> Target { let mut options = base::wasm::options(); @@ -54,8 +54,13 @@ pub fn target() -> Target { // signatures. options.entry_name = "__main_void".into(); + // Default to PIC unlike base wasm. This makes precompiled objects such as + // the standard library more suitable to be used with shared libaries a la + // emscripten's dynamic linking convention. + options.relocation_model = RelocModel::Pic; + Target { - llvm_target: "wasm32-unknown-unknown".into(), + llvm_target: "wasm32-wasip2".into(), metadata: crate::spec::TargetMetadata { description: None, tier: None,