diff --git a/compiler/rustc_target/src/spec/targets/wasm32_wasip2.rs b/compiler/rustc_target/src/spec/targets/wasm32_wasip2.rs index a4346cd5a8722..1259969ac3655 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,6 +54,11 @@ 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-wasip2".into(), metadata: crate::spec::TargetMetadata {