A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Debug: use libcall-based traps on Pulley. (#11982)
Chris Fallin1e0da2c8a6ba
diff --git a/cranelift/codegen/src/isa/pulley_shared/lower.isle b/cranelift/codegen/src/isa/pulley_shared/lower.isleindex 7cde5f2027..0373d45157 100644--- a/cranelift/codegen/src/isa/pulley_shared/lower.isle+++ b/cranelift/codegen/src/isa/pulley_shared/lower.isle@@ -1341,6 +1341,18 @@(rule (lower (has_type $I64 (uadd_overflow_trap a b tc)))(pulley_xadd64_uoverflow_trap a b tc))+;;;; Rules for `uadd_overflow` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;++(rule (lower (has_type $I32 (uadd_overflow a b)))+ (let ((sum XReg (pulley_xadd32 a b))+ (is_overflow XReg (pulley_xult32 sum a)))+ (output_pair sum is_overflow)))++(rule (lower (has_type $I64 (uadd_overflow a b)))+ (let ((sum XReg (pulley_xadd64 a b))+ (is_overflow XReg (pulley_xult64 sum a)))+ (output_pair sum is_overflow)))+;;;; Rules for `select` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;(rule 0 (lower (has_type (ty_int (fits_in_32 _)) (select c a b)))diff --git a/cranelift/filetests/filetests/runtests/uadd_overflow.clif b/cranelift/filetests/filetests/runtests/uadd_overflow.clifindex 9fc6a6d8dd..ca2fb3d2fc 100644--- a/cranelift/filetests/filetests/runtests/uadd_overflow.clif+++ b/cranelift/filetests/filetests/runtests/uadd_overflow.clif@@ -5,25 +5,10 @@ target aarch64set enable_multi_ret_implicit_srettarget x86_64target riscv64--function %uaddof_i128(i128, i128) -> i128, i8 {-block0(v0: i128,v1: i128):- v2, v3 = uadd_overflow v0, v1- return v2, v3-}-; run: %uaddof_i128(0, 0) == [0, 0]-; run: %uaddof_i128(1, 0) == [1, 0]-; run: %uaddof_i128(1, 1) == [2, 0]-; run: %uaddof_i128(1, -1) == [0, 1]-; run: %uaddof_i128(0xFFFFFFFF_FFFFFFFF_00000000_00000000, 0x00000000_00000000_FFFFFFFF_FFFFFFFF) == [-1, 0]-; run: %uaddof_i128(0x00000000_00000000_FFFFFFFF_FFFFFFFF, 1) == [0x1_00000000_00000000, 0]-; run: %uaddof_i128(-1, 1) == [0, 1]-; run: %uaddof_i128(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF) == [-2, 0]-; run: %uaddof_i128(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x80000000_00000000_00000000_00000000) == [-1, 0]-; run: %uaddof_i128(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x80000000_00000000_00000000_00000001) == [0, 1]-; run: %uaddof_i128(0x01234567_89ABCDEF_01234567_89ABCDEF, 0xFEDCBA98_76543210_FEDCBA98_76543210) == [-1, 0]-; run: %uaddof_i128(0x06060606_06060606_A00A00A0_0A00A00A, 0x30303030_30303030_0BB0BB0B_B0BB0BB0) == [0x36363636_36363636_ABBABBAB_BABBABBA, 0]-; run: %uaddof_i128(0xC0FFEEEE_C0FFEEEE_C0FFEEEE_C0FFEEEE, 0x1DCB1111_1DCB1111_1DCB1111_1DCB1111) == [0xDECAFFFF_DECAFFFF_DECAFFFF_DECAFFFF, 0]+target pulley32+target pulley32be+target pulley64+target pulley64befunction %uaddof_i64(i64, i64) -> i64, i8 {block0(v0: i64,v1: i64):diff --git a/cranelift/filetests/filetests/runtests/uadd_overflow_128.clif b/cranelift/filetests/filetests/runtests/uadd_overflow_128.clifnew file mode 100644index 0000000000..aff84a7188--- /dev/null+++ b/cranelift/filetests/filetests/runtests/uadd_overflow_128.clif@@ -0,0 +1,26 @@+test interpret+test run+set enable_llvm_abi_extensions=true+target aarch64+set enable_multi_ret_implicit_sret+target x86_64+target riscv64++function %uaddof_i128(i128, i128) -> i128, i8 {+block0(v0: i128,v1: i128):+ v2, v3 = uadd_overflow v0, v1+ return v2, v3+}+; run: %uaddof_i128(0, 0) == [0, 0]+; run: %uaddof_i128(1, 0) == [1, 0]+; run: %uaddof_i128(1, 1) == [2, 0]+; run: %uaddof_i128(1, -1) == [0, 1]+; run: %uaddof_i128(0xFFFFFFFF_FFFFFFFF_00000000_00000000, 0x00000000_00000000_FFFFFFFF_FFFFFFFF) == [-1, 0]+; run: %uaddof_i128(0x00000000_00000000_FFFFFFFF_FFFFFFFF, 1) == [0x1_00000000_00000000, 0]+; run: %uaddof_i128(-1, 1) == [0, 1]+; run: %uaddof_i128(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF) == [-2, 0]+; run: %uaddof_i128(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x80000000_00000000_00000000_00000000) == [-1, 0]+; run: %uaddof_i128(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x80000000_00000000_00000000_00000001) == [0, 1]+; run: %uaddof_i128(0x01234567_89ABCDEF_01234567_89ABCDEF, 0xFEDCBA98_76543210_FEDCBA98_76543210) == [-1, 0]+; run: %uaddof_i128(0x06060606_06060606_A00A00A0_0A00A00A, 0x30303030_30303030_0BB0BB0B_B0BB0BB0) == [0x36363636_36363636_ABBABBAB_BABBABBA, 0]+; run: %uaddof_i128(0xC0FFEEEE_C0FFEEEE_C0FFEEEE_C0FFEEEE, 0x1DCB1111_1DCB1111_1DCB1111_1DCB1111) == [0xDECAFFFF_DECAFFFF_DECAFFFF_DECAFFFF, 0]diff --git a/crates/cranelift/src/func_environ.rs b/crates/cranelift/src/func_environ.rsindex 05282765f6..e5196037d0 100644--- a/crates/cranelift/src/func_environ.rs+++ b/crates/cranelift/src/func_environ.rs@@ -4488,11 +4488,14 @@ impl FuncEnvironment<'_> {/// Returns whether it's acceptable to have CLIF instructions natively trap,/// such as division-by-zero.///- /// This enabled if `signals_based_traps` is `true` or on Pulley- /// unconditionally since Pulley doesn't use hardware-based traps in its- /// runtime.+ /// This is enabled if `signals_based_traps` is `true` or on+ /// Pulley unconditionally since Pulley doesn't use hardware-based+ /// traps in its runtime. However, if guest debugging is enabled,+ /// then we cannot rely on Pulley traps and still need a libcall+ /// to gain proper ownership of the store in the runtime's+ /// debugger hooks.pub fn clif_instruction_traps_enabled(&self) -> bool {- self.tunables.signals_based_traps || self.is_pulley()+ self.tunables.signals_based_traps || (self.is_pulley() && !self.tunables.debug_guest)}/// Returns whether loads from the null address are allowed as signals ofdiff --git a/tests/all/debug.rs b/tests/all/debug.rsindex 904b0b33c6..31096a4215 100644--- a/tests/all/debug.rs+++ b/tests/all/debug.rs@@ -363,12 +363,6 @@ async fn caught_exception_events() -> anyhow::Result<()> {#[tokio::test]#[cfg_attr(miri, ignore)]-#[cfg(any(- target_arch = "x86_64",- target_arch = "aarch64",- target_arch = "s390x",- target_arch = "riscv64"-))]async fn hostcall_trap_events() -> anyhow::Result<()> {let _ = env_logger::try_init();