Skip to content

Commit e3029d2

Browse files
committed
Auto merge of #124858 - alexcrichton:some-wasi-changes, r=michaelwoerister
rustc: Some small changes for the wasm32-wasip2 target This commit has a few changes for the wasm32-wasip2 target. The first two are aimed at improving the compatibility of using `clang` as an external linker driver on this target. The default target to LLVM is updated to match the Rust target and additionally the `-fuse-ld=lld` argument is dropped since that otherwise interferes with clang's own linker detection. The only linker on wasm targets is LLD but on the wasip2 target a wrapper around LLD, `wasm-component-ld`, is used to drive the process and perform steps necessary for componentization. The final commit changes the output of all objects on the wasip2 target to being PIC by default. This improves compatibilty with shared libaries but notably does not mean that there's a turnkey solution for shared libraries. The hope is that by having the standard libray work both with and without dynamic libraries will make experimentation easier.
2 parents 1fef152 + 38b2bd7 commit e3029d2

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -3127,7 +3127,13 @@ fn add_lld_args(
31273127

31283128
// 2. Implement the "linker flavor" part of this feature by asking `cc` to use some kind of
31293129
// `lld` as the linker.
3130-
cmd.arg("-fuse-ld=lld");
3130+
//
3131+
// Note that wasm targets skip this step since the only option there anyway
3132+
// is to use LLD but the `wasm32-wasip2` target relies on a wrapper around
3133+
// this, `wasm-component-ld`, which is overridden if this option is passed.
3134+
if !sess.target.is_like_wasm {
3135+
cmd.arg("-fuse-ld=lld");
3136+
}
31313137

31323138
if !flavor.is_gnu() {
31333139
// Tell clang to use a non-default LLD flavor.

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

+7-2
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,8 +54,13 @@ 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 {
58-
llvm_target: "wasm32-unknown-unknown".into(),
63+
llvm_target: "wasm32-wasip2".into(),
5964
metadata: crate::spec::TargetMetadata {
6065
description: None,
6166
tier: None,

0 commit comments

Comments
 (0)