1
Fork 0

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.
This commit is contained in:
Alex Crichton 2021-10-28 10:58:16 -07:00
parent 68ca579406
commit 7f3ffbc8c2
13 changed files with 41 additions and 22 deletions

View file

@ -23,11 +23,10 @@ pub fn target() -> Target {
// For now this target just never has an entry symbol no matter the output // For now this target just never has an entry symbol no matter the output
// type, so unconditionally pass this. // type, so unconditionally pass this.
clang_args.push("-Wl,--no-entry".to_string()); clang_args.push("-Wl,--no-entry".to_string());
options
.pre_link_args let lld_args = options.pre_link_args.get_mut(&LinkerFlavor::Lld(LldFlavor::Wasm)).unwrap();
.get_mut(&LinkerFlavor::Lld(LldFlavor::Wasm)) lld_args.push("--no-entry".to_string());
.unwrap() lld_args.push("-mwasm64".to_string());
.push("--no-entry".to_string());
Target { Target {
llvm_target: "wasm64-unknown-unknown".to_string(), llvm_target: "wasm64-unknown-unknown".to_string(),

View file

@ -63,6 +63,7 @@ impl fmt::Debug for c_void {
all(not(target_arch = "aarch64"), not(target_arch = "powerpc"), not(target_arch = "x86_64")), all(not(target_arch = "aarch64"), not(target_arch = "powerpc"), not(target_arch = "x86_64")),
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")), all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")),
target_arch = "wasm32", target_arch = "wasm32",
target_arch = "wasm64",
target_arch = "asmjs", target_arch = "asmjs",
windows windows
))] ))]
@ -86,6 +87,7 @@ pub struct VaListImpl<'f> {
all(not(target_arch = "aarch64"), not(target_arch = "powerpc"), not(target_arch = "x86_64")), all(not(target_arch = "aarch64"), not(target_arch = "powerpc"), not(target_arch = "x86_64")),
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")), all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")),
target_arch = "wasm32", target_arch = "wasm32",
target_arch = "wasm64",
target_arch = "asmjs", target_arch = "asmjs",
windows windows
))] ))]
@ -186,6 +188,7 @@ pub struct VaList<'a, 'f: 'a> {
), ),
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")), all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")),
target_arch = "wasm32", target_arch = "wasm32",
target_arch = "wasm64",
target_arch = "asmjs", target_arch = "asmjs",
windows windows
))] ))]
@ -195,6 +198,7 @@ pub struct VaList<'a, 'f: 'a> {
any(target_arch = "aarch64", target_arch = "powerpc", target_arch = "x86_64"), any(target_arch = "aarch64", target_arch = "powerpc", target_arch = "x86_64"),
any(not(target_arch = "aarch64"), not(any(target_os = "macos", target_os = "ios"))), any(not(target_arch = "aarch64"), not(any(target_os = "macos", target_os = "ios"))),
not(target_arch = "wasm32"), not(target_arch = "wasm32"),
not(target_arch = "wasm64"),
not(target_arch = "asmjs"), not(target_arch = "asmjs"),
not(windows) not(windows)
))] ))]
@ -207,6 +211,7 @@ pub struct VaList<'a, 'f: 'a> {
all(not(target_arch = "aarch64"), not(target_arch = "powerpc"), not(target_arch = "x86_64")), all(not(target_arch = "aarch64"), not(target_arch = "powerpc"), not(target_arch = "x86_64")),
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")), all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")),
target_arch = "wasm32", target_arch = "wasm32",
target_arch = "wasm64",
target_arch = "asmjs", target_arch = "asmjs",
windows windows
))] ))]
@ -228,6 +233,7 @@ impl<'f> VaListImpl<'f> {
any(target_arch = "aarch64", target_arch = "powerpc", target_arch = "x86_64"), any(target_arch = "aarch64", target_arch = "powerpc", target_arch = "x86_64"),
any(not(target_arch = "aarch64"), not(any(target_os = "macos", target_os = "ios"))), any(not(target_arch = "aarch64"), not(any(target_os = "macos", target_os = "ios"))),
not(target_arch = "wasm32"), not(target_arch = "wasm32"),
not(target_arch = "wasm64"),
not(target_arch = "asmjs"), not(target_arch = "asmjs"),
not(windows) not(windows)
))] ))]

View file

