Skip to content

Commit b6f580a

Browse files
committed
Auto merge of #90382 - alexcrichton:wasm64-libstd, r=joshtriplett
std: Get the standard library compiling for wasm64 This commit goes through and updates various `#[cfg]` as appropriate to get the wasm64-unknown-unknown target behaving similarly to the wasm32-unknown-unknown target. Most of this is just updating various conditions for `target_arch = "wasm32"` to also account for `target_arch = "wasm64"` where appropriate. This commit also lists `wasm64` as an allow-listed architecture to not have the `restricted_std` feature enabled, enabling experimentation with `-Z build-std` externally. The main goal of this commit is to enable playing around with `wasm64-unknown-unknown` externally via `-Z build-std` in a way that's similar to the `wasm32-unknown-unknown` target. These targets are effectively the same and only differ in their pointer size, but wasm64 is much newer and has much less ecosystem/library support so it'll still take time to get wasm64 fully-fledged.
2 parents 6414e0b + af217f7 commit b6f580a

File tree

31 files changed

+183
-60
lines changed

31 files changed

+183
-60
lines changed

Cargo.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -678,9 +678,9 @@ dependencies = [
678678

679679
[[package]]
680680
name = "compiler_builtins"
681-
version = "0.1.49"
681+
version = "0.1.52"
682682
source = "registry+https://github.com/rust-lang/crates.io-index"
683-
checksum = "20b1438ef42c655665a8ab2c1c6d605a305f031d38d9be689ddfef41a20f3aa2"
683+
checksum = "b6591c2442ee984e2b264638a8b5e7ae44fd47b32d28e3a08e2e9c3cdb0c2fb0"
684684
dependencies = [
685685
"cc",
686686
"rustc-std-workspace-core",
@@ -1028,9 +1028,9 @@ dependencies = [
10281028

10291029
[[package]]
10301030
name = "dlmalloc"
1031-
version = "0.2.1"
1031+
version = "0.2.3"
10321032
source = "registry+https://github.com/rust-lang/crates.io-index"
1033-
checksum = "332570860c2edf2d57914987bf9e24835425f75825086b6ba7d1e6a3e4f1f254"
1033+
checksum = "a6fe28e0bf9357092740362502f5cc7955d8dc125ebda71dec72336c2e15c62e"
10341034
dependencies = [
10351035
"compiler_builtins",
10361036
"libc",

compiler/rustc_codegen_llvm/src/asm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
320320
InlineAsmArch::Mips | InlineAsmArch::Mips64 => {}
321321
InlineAsmArch::S390x => {}
322322
InlineAsmArch::SpirV => {}
323-
InlineAsmArch::Wasm32 => {}
323+
InlineAsmArch::Wasm32 | InlineAsmArch::Wasm64 => {}
324324
InlineAsmArch::Bpf => {}
325325
}
326326
}

compiler/rustc_codegen_llvm/src/builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
769769
// we like. To ensure that LLVM picks the right instruction we choose
770770
// the raw wasm intrinsic functions which avoid LLVM inserting all the
771771
// other control flow automatically.
772-
if self.sess().target.arch == "wasm32" {
772+
if self.sess().target.is_like_wasm {
773773
let src_ty = self.cx.val_ty(val);
774774
if self.cx.type_kind(src_ty) != TypeKind::Vector {
775775
let float_width = self.cx.float_width(src_ty);
@@ -791,7 +791,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
791791

792792
fn fptosi(&mut self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
793793
// see `fptoui` above for why wasm is different here
794-
if self.sess().target.arch == "wasm32" {
794+
if self.sess().target.is_like_wasm {
795795
let src_ty = self.cx.val_ty(val);
796796
if self.cx.type_kind(src_ty) != TypeKind::Vector {
797797
let float_width = self.cx.float_width(src_ty);

compiler/rustc_codegen_llvm/src/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ impl StaticMethods for CodegenCx<'ll, 'tcx> {
490490

491491
// Wasm statics with custom link sections get special treatment as they
492492
// go into custom sections of the wasm executable.
493-
if self.tcx.sess.opts.target_triple.triple().starts_with("wasm32") {
493+
if self.tcx.sess.target.is_like_wasm {
494494
if let Some(section) = attrs.link_section {
495495
let section = llvm::LLVMMDStringInContext(
496496
self.llcx,

compiler/rustc_codegen_llvm/src/llvm_util.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ unsafe fn configure_llvm(sess: &Session) {
7575
if sess.print_llvm_passes() {
7676
add("-debug-pass=Structure", false);
7777
}
78-
if !sess.opts.debugging_opts.no_generate_arange_section {
78+
if sess.target.generate_arange_section
79+
&& !sess.opts.debugging_opts.no_generate_arange_section
80+
{
7981
add("-generate-arange-section", false);
8082
}
8183

compiler/rustc_target/src/asm/mod.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ pub enum InlineAsmArch {
189189
S390x,
190190
SpirV,
191191
Wasm32,
192+
Wasm64,
192193
Bpf,
193194
}
194195

@@ -212,6 +213,7 @@ impl FromStr for InlineAsmArch {
212213
"s390x" => Ok(Self::S390x),
213214
"spirv" => Ok(Self::SpirV),
214215
"wasm32" => Ok(Self::Wasm32),
216+
"wasm64" => Ok(Self::Wasm64),
215217
"bpf" => Ok(Self::Bpf),
216218
_ => Err(()),
217219
}
@@ -318,7 +320,7 @@ impl InlineAsmReg {
318320
InlineAsmArch::SpirV => {
319321
Self::SpirV(SpirVInlineAsmReg::parse(arch, has_feature, target, &name)?)
320322
}
321-
InlineAsmArch::Wasm32 => {
323+
InlineAsmArch::Wasm32 | InlineAsmArch::Wasm64 => {
322324
Self::Wasm(WasmInlineAsmReg::parse(arch, has_feature, target, &name)?)
323325
}
324326
InlineAsmArch::Bpf => {
@@ -529,7 +531,9 @@ impl InlineAsmRegClass {
529531
}
530532
InlineAsmArch::S390x => Self::S390x(S390xInlineAsmRegClass::parse(arch, name)?),
531533
InlineAsmArch::SpirV => Self::SpirV(SpirVInlineAsmRegClass::parse(arch, name)?),
532-
InlineAsmArch::Wasm32 => Self::Wasm(WasmInlineAsmRegClass::parse(arch, name)?),
534+
InlineAsmArch::Wasm32 | InlineAsmArch::Wasm64 => {
535+
Self::Wasm(WasmInlineAsmRegClass::parse(arch, name)?)
536+
}
533537
InlineAsmArch::Bpf => Self::Bpf(BpfInlineAsmRegClass::parse(arch, name)?),
534538
})
535539
}
@@ -725,7 +729,7 @@ pub fn allocatable_registers(
725729
spirv::fill_reg_map(arch, has_feature, target, &mut map);
726730
map
727731
}
728-
InlineAsmArch::Wasm32 => {
732+
InlineAsmArch::Wasm32 | InlineAsmArch::Wasm64 => {
729733
let mut map = wasm::regclass_map();
730734
wasm::fill_reg_map(arch, has_feature, target, &mut map);
731735
map

compiler/rustc_target/src/spec/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,9 @@ pub struct TargetOptions {
13571357

13581358
/// Minimum number of bits in #[repr(C)] enum. Defaults to 32.
13591359
pub c_enum_min_bits: u64,
1360+
1361+
/// Whether or not the DWARF `.debug_aranges` section should be generated.
1362+
pub generate_arange_section: bool,
13601363
}
13611364

13621365
impl Default for TargetOptions {
@@ -1462,6 +1465,7 @@ impl Default for TargetOptions {
14621465
supported_sanitizers: SanitizerSet::empty(),
14631466
default_adjusted_cabi: None,
14641467
c_enum_min_bits: 32,
1468+
generate_arange_section: true,
14651469
}
14661470
}
14671471
}
@@ -2047,6 +2051,7 @@ impl Target {
20472051
key!(supported_sanitizers, SanitizerSet)?;
20482052
key!(default_adjusted_cabi, Option<Abi>)?;
20492053
key!(c_enum_min_bits, u64);
2054+
key!(generate_arange_section, bool);
20502055

20512056
if base.is_builtin {
20522057
// This can cause unfortunate ICEs later down the line.
@@ -2286,6 +2291,7 @@ impl ToJson for Target {
22862291
target_option_val!(split_debuginfo);
22872292
target_option_val!(supported_sanitizers);
22882293
target_option_val!(c_enum_min_bits);
2294+
target_option_val!(generate_arange_section);
22892295

22902296
if let Some(abi) = self.default_adjusted_cabi {
22912297
d.insert("default-adjusted-cabi".to_string(), Abi::name(abi).to_json());

compiler/rustc_target/src/spec/wasm32_unknown_emscripten.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub fn target() -> Target {
3737
is_like_emscripten: true,
3838
panic_strategy: PanicStrategy::Unwind,
3939
post_link_args,
40-
families: vec!["unix".to_string()],
40+
families: vec!["unix".to_string(), "wasm".to_string()],
4141
..options
4242
};
4343
Target {

compiler/rustc_target/src/spec/wasm64_unknown_unknown.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@ pub fn target() -> Target {
2323
// For now this target just never has an entry symbol no matter the output
2424
// type, so unconditionally pass this.
2525
clang_args.push("-Wl,--no-entry".to_string());
26-
options
27-
.pre_link_args
28-
.get_mut(&LinkerFlavor::Lld(LldFlavor::Wasm))
29-
.unwrap()
30-
.push("--no-entry".to_string());
26+
27+
let lld_args = options.pre_link_args.get_mut(&LinkerFlavor::Lld(LldFlavor::Wasm)).unwrap();
28+
lld_args.push("--no-entry".to_string());
29+
lld_args.push("-mwasm64".to_string());
30+
31+
// Any engine that implements wasm64 will surely implement the rest of these
32+
// features since they were all merged into the official spec by the time
33+
// wasm64 was designed.
34+
options.features = "+bulk-memory,+mutable-globals,+sign-ext,+nontrapping-fptoint".to_string();
3135

3236
Target {
3337
llvm_target: "wasm64-unknown-unknown".to_string(),

compiler/rustc_target/src/spec/wasm_base.rs

+6
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ pub fn options() -> TargetOptions {
128128
// gdb scripts don't work on wasm blobs
129129
emit_debug_gdb_scripts: false,
130130

131+
// There's more discussion of this at
132+
// https://bugs.llvm.org/show_bug.cgi?id=52442 but the general result is
133+
// that this isn't useful for wasm and has tricky issues with
134+
// representation, so this is disabled.
135+
generate_arange_section: false,
136+
131137
..Default::default()
132138
}
133139
}

compiler/rustc_typeck/src/check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -536,8 +536,8 @@ fn fn_maybe_err(tcx: TyCtxt<'_>, sp: Span, abi: Abi) {
536536
}
537537

538538
fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: LocalDefId, span: Span) {
539-
// Only restricted on wasm32 target for now
540-
if !tcx.sess.opts.target_triple.triple().starts_with("wasm32") {
539+
// Only restricted on wasm target for now
540+
if !tcx.sess.target.is_like_wasm {
541541
return;
542542
}
543543

library/core/src/ffi.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl fmt::Debug for c_void {
6262
#[cfg(any(
6363
all(not(target_arch = "aarch64"), not(target_arch = "powerpc"), not(target_arch = "x86_64")),
6464
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")),
65-
target_arch = "wasm32",
65+
target_family = "wasm",
6666
target_arch = "asmjs",
6767
windows
6868
))]
@@ -85,7 +85,7 @@ pub struct VaListImpl<'f> {
8585
#[cfg(any(
8686
all(not(target_arch = "aarch64"), not(target_arch = "powerpc"), not(target_arch = "x86_64")),
8787
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")),
88-
target_arch = "wasm32",
88+
target_family = "wasm",
8989
target_arch = "asmjs",
9090
windows
9191
))]
@@ -185,7 +185,7 @@ pub struct VaList<'a, 'f: 'a> {
185185
not(target_arch = "x86_64")
186186
),
187187
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")),
188-
target_arch = "wasm32",
188+
target_family = "wasm",
189189
target_arch = "asmjs",
190190
windows
191191
))]
@@ -194,7 +194,7 @@ pub struct VaList<'a, 'f: 'a> {
194194
#[cfg(all(
195195
any(target_arch = "aarch64", target_arch = "powerpc", target_arch = "x86_64"),
196196
any(not(target_arch = "aarch64"), not(any(target_os = "macos", target_os = "ios"))),
197-
not(target_arch = "wasm32"),
197+
not(target_family = "wasm"),
198198
not(target_arch = "asmjs"),
199199
not(windows)
200200
))]
@@ -206,7 +206,7 @@ pub struct VaList<'a, 'f: 'a> {
206206
#[cfg(any(
207207
all(not(target_arch = "aarch64"), not(target_arch = "powerpc"), not(target_arch = "x86_64")),
208208
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")),
209-
target_arch = "wasm32",
209+
target_family = "wasm",
210210
target_arch = "asmjs",
211211
windows
212212
))]
@@ -227,7 +227,7 @@ impl<'f> VaListImpl<'f> {
227227
#[cfg(all(
228228
any(target_arch = "aarch64", target_arch = "powerpc", target_arch = "x86_64"),
229229
any(not(target_arch = "aarch64"), not(any(target_os = "macos", target_os = "ios"))),
230-
not(target_arch = "wasm32"),
230+
not(target_family = "wasm"),
231231
not(target_arch = "asmjs"),
232232
not(windows)
233233
))]

library/panic_abort/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub unsafe extern "C-unwind" fn __rust_start_panic(_payload: *mut &mut dyn BoxMe
117117
pub mod personalities {
118118
#[rustc_std_internal_symbol]
119119
#[cfg(not(any(
120-
all(target_arch = "wasm32", not(target_os = "emscripten"),),
120+
all(target_family = "wasm", not(target_os = "emscripten")),
121121
all(target_os = "windows", target_env = "gnu", target_arch = "x86_64",),
122122
)))]
123123
pub extern "C" fn rust_eh_personality() {}

library/panic_unwind/src/dummy.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
//! Unwinding for *wasm32* target.
1+
//! Unwinding for unsupported target.
22
//!
3-
//! Right now we don't support this, so this is just stubs.
3+
//! Stubs that simply abort for targets that don't support unwinding otherwise.
44
55
use alloc::boxed::Box;
66
use core::any::Any;

library/panic_unwind/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ cfg_if::cfg_if! {
5656
mod real_imp;
5757
} else {
5858
// Targets that don't support unwinding.
59-
// - arch=wasm32
59+
// - family=wasm
6060
// - os=none ("bare metal" targets)
6161
// - os=uefi
6262
// - os=espidf

library/std/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ panic_unwind = { path = "../panic_unwind", optional = true }
1616
panic_abort = { path = "../panic_abort" }
1717
core = { path = "../core" }
1818
libc = { version = "0.2.106", default-features = false, features = ['rustc-dep-of-std'] }
19-
compiler_builtins = { version = "0.1.44" }
19+
compiler_builtins = { version = "0.1.52" }
2020
profiler_builtins = { path = "../profiler_builtins", optional = true }
2121
unwind = { path = "../unwind" }
2222
hashbrown = { version = "0.11", default-features = false, features = ['rustc-dep-of-std'] }
@@ -35,8 +35,8 @@ features = ['read_core', 'elf', 'macho', 'pe', 'unaligned', 'archive']
3535
[dev-dependencies]
3636
rand = "0.7"
3737

38-
[target.'cfg(any(all(target_arch = "wasm32", not(target_os = "emscripten")), all(target_vendor = "fortanix", target_env = "sgx")))'.dependencies]
39-
dlmalloc = { version = "0.2.1", features = ['rustc-dep-of-std'] }
38+
[target.'cfg(any(all(target_family = "wasm", not(target_os = "emscripten")), all(target_vendor = "fortanix", target_env = "sgx")))'.dependencies]
39+
dlmalloc = { version = "0.2.3", features = ['rustc-dep-of-std'] }
4040

4141
[target.x86_64-fortanix-unknown-sgx.dependencies]
4242
fortanix-sgx-abi = { version = "0.3.2", features = ['rustc-dep-of-std'] }

library/std/build.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ fn main() {
2525
|| target.contains("haiku")
2626
|| target.contains("vxworks")
2727
|| target.contains("wasm32")
28+
|| target.contains("wasm64")
2829
|| target.contains("asmjs")
2930
|| target.contains("espidf")
3031
|| target.contains("solid")

library/std/src/sys/common/alloc.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ pub const MIN_ALIGN: usize = 8;
2424
target_arch = "mips64",
2525
target_arch = "s390x",
2626
target_arch = "sparc64",
27-
target_arch = "riscv64"
27+
target_arch = "riscv64",
28+
target_arch = "wasm64",
2829
)))]
2930
pub const MIN_ALIGN: usize = 16;
3031

library/std/src/sys/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ cfg_if::cfg_if! {
4040
} else if #[cfg(target_os = "wasi")] {
4141
mod wasi;
4242
pub use self::wasi::*;
43-
} else if #[cfg(target_arch = "wasm32")] {
43+
} else if #[cfg(target_family = "wasm")] {
4444
mod wasm;
4545
pub use self::wasm::*;
4646
} else if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {

library/std/src/sys/wasm/alloc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
//! This is an implementation of a global allocator on the wasm32 platform when
1+
//! This is an implementation of a global allocator on wasm targets when
22
//! emscripten is not in use. In that situation there's no actual runtime for us
33
//! to lean on for allocation, so instead we provide our own!
44
//!
5-
//! The wasm32 instruction set has two instructions for getting the current
5+
//! The wasm instruction set has two instructions for getting the current
66
//! amount of memory and growing the amount of memory. These instructions are the
77
//! foundation on which we're able to build an allocator, so we do so! Note that
88
//! the instructions are also pretty "global" and this is the "global" allocator

library/std/src/sys_common/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ cfg_if::cfg_if! {
4040
if #[cfg(any(target_os = "l4re",
4141
target_os = "hermit",
4242
feature = "restricted-std",
43-
all(target_arch = "wasm32", not(target_os = "emscripten")),
43+
all(target_family = "wasm", not(target_os = "emscripten")),
4444
all(target_vendor = "fortanix", target_env = "sgx")))] {
4545
pub use crate::sys::net;
4646
} else {

0 commit comments

Comments
 (0)