Skip to content

Commit 87817f3

Browse files
authored
Improve unsupported architecture errors in Wasmtime (#9039)
Don't rely purely on `compile_error!` which doesn't halt compilation. Instead fill out some stubs which won't ever actually get compiled but prevent other compiler errors from cropping up.
1 parent c17913d commit 87817f3

File tree

7 files changed

+85
-16
lines changed

7 files changed

+85
-16
lines changed

crates/wasmtime/src/runtime/gc/enabled/rooting.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ pub struct GcRootIndex {
200200
const _: () = {
201201
// NB: these match the C API which should also be updated if this changes
202202
assert!(mem::size_of::<GcRootIndex>() == 16);
203-
assert!(mem::align_of::<GcRootIndex>() == 8);
203+
assert!(mem::align_of::<GcRootIndex>() == mem::align_of::<u64>());
204204
};
205205

206206
impl GcRootIndex {
@@ -1302,9 +1302,9 @@ const _: () = {
13021302

13031303
// NB: these match the C API which should also be updated if this changes
13041304
assert!(mem::size_of::<ManuallyRooted<AnyRef>>() == 16);
1305-
assert!(mem::align_of::<ManuallyRooted<AnyRef>>() == 8);
1305+
assert!(mem::align_of::<ManuallyRooted<AnyRef>>() == mem::align_of::<u64>());
13061306
assert!(mem::size_of::<ManuallyRooted<ExternRef>>() == 16);
1307-
assert!(mem::align_of::<ManuallyRooted<ExternRef>>() == 8);
1307+
assert!(mem::align_of::<ManuallyRooted<ExternRef>>() == mem::align_of::<u64>());
13081308
};
13091309

13101310
impl<T: GcRef> Debug for ManuallyRooted<T> {

crates/wasmtime/src/runtime/vm/arch/mod.rs

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,44 @@
1010
cfg_if::cfg_if! {
1111
if #[cfg(target_arch = "x86_64")] {
1212
mod x86_64;
13-
pub use x86_64::*;
13+
use x86_64 as imp;
1414
} else if #[cfg(target_arch = "aarch64")] {
1515
mod aarch64;
16-
pub use aarch64::*;
16+
use aarch64 as imp;
1717
} else if #[cfg(target_arch = "s390x")] {
1818
mod s390x;
19-
pub use s390x::*;
19+
use s390x as imp;
2020
} else if #[cfg(target_arch = "riscv64")] {
2121
mod riscv64;
22-
pub use riscv64::*;
22+
use riscv64 as imp;
2323
} else {
24-
compile_error!(
25-
"Wasmtime is being compiled for an architecture \
26-
that it does not support. If this architecture is \
27-
one you would like to see supported you may file an \
28-
issue on Wasmtime's issue tracker: \
29-
https://github.com/bytecodealliance/wasmtime/issues/new\
30-
");
24+
mod unsupported;
25+
use unsupported as imp;
3126
}
3227
}
28+
29+
// Functions defined in this module but all the implementations delegate to each
30+
// `imp` module. This exists to assert that each module internally provides the
31+
// same set of functionality with the same types for all architectures.
32+
33+
pub fn get_stack_pointer() -> usize {
34+
imp::get_stack_pointer()
35+
}
36+
37+
pub unsafe fn get_next_older_pc_from_fp(fp: usize) -> usize {
38+
imp::get_next_older_pc_from_fp(fp)
39+
}
40+
41+
pub const NEXT_OLDER_FP_FROM_FP_OFFSET: usize = imp::NEXT_OLDER_FP_FROM_FP_OFFSET;
42+
43+
pub fn reached_entry_sp(fp: usize, entry_sp: usize) -> bool {
44+
imp::reached_entry_sp(fp, entry_sp)
45+
}
46+
47+
pub fn assert_entry_sp_is_aligned(sp: usize) {
48+
imp::assert_entry_sp_is_aligned(sp)
49+
}
50+
51+
pub fn assert_fp_is_aligned(fp: usize) {
52+
imp::assert_fp_is_aligned(fp)
53+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
compile_error!("Wasmtime's runtime is being compiled for an architecture that it does not support");
2+
3+
cfg_if::cfg_if! {
4+
if #[cfg(target_arch = "x86")] {
5+
compile_error!("\
6+
the tracking issue for i686 support is https://github.com/bytecodealliance/wasmtime/issues/1980 \
7+
");
8+
} else if #[cfg(target_arch = "arm")] {
9+
compile_error!("\
10+
the tracking issue for arm support is https://github.com/bytecodealliance/wasmtime/issues/1173 \
11+
");
12+
} else if #[cfg(target_arch = "riscv32")] {
13+
compile_error!("\
14+
the tracking issue for riscv32 support is https://github.com/bytecodealliance/wasmtime/issues/8768 \
15+
");
16+
} else {
17+
compile_error!("\
18+
if you'd like feel free to file an issue for platform support at
19+
https://github.com/bytecodealliance/wasmtime/issues/new
20+
");
21+
}
22+
}
23+
24+
pub fn get_stack_pointer() -> usize {
25+
panic!()
26+
}
27+
28+
pub unsafe fn get_next_older_pc_from_fp(_fp: usize) -> usize {
29+
panic!()
30+
}
31+
32+
pub const NEXT_OLDER_FP_FROM_FP_OFFSET: usize = 0;
33+
34+
pub fn reached_entry_sp(_fp: usize, _entry_sp: usize) -> bool {
35+
panic!()
36+
}
37+
38+
pub fn assert_entry_sp_is_aligned(_sp: usize) {
39+
panic!()
40+
}
41+
42+
pub fn assert_fp_is_aligned(_fp: usize) {
43+
panic!()
44+
}

crates/wasmtime/src/runtime/vm/gc/gc_ref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use wasmtime_environ::{VMGcKind, VMSharedTypeIndex};
2828
/// ty: Option<VMSharedTypeIndex>,
2929
/// }
3030
/// ```
31-
#[repr(transparent)]
31+
#[repr(align(8))]
3232
pub struct VMGcHeader(u64);
3333

3434
unsafe impl GcHeapObject for VMGcHeader {

crates/wasmtime/src/runtime/vm/instance/allocator/pooling.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,10 @@ impl Default for InstanceLimits {
166166
// have 10k+ elements.
167167
table_elements: 20_000,
168168
max_memories_per_module: 1,
169+
#[cfg(target_pointer_width = "64")]
169170
max_memory_size: 1 << 32, // 4G,
171+
#[cfg(target_pointer_width = "32")]
172+
max_memory_size: usize::MAX,
170173
#[cfg(feature = "gc")]
171174
total_gc_heaps: 1000,
172175
}

crates/wasmtime/src/runtime/vm/sys/unix/signals.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ unsafe fn get_pc_and_fp(cx: *mut libc::c_void, _signum: libc::c_int) -> (*const
320320
}
321321
else {
322322
compile_error!("unsupported platform");
323+
panic!();
323324
}
324325
}
325326
}

crates/wasmtime/src/runtime/vm/vmcontext.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ pub union ValRaw {
10181018
// matched in C.
10191019
const _: () = {
10201020
assert!(mem::size_of::<ValRaw>() == 16);
1021-
assert!(mem::align_of::<ValRaw>() == 8);
1021+
assert!(mem::align_of::<ValRaw>() == mem::align_of::<u64>());
10221022
};
10231023

10241024
// This type is just a bag-of-bits so it's up to the caller to figure out how

0 commit comments

Comments
 (0)