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.
This commit is contained in:
Alex Crichton 2024-05-07 13:23:46 -07:00
parent 400e75494a
commit 38b2bd782b

View File

@ -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 {