@ -117,7 +117,8 @@ pub unsafe extern "C-unwind" fn __rust_start_panic(_payload: *mut &mut dyn BoxMe
pub mod personalities { pub mod personalities {
#[rustc_std_internal_symbol] #[rustc_std_internal_symbol]
#[cfg(not(any( #[cfg(not(any(
all(target_arch = "wasm32", not(target_os = "emscripten"),), all(target_arch = "wasm32", not(target_os = "emscripten")),
all(target_arch = "wasm64", not(target_os = "emscripten")),
all(target_os = "windows", target_env = "gnu", target_arch = "x86_64",), all(target_os = "windows", target_env = "gnu", target_arch = "x86_64",),
)))] )))]
pub extern "C" fn rust_eh_personality() {} pub extern "C" fn rust_eh_personality() {}

View file

@ -1,6 +1,6 @@
//! Unwinding for *wasm32* target. //! Unwinding for unsupported target.
//! //!
//! Right now we don't support this, so this is just stubs. //! Stubs that simply abort for targets that don't support unwinding otherwise.
use alloc::boxed::Box; use alloc::boxed::Box;
use core::any::Any; use core::any::Any;

View file

@ -57,6 +57,7 @@ cfg_if::cfg_if! {
} else { } else {
// Targets that don't support unwinding. // Targets that don't support unwinding.
// - arch=wasm32 // - arch=wasm32
// - arch=wasm64
// - os=none ("bare metal" targets) // - os=none ("bare metal" targets)
// - os=uefi // - os=uefi
// - os=espidf // - os=espidf

View file

@ -35,7 +35,7 @@ features = ['read_core', 'elf', 'macho', 'pe', 'unaligned', 'archive']
[dev-dependencies] [dev-dependencies]
rand = "0.7" rand = "0.7"
[target.'cfg(any(all(target_arch = "wasm32", not(target_os = "emscripten")), all(target_vendor = "fortanix", target_env = "sgx")))'.dependencies] [target.'cfg(any(all(any(target_arch = "wasm32", target_arch = "wasm64"), not(target_os = "emscripten")), all(target_vendor = "fortanix", target_env = "sgx")))'.dependencies]
dlmalloc = { version = "0.2.1", features = ['rustc-dep-of-std'] } dlmalloc = { version = "0.2.1", features = ['rustc-dep-of-std'] }
[target.x86_64-fortanix-unknown-sgx.dependencies] [target.x86_64-fortanix-unknown-sgx.dependencies]

View file

@ -25,6 +25,7 @@ fn main() {
|| target.contains("haiku") || target.contains("haiku")
|| target.contains("vxworks") || target.contains("vxworks")
|| target.contains("wasm32") || target.contains("wasm32")
|| target.contains("wasm64")
|| target.contains("asmjs") || target.contains("asmjs")
|| target.contains("espidf") || target.contains("espidf")
|| target.contains("solid") || target.contains("solid")

View file

@ -24,7 +24,8 @@ pub const MIN_ALIGN: usize = 8;
target_arch = "mips64", target_arch = "mips64",
target_arch = "s390x", target_arch = "s390x",
target_arch = "sparc64", target_arch = "sparc64",
target_arch = "riscv64" target_arch = "riscv64",
target_arch = "wasm64",
)))] )))]
pub const MIN_ALIGN: usize = 16; pub const MIN_ALIGN: usize = 16;

View file

