1
Fork 0

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.
This commit is contained in:
bors 2021-11-18 17:19:27 +00:00
commit b6f580acc0
31 changed files with 183 additions and 60 deletions

View file

@ -189,6 +189,7 @@ pub enum InlineAsmArch {
S390x,
SpirV,
Wasm32,
Wasm64,
Bpf,
}
@ -212,6 +213,7 @@ impl FromStr for InlineAsmArch {
"s390x" => Ok(Self::S390x),
"spirv" => Ok(Self::SpirV),
"wasm32" => Ok(Self::Wasm32),
"wasm64" => Ok(Self::Wasm64),
"bpf" => Ok(Self::Bpf),
_ => Err(()),
}
@ -318,7 +320,7 @@ impl InlineAsmReg {
InlineAsmArch::SpirV => {
Self::SpirV(SpirVInlineAsmReg::parse(arch, has_feature, target, &name)?)
}
InlineAsmArch::Wasm32 => {
InlineAsmArch::Wasm32 | InlineAsmArch::Wasm64 => {
Self::Wasm(WasmInlineAsmReg::parse(arch, has_feature, target, &name)?)
}
InlineAsmArch::Bpf => {
@ -529,7 +531,9 @@ impl InlineAsmRegClass {
}
InlineAsmArch::S390x => Self::S390x(S390xInlineAsmRegClass::parse(arch, name)?),
InlineAsmArch::SpirV => Self::SpirV(SpirVInlineAsmRegClass::parse(arch, name)?),
InlineAsmArch::Wasm32 => Self::Wasm(WasmInlineAsmRegClass::parse(arch, name)?),
InlineAsmArch::Wasm32 | InlineAsmArch::Wasm64 => {
Self::Wasm(WasmInlineAsmRegClass::parse(arch, name)?)
}
InlineAsmArch::Bpf => Self::Bpf(BpfInlineAsmRegClass::parse(arch, name)?),
})
}
@ -725,7 +729,7 @@ pub fn allocatable_registers(
spirv::fill_reg_map(arch, has_feature, target, &mut map);
map
}
InlineAsmArch::Wasm32 => {
InlineAsmArch::Wasm32 | InlineAsmArch::Wasm64 => {
let mut map = wasm::regclass_map();
wasm::fill_reg_map(arch, has_feature, target, &mut map);
map

View file

@ -1357,6 +1357,9 @@ pub struct TargetOptions {
/// Minimum number of bits in #[repr(C)] enum. Defaults to 32.
pub c_enum_min_bits: u64,
/// Whether or not the DWARF `.debug_aranges` section should be generated.
pub generate_arange_section: bool,
}
impl Default for TargetOptions {
@ -1462,6 +1465,7 @@ impl Default for TargetOptions {
supported_sanitizers: SanitizerSet::empty(),
default_adjusted_cabi: None,
c_enum_min_bits: 32,
generate_arange_section: true,
}
}
}
@ -2047,6 +2051,7 @@ impl Target {
key!(supported_sanitizers, SanitizerSet)?;
key!(default_adjusted_cabi, Option<Abi>)?;
key!(c_enum_min_bits, u64);
key!(generate_arange_section, bool);
if base.is_builtin {
// This can cause unfortunate ICEs later down the line.
@ -2286,6 +2291,7 @@ impl ToJson for Target {
target_option_val!(split_debuginfo);
target_option_val!(supported_sanitizers);
target_option_val!(c_enum_min_bits);
target_option_val!(generate_arange_section);
if let Some(abi) = self.default_adjusted_cabi {
d.insert("default-adjusted-cabi".to_string(), Abi::name(abi).to_json());

View file

@ -37,7 +37,7 @@ pub fn target() -> Target {
is_like_emscripten: true,
panic_strategy: PanicStrategy::Unwind,
post_link_args,
families: vec!["unix".to_string()],
families: vec!["unix".to_string(), "wasm".to_string()],
..options
};
Target {

View file

@ -23,11 +23,15 @@ pub fn target() -> Target {
// For now this target just never has an entry symbol no matter the output
// type, so unconditionally pass this.
clang_args.push("-Wl,--no-entry".to_string());
options
.pre_link_args
.get_mut(&LinkerFlavor::Lld(LldFlavor::Wasm))
.unwrap()
.push("--no-entry".to_string());
let lld_args = options.pre_link_args.get_mut(&LinkerFlavor::Lld(LldFlavor::Wasm)).unwrap();
lld_args.push("--no-entry".to_string());
lld_args.push("-mwasm64".to_string());
// Any engine that implements wasm64 will surely implement the rest of these
// features since they were all merged into the official spec by the time
// wasm64 was designed.
options.features = "+bulk-memory,+mutable-globals,+sign-ext,+nontrapping-fptoint".to_string();
Target {
llvm_target: "wasm64-unknown-unknown".to_string(),

View file

@ -128,6 +128,12 @@ pub fn options() -> TargetOptions {
// gdb scripts don't work on wasm blobs
emit_debug_gdb_scripts: false,
// There's more discussion of this at
// https://bugs.llvm.org/show_bug.cgi?id=52442 but the general result is
// that this isn't useful for wasm and has tricky issues with
// representation, so this is disabled.
generate_arange_section: false,
..Default::default()
}
}