Skip to content

Commit 1b13484

Browse files
committed
Wasmtime+Cranelift: strip out some dead x86-32 code.
I was recently pointed to fastly/Viceroy#200 where it seems some folks are trying to compile Wasmtime (via Viceroy) for Windows x86-32 and the failures may not be loud enough. I've tried to reproduce this cross-compiling to i686-pc-windows-gnu from Linux and hit build failures (as expected) in several places. Nevertheless, while trying to discern what others may be attempting, I noticed some dead x86-32-specific code in our repo, and figured it would be a good idea to clean this up. Otherwise, it (i) sends some mixed messages -- "hey look, this codebase does support x86-32" -- and (ii) keeps untested code around, which is generally not great. This PR removes x86-32-specific cases in traphandlers and unwind code, and Cranelift's native feature detection. It adds helpful compile-error messages in a few cases. If we ever support x86-32 (contributors welcome! The big missing piece is Cranelift support; see #1980), these compile errors and git history should be enough to recover any knowledge we are now encoding in the source. I left the x86-32 support in `wasmtime-fiber` alone because that seems like a bit of a special case -- foundation library, separate from the rest of Wasmtime, with specific care to provide a (presumably working) full 32-bit version.
1 parent 3e5938e commit 1b13484

File tree

6 files changed

+18
-43
lines changed

6 files changed

+18
-43
lines changed

cranelift/native/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ pub fn builder_with_options(infer_native_flags: bool) -> Result<isa::Builder, &'
4646
isa::LookupError::Unsupported => "unsupported architecture",
4747
})?;
4848

49-
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
49+
#[cfg(any(target_arch = "x86"))]
50+
{
51+
compile_error!("Unsupported architecture");
52+
}
53+
54+
#[cfg(any(target_arch = "x86_64"))]
5055
{
5156
use cranelift_codegen::settings::Configurable;
5257

crates/jit/src/unwind.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ cfg_if::cfg_if! {
22
if #[cfg(all(windows, any(target_arch = "x86_64", target_arch = "aarch64")))] {
33
mod winx64;
44
pub use self::winx64::*;
5-
} else if #[cfg(all(windows, target_arch = "x86"))] {
6-
mod winx32;
7-
pub use self::winx32::*;
85
} else if #[cfg(unix)] {
96
mod systemv;
107
pub use self::systemv::*;

crates/jit/src/unwind/winx32.rs

Lines changed: 0 additions & 20 deletions
This file was deleted.

crates/runtime/src/traphandlers/macos.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ mod mach_addons {
120120

121121
pub static ARM_THREAD_STATE64: thread_state_flavor_t = 6;
122122

123-
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
123+
#[cfg(target_arch = "x86_64")]
124124
pub static THREAD_STATE_NONE: thread_state_flavor_t = 13;
125125
#[cfg(target_arch = "aarch64")]
126126
pub static THREAD_STATE_NONE: thread_state_flavor_t = 5;

crates/runtime/src/traphandlers/unix.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,24 @@ pub unsafe fn platform_init() {
4747
register(&mut PREV_SIGILL, libc::SIGILL);
4848

4949
// x86 and s390x use SIGFPE to report division by zero
50-
if cfg!(target_arch = "x86") || cfg!(target_arch = "x86_64") || cfg!(target_arch = "s390x") {
50+
if cfg!(target_arch = "x86_64") || cfg!(target_arch = "s390x") {
5151
register(&mut PREV_SIGFPE, libc::SIGFPE);
5252
}
5353

5454
// Sometimes we need to handle SIGBUS too:
55-
// - On ARM, handle Unaligned Accesses.
5655
// - On Darwin, guard page accesses are raised as SIGBUS.
57-
if cfg!(target_arch = "arm") || cfg!(target_os = "macos") || cfg!(target_os = "freebsd") {
56+
if cfg!(target_os = "macos") || cfg!(target_os = "freebsd") {
5857
register(&mut PREV_SIGBUS, libc::SIGBUS);
5958
}
59+
60+
#[cfg(target_arch = "x86")]
61+
{
62+
compile_error!("x86-32 unsupported; may need SIGFPE handler registered");
63+
}
64+
#[cfg(target_arch = "arm")]
65+
{
66+
compile_error!("ARM32 unsupported; may need SIGBUS handler registered");
67+
}
6068
}
6169

6270
unsafe extern "C" fn trap_handler(
@@ -172,12 +180,6 @@ unsafe fn get_pc_and_fp(cx: *mut libc::c_void, _signum: libc::c_int) -> (*const
172180
cx.uc_mcontext.gregs[libc::REG_RIP as usize] as *const u8,
173181
cx.uc_mcontext.gregs[libc::REG_RBP as usize] as usize
174182
)
175-
} else if #[cfg(all(target_os = "linux", target_arch = "x86"))] {
176-
let cx = &*(cx as *const libc::ucontext_t);
177-
(
178-
cx.uc_mcontext.gregs[libc::REG_EIP as usize] as *const u8,
179-
cx.uc_mcontext.gregs[libc::REG_EBP as usize] as usize,
180-
)
181183
} else if #[cfg(all(any(target_os = "linux", target_os = "android"), target_arch = "aarch64"))] {
182184
let cx = &*(cx as *const libc::ucontext_t);
183185
(
@@ -210,12 +212,6 @@ unsafe fn get_pc_and_fp(cx: *mut libc::c_void, _signum: libc::c_int) -> (*const
210212
(*cx.uc_mcontext).__ss.__rip as *const u8,
211213
(*cx.uc_mcontext).__ss.__rbp as usize,
212214
)
213-
} else if #[cfg(all(target_os = "macos", target_arch = "x86"))] {
214-
let cx = &*(cx as *const libc::ucontext_t);
215-
(
216-
(*cx.uc_mcontext).__ss.__eip as *const u8,
217-
(*cx.uc_mcontext).__ss.__ebp as usize,
218-
)
219215
} else if #[cfg(all(target_os = "macos", target_arch = "aarch64"))] {
220216
let cx = &*(cx as *const libc::ucontext_t);
221217
(

crates/runtime/src/traphandlers/windows.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ unsafe extern "system" fn exception_handler(exception_info: *mut EXCEPTION_POINT
5555
if #[cfg(target_arch = "x86_64")] {
5656
let ip = (*(*exception_info).ContextRecord).Rip as *const u8;
5757
let fp = (*(*exception_info).ContextRecord).Rbp as usize;
58-
} else if #[cfg(target_arch = "x86")] {
59-
let ip = (*(*exception_info).ContextRecord).Eip as *const u8;
60-
let fp = (*(*exception_info).ContextRecord).Ebp as usize;
6158
} else if #[cfg(target_arch = "aarch64")] {
6259
let ip = (*(*exception_info).ContextRecord).Pc as *const u8;
6360
let fp = (*(*exception_info).ContextRecord).Anonymous.Anonymous.Fp as usize;

0 commit comments

Comments
 (0)