From 3dc4a731f23da97c8b40b41b6d7f16ce1ee4d5dd Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Mon, 1 Aug 2022 17:18:41 +0200 Subject: [PATCH 1/5] Fixed how traps information are retrieved (for #2847) --- lib/compiler/src/engine/trap/frame_info.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/compiler/src/engine/trap/frame_info.rs b/lib/compiler/src/engine/trap/frame_info.rs index d71c1aad5a8..0dc5d7494db 100644 --- a/lib/compiler/src/engine/trap/frame_info.rs +++ b/lib/compiler/src/engine/trap/frame_info.rs @@ -65,8 +65,10 @@ impl ModuleInfoFrameInfo { /// Gets a function given a pc fn function_info(&self, pc: usize) -> Option<&FunctionInfo> { - let (end, func) = self.functions.range(pc..).next()?; - if func.start <= pc && pc <= *end { + // the +1 is to avoid selecting an interval that end with pc, + // as end should be non-inclusive + let (end, func) = self.functions.range((pc + 1)..).next()?; + if func.start <= pc && pc < *end { Some(func) } else { None @@ -151,8 +153,10 @@ impl GlobalFrameInfo { /// Gets a module given a pc fn module_info(&self, pc: usize) -> Option<&ModuleInfoFrameInfo> { - let (end, module_info) = self.ranges.range(pc..).next()?; - if module_info.start <= pc && pc <= *end { + // the +1 is to avoid selecting an interval that end with pc, + // as end should be non-inclusive + let (end, module_info) = self.ranges.range((pc + 1)..).next()?; + if module_info.start <= pc && pc < *end { Some(module_info) } else { None From 6d8c1ac6fabadddeb921396ba7c424154c86bbea Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Mon, 1 Aug 2022 17:19:24 +0200 Subject: [PATCH 2/5] Adjusted ignores, as cranelift+aarch64 trap tracking is correct now (but still not llvm) --- tests/ignores.txt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/ignores.txt b/tests/ignores.txt index 39f9f2f9ab2..fe832d4fcbc 100644 --- a/tests/ignores.txt +++ b/tests/ignores.txt @@ -6,22 +6,18 @@ singlepass spec::simd # Singlepass doesn't support yet SIMD (no one asked for th ## Unwinding is not properly implemented in Singlepass # Needs investigation singlepass+aarch64+macos traps::test_trap_trace -cranelift+aarch64 traps::test_trap_trace +llvm+aarch64 traps::test_trap_trace singlepass+aarch64+macos traps::test_trap_stack_overflow # Need to investigate -cranelift+aarch64 traps::test_trap_stack_overflow # Need to investigate singlepass+aarch64+macos traps::trap_display_pretty llvm traps::trap_display_pretty -cranelift+aarch64 traps::trap_display_pretty singlepass+aarch64+macos traps::trap_display_multi_module llvm traps::trap_display_multi_module -cranelift+aarch64 traps::trap_display_multi_module windows+singlepass traps::trap_display_multi_module singlepass traps::call_signature_mismatch # Need to investigate, get foo (a[0]:0x33) instead of 0x30 for inderect call llvm traps::call_signature_mismatch macos+aarch64 traps::call_signature_mismatch singlepass+aarch64+macos traps::start_trap_pretty llvm traps::start_trap_pretty -cranelift+aarch64 traps::start_trap_pretty # Also neither LLVM nor Cranelift currently implement stack probing on AArch64. # https://github.com/wasmerio/wasmer/issues/2808 From a070f578ff01f2a7335b95b3b64e960d47d41c70 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Mon, 1 Aug 2022 17:27:02 +0200 Subject: [PATCH 3/5] Pretty printing traps on cranelift+aarch64+macos is still broken --- tests/ignores.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/ignores.txt b/tests/ignores.txt index fe832d4fcbc..19d28fbf16f 100644 --- a/tests/ignores.txt +++ b/tests/ignores.txt @@ -6,18 +6,22 @@ singlepass spec::simd # Singlepass doesn't support yet SIMD (no one asked for th ## Unwinding is not properly implemented in Singlepass # Needs investigation singlepass+aarch64+macos traps::test_trap_trace +cranelift+aarch64+macos traps::test_trap_trace llvm+aarch64 traps::test_trap_trace singlepass+aarch64+macos traps::test_trap_stack_overflow # Need to investigate singlepass+aarch64+macos traps::trap_display_pretty llvm traps::trap_display_pretty +cranelift+aarch64+macos traps::trap_display_pretty singlepass+aarch64+macos traps::trap_display_multi_module llvm traps::trap_display_multi_module +cranelift+aarch64+macos traps::trap_display_multi_module windows+singlepass traps::trap_display_multi_module singlepass traps::call_signature_mismatch # Need to investigate, get foo (a[0]:0x33) instead of 0x30 for inderect call llvm traps::call_signature_mismatch macos+aarch64 traps::call_signature_mismatch singlepass+aarch64+macos traps::start_trap_pretty llvm traps::start_trap_pretty +cranelift+aarch64+macos traps::start_trap_pretty # Also neither LLVM nor Cranelift currently implement stack probing on AArch64. # https://github.com/wasmerio/wasmer/issues/2808 From b9c34c736b034fb0e916dd72ebc80bada476b583 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Tue, 2 Aug 2022 09:31:25 +0200 Subject: [PATCH 4/5] Refactored frame_informations so end of ranges is correct --- lib/compiler/src/engine/trap/frame_info.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/compiler/src/engine/trap/frame_info.rs b/lib/compiler/src/engine/trap/frame_info.rs index 0dc5d7494db..e74c4373433 100644 --- a/lib/compiler/src/engine/trap/frame_info.rs +++ b/lib/compiler/src/engine/trap/frame_info.rs @@ -65,10 +65,8 @@ impl ModuleInfoFrameInfo { /// Gets a function given a pc fn function_info(&self, pc: usize) -> Option<&FunctionInfo> { - // the +1 is to avoid selecting an interval that end with pc, - // as end should be non-inclusive - let (end, func) = self.functions.range((pc + 1)..).next()?; - if func.start <= pc && pc < *end { + let (end, func) = self.functions.range(pc..).next()?; + if func.start <= pc && pc <= *end { Some(func) } else { None @@ -153,10 +151,8 @@ impl GlobalFrameInfo { /// Gets a module given a pc fn module_info(&self, pc: usize) -> Option<&ModuleInfoFrameInfo> { - // the +1 is to avoid selecting an interval that end with pc, - // as end should be non-inclusive - let (end, module_info) = self.ranges.range((pc + 1)..).next()?; - if module_info.start <= pc && pc < *end { + let (end, module_info) = self.ranges.range(pc..).next()?; + if module_info.start <= pc && pc <= *end { Some(module_info) } else { None @@ -207,7 +203,7 @@ pub fn register( ) in finished_functions.iter() { let start = **start as usize; - let end = start + len; + let end = start + len - 1; min = cmp::min(min, start); max = cmp::max(max, end); let func = FunctionInfo { From 7ad24fc29eb27738ed410c4c8962c9b31cfbd8db Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Tue, 2 Aug 2022 09:46:37 +0200 Subject: [PATCH 5/5] Added comment to track the -1 --- lib/compiler/src/engine/trap/frame_info.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/compiler/src/engine/trap/frame_info.rs b/lib/compiler/src/engine/trap/frame_info.rs index e74c4373433..65324014cfd 100644 --- a/lib/compiler/src/engine/trap/frame_info.rs +++ b/lib/compiler/src/engine/trap/frame_info.rs @@ -203,6 +203,7 @@ pub fn register( ) in finished_functions.iter() { let start = **start as usize; + // end is "last byte" of the function code let end = start + len - 1; min = cmp::min(min, start); max = cmp::max(max, end);