Skip to content

Commit

Permalink
Auto merge of #124858 - alexcrichton:some-wasi-changes, r=michaelwoer…
Browse files Browse the repository at this point in the history
…ister

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.
  • Loading branch information
bors committed May 8, 2024
2 parents 1fef152 + 38b2bd7 commit e3029d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 7 additions & 1 deletion compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 7 additions & 2 deletions compiler/rustc_target/src/spec/targets/wasm32_wasip2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit e3029d2

Please sign in to comment.