Skip to content

Commit 38b2bd7

Browse files
committed
rustc: Change wasm32-wasip2 to PIC-by-default
This commit changes the new `wasm32-wasip2` target to being PIC by default rather than the previous non-PIC by default. This change is intended to make it easier for the standard library to be used in a shared object in its precompiled form. This comes with a hypothetical modest slowdown but it's expected that this is quite minor in most use cases or otherwise wasm compilers and/or optimizing runtimes can elide the cost.
1 parent 400e754 commit 38b2bd7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

compiler/rustc_target/src/spec/targets/wasm32_wasip2.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
1919
use crate::spec::crt_objects;
2020
use crate::spec::LinkSelfContainedDefault;
21-
use crate::spec::{base, Target};
21+
use crate::spec::{base, RelocModel, Target};
2222

2323
pub fn target() -> Target {
2424
let mut options = base::wasm::options();
@@ -54,6 +54,11 @@ pub fn target() -> Target {
5454
// signatures.
5555
options.entry_name = "__main_void".into();
5656

57+
// Default to PIC unlike base wasm. This makes precompiled objects such as
58+
// the standard library more suitable to be used with shared libaries a la
59+
// emscripten's dynamic linking convention.
60+
options.relocation_model = RelocModel::Pic;
61+
5762
Target {
5863
llvm_target: "wasm32-wasip2".into(),
5964
metadata: crate::spec::TargetMetadata {

0 commit comments

Comments
 (0)