@ -40,7 +40,7 @@ cfg_if::cfg_if! {
} else if #[cfg(target_os = "wasi")] { } else if #[cfg(target_os = "wasi")] {
mod wasi; mod wasi;
pub use self::wasi::*; pub use self::wasi::*;
} else if #[cfg(target_arch = "wasm32")] { } else if #[cfg(any(target_arch = "wasm32", target_arch = "wasm64"))] {
mod wasm; mod wasm;
pub use self::wasm::*; pub use self::wasm::*;
} else if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] { } else if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {

View file

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

View file

@ -41,6 +41,7 @@ cfg_if::cfg_if! {
target_os = "hermit", target_os = "hermit",
feature = "restricted-std", feature = "restricted-std",
all(target_arch = "wasm32", not(target_os = "emscripten")), all(target_arch = "wasm32", not(target_os = "emscripten")),
all(target_arch = "wasm64", not(target_os = "emscripten")),
all(target_vendor = "fortanix", target_env = "sgx")))] { all(target_vendor = "fortanix", target_env = "sgx")))] {
pub use crate::sys::net; pub use crate::sys::net;
} else { } else {

View file

@ -172,7 +172,7 @@ macro_rules! __thread_local_inner {
// //
// FIXME(#84224) this should come after the `target_thread_local` // FIXME(#84224) this should come after the `target_thread_local`
// block. // block.
#[cfg(all(target_arch = "wasm32", not(target_feature = "atomics")))] #[cfg(all(any(target_arch = "wasm32", target_arch = "wasm64"), not(target_feature = "atomics")))]
{ {
static mut VAL: $t = $init; static mut VAL: $t = $init;
Some(&VAL) Some(&VAL)
@ -181,7 +181,10 @@ macro_rules! __thread_local_inner {
// If the platform has support for `#[thread_local]`, use it. // If the platform has support for `#[thread_local]`, use it.
#[cfg(all( #[cfg(all(
target_thread_local, target_thread_local,
not(all(target_arch = "wasm32", not(target_feature = "atomics"))), not(all(
any(target_arch = "wasm32", target_arch = "wasm64"),
not(target_feature = "atomics"),
)),
))] ))]
{ {
// If a dtor isn't needed we can do something "very raw" and // If a dtor isn't needed we can do something "very raw" and
@ -238,7 +241,10 @@ macro_rules! __thread_local_inner {
// same implementation as below for os thread locals. // same implementation as below for os thread locals.
#[cfg(all( #[cfg(all(
not(target_thread_local), not(target_thread_local),
not(all(target_arch = "wasm32", not(target_feature = "atomics"))), not(all(
any(target_arch = "wasm32", target_arch = "wasm64"),
not(target_feature = "atomics"),
)),
))] ))]
{ {
#[inline] #[inline]
@ -285,21 +291,21 @@ macro_rules! __thread_local_inner {
// The issue of "should enable on Windows sometimes" is #84933 // The issue of "should enable on Windows sometimes" is #84933
#[cfg_attr(not(windows), inline)] #[cfg_attr(not(windows), inline)]
unsafe fn __getit() -> $crate::option::Option<&'static $t> { unsafe fn __getit() -> $crate::option::Option<&'static $t> {
#[cfg(all(target_arch = "wasm32", not(target_feature = "atomics")))] #[cfg(all(any(target_arch = "wasm32", target_arch = "wasm64"), not(target_feature = "atomics")))]
static __KEY: $crate::thread::__StaticLocalKeyInner<$t> = static __KEY: $crate::thread::__StaticLocalKeyInner<$t> =
$crate::thread::__StaticLocalKeyInner::new(); $crate::thread::__StaticLocalKeyInner::new();
#[thread_local] #[thread_local]
#[cfg(all( #[cfg(all(
target_thread_local, target_thread_local,
not(all(target_arch = "wasm32", not(target_feature = "atomics"))), not(all(any(target_arch = "wasm32", target_arch = "wasm64"), not(target_feature = "atomics"))),
))] ))]
static __KEY: $crate::thread::__FastLocalKeyInner<$t> = static __KEY: $crate::thread::__FastLocalKeyInner<$t> =
$crate::thread::__FastLocalKeyInner::new(); $crate::thread::__FastLocalKeyInner::new();
#[cfg(all( #[cfg(all(
not(target_thread_local), not(target_thread_local),
not(all(target_arch = "wasm32", not(target_feature = "atomics"))), not(all(any(target_arch = "wasm32", target_arch = "wasm64"), not(target_feature = "atomics"))),
))] ))]
static __KEY: $crate::thread::__OsLocalKeyInner<$t> = static __KEY: $crate::thread::__OsLocalKeyInner<$t> =
$crate::thread::__OsLocalKeyInner::new(); $crate::thread::__OsLocalKeyInner::new();
@ -479,10 +485,10 @@ mod lazy {
} }
} }
/// On some platforms like wasm32 there's no threads, so no need to generate /// On some platforms like wasm there's no threads, so no need to generate
/// thread locals and we can instead just use plain statics! /// thread locals and we can instead just use plain statics!
#[doc(hidden)] #[doc(hidden)]
#[cfg(all(target_arch = "wasm32", not(target_feature = "atomics")))] #[cfg(all(any(target_arch = "wasm32", target_arch = "wasm64"), not(target_feature = "atomics")))]
pub mod statik { pub mod statik {
use super::lazy::LazyKeyInner; use super::lazy::LazyKeyInner;
use crate::fmt; use crate::fmt;

View file

@ -200,7 +200,10 @@ pub use self::local::fast::Key as __FastLocalKeyInner;
#[doc(hidden)] #[doc(hidden)]
pub use self::local::os::Key as __OsLocalKeyInner; pub use self::local::os::Key as __OsLocalKeyInner;
#[unstable(feature = "libstd_thread_internals", issue = "none")] #[unstable(feature = "libstd_thread_internals", issue = "none")]
#[cfg(all(target_arch = "wasm32", not(target_feature = "atomics")))] #[cfg(all(
any(target_arch = "wasm32", target_arch = "wasm64"),
not(target_feature = "atomics")
))]
#[doc(hidden)] #[doc(hidden)]
pub use self::local::statik::Key as __StaticLocalKeyInner; pub use self::local::statik::Key as __StaticLocalKeyInner;