diff --git a/runtime/src/abort.rs b/runtime/src/abort.rs new file mode 100644 index 0000000..51e39c8 --- /dev/null +++ b/runtime/src/abort.rs @@ -0,0 +1,25 @@ +//! Abort shim for the Fortanix SGX target. +//! +//! Why this exists: +//! +//! Some native libraries assume the standard C function `abort()` is +//! available. In our case, the `wasm3` runtime (via `wasm3-sys`) calls +//! `abort()` from C code (`m3_core.c` -> `m3_Abort`). +//! +//! When linking for `x86_64-fortanix-unknown-sgx`, there is no libc +//! providing the `abort` symbol, so linking fails with: +//! +//! rust-lld: error: undefined symbol: abort +//! +//! This shim exports a C-compatible symbol named `abort` and forwards +//! execution to Rust's internal abort routine (`__rust_abort`), which +//! terminates the enclave/process immediately and never returns. + +#[no_mangle] +pub extern "C" fn abort() -> ! { + extern "C" { + fn __rust_abort() -> !; + } + + unsafe { __rust_abort() } +} diff --git a/runtime/src/main.rs b/runtime/src/main.rs index c3912eb..3cea076 100644 --- a/runtime/src/main.rs +++ b/runtime/src/main.rs @@ -1,5 +1,8 @@ use oasis_runtime_sdk::Runtime; +#[cfg(all(target_env = "sgx", target_vendor = "fortanix"))] +mod abort; + fn main() { cipher_paratime::Runtime::start(); }