Skip to content

Commit

Permalink
Wasmtime+Cranelift: strip out some dead x86-32 code.
Browse files Browse the repository at this point in the history
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 bytecodealliance#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.
  • Loading branch information
cfallin committed Nov 8, 2022
1 parent 3e5938e commit cc2946f
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 43 deletions.
7 changes: 6 additions & 1 deletion cranelift/native/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ pub fn builder_with_options(infer_native_flags: bool) -> Result<isa::Builder, &'
isa::LookupError::Unsupported => "unsupported architecture",
})?;

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86")]
{
compile_error!("Unsupported architecture");
}

#[cfg(target_arch = "x86_64")]
{
use cranelift_codegen::settings::Configurable;

Expand Down
3 changes: 0 additions & 3 deletions crates/jit/src/unwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ cfg_if::cfg_if! {
if #[cfg(all(windows, any(target_arch = "x86_64", target_arch = "aarch64")))] {
mod winx64;
pub use self::winx64::*;
} else if #[cfg(all(windows, target_arch = "x86"))] {
mod winx32;
pub use self::winx32::*;
} else if #[cfg(unix)] {
mod systemv;
pub use self::systemv::*;
Expand Down
20 changes: 0 additions & 20 deletions crates/jit/src/unwind/winx32.rs

This file was deleted.

2 changes: 1 addition & 1 deletion crates/runtime/src/traphandlers/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ mod mach_addons {

pub static ARM_THREAD_STATE64: thread_state_flavor_t = 6;

#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
#[cfg(target_arch = "x86_64")]
pub static THREAD_STATE_NONE: thread_state_flavor_t = 13;
#[cfg(target_arch = "aarch64")]
pub static THREAD_STATE_NONE: thread_state_flavor_t = 5;
Expand Down
26 changes: 11 additions & 15 deletions crates/runtime/src/traphandlers/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,24 @@ pub unsafe fn platform_init() {
register(&mut PREV_SIGILL, libc::SIGILL);

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

// Sometimes we need to handle SIGBUS too:
// - On ARM, handle Unaligned Accesses.
// - On Darwin, guard page accesses are raised as SIGBUS.
if cfg!(target_arch = "arm") || cfg!(target_os = "macos") || cfg!(target_os = "freebsd") {
if cfg!(target_os = "macos") || cfg!(target_os = "freebsd") {
register(&mut PREV_SIGBUS, libc::SIGBUS);
}

#[cfg(target_arch = "x86")]
{
compile_error!("x86-32 unsupported; may need SIGFPE handler registered");
}
#[cfg(target_arch = "arm")]
{
compile_error!("ARM32 unsupported; may need SIGBUS handler registered");
}
}

unsafe extern "C" fn trap_handler(
Expand Down Expand Up @@ -172,12 +180,6 @@ unsafe fn get_pc_and_fp(cx: *mut libc::c_void, _signum: libc::c_int) -> (*const
cx.uc_mcontext.gregs[libc::REG_RIP as usize] as *const u8,
cx.uc_mcontext.gregs[libc::REG_RBP as usize] as usize
)
} else if #[cfg(all(target_os = "linux", target_arch = "x86"))] {
let cx = &*(cx as *const libc::ucontext_t);
(
cx.uc_mcontext.gregs[libc::REG_EIP as usize] as *const u8,
cx.uc_mcontext.gregs[libc::REG_EBP as usize] as usize,
)
} else if #[cfg(all(any(target_os = "linux", target_os = "android"), target_arch = "aarch64"))] {
let cx = &*(cx as *const libc::ucontext_t);
(
Expand Down Expand Up @@ -210,12 +212,6 @@ unsafe fn get_pc_and_fp(cx: *mut libc::c_void, _signum: libc::c_int) -> (*const
(*cx.uc_mcontext).__ss.__rip as *const u8,
(*cx.uc_mcontext).__ss.__rbp as usize,
)
} else if #[cfg(all(target_os = "macos", target_arch = "x86"))] {
let cx = &*(cx as *const libc::ucontext_t);
(
(*cx.uc_mcontext).__ss.__eip as *const u8,
(*cx.uc_mcontext).__ss.__ebp as usize,
)
} else if #[cfg(all(target_os = "macos", target_arch = "aarch64"))] {
let cx = &*(cx as *const libc::ucontext_t);
(
Expand Down
3 changes: 0 additions & 3 deletions crates/runtime/src/traphandlers/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ unsafe extern "system" fn exception_handler(exception_info: *mut EXCEPTION_POINT
if #[cfg(target_arch = "x86_64")] {
let ip = (*(*exception_info).ContextRecord).Rip as *const u8;
let fp = (*(*exception_info).ContextRecord).Rbp as usize;
} else if #[cfg(target_arch = "x86")] {
let ip = (*(*exception_info).ContextRecord).Eip as *const u8;
let fp = (*(*exception_info).ContextRecord).Ebp as usize;
} else if #[cfg(target_arch = "aarch64")] {
let ip = (*(*exception_info).ContextRecord).Pc as *const u8;
let fp = (*(*exception_info).ContextRecord).Anonymous.Anonymous.Fp as usize;
Expand Down

0 comments on commit cc2946f

Please sign in to comment.