From 02a29af08c66ea9043052f79ef48896c14e569c7 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Sat, 5 Aug 2023 20:41:26 +0800 Subject: [PATCH 1/2] cargo: support building as part of libstd Support using `unwinding` as a backend for the libstd `unwind` crate. This will enable unwinding support for new targets while allowing us to continue to use `libunwind` from llvm for supported targets. Signed-off-by: Sean Cross --- Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index d84a5bc..f0ec722 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,8 @@ members = ["cdylib", "example"] gimli = { version = "0.26.1", default-features = false, features = ["read-core"] } libc = { version = "0.2", optional = true } spin = { version = "0.9.8", optional = true, default-features = false, features = ["mutex", "spin_mutex"] } +core = { version = '1.0.0', optional = true, package = 'rustc-std-workspace-core' } +compiler_builtins = { version = "0.1.2", optional = true } [features] alloc = [] @@ -36,6 +38,7 @@ panic-handler = ["print", "panic"] panic-handler-dummy = [] system-alloc = [] default = ["unwinder", "dwarf-expr", "hide-trace", "fde-phdr-dl", "fde-registry"] +rustc-dep-of-std = ["core", "gimli/rustc-dep-of-std", "compiler_builtins"] [profile.release] debug = true From caab98753f5bd3f8b0d4ca388e26c800fb5c55f0 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Sat, 5 Aug 2023 20:44:54 +0800 Subject: [PATCH 2/2] find_fde: make `text_base` optional No platforms currently use relative addressing. Make this parameter optional in order to support targets where this value is not available. Signed-off-by: Sean Cross --- src/unwinder/find_fde/custom.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/unwinder/find_fde/custom.rs b/src/unwinder/find_fde/custom.rs index cf9883d..25da562 100644 --- a/src/unwinder/find_fde/custom.rs +++ b/src/unwinder/find_fde/custom.rs @@ -22,7 +22,7 @@ pub unsafe trait EhFrameFinder { } pub struct FrameInfo { - pub text_base: usize, + pub text_base: Option, pub kind: FrameInfoKind, } @@ -102,13 +102,14 @@ fn find_fde(eh_frame_finder: &T, pc: usize) -> Option fn find_fde_with_eh_frame_hdr( pc: usize, - text_base: usize, + text_base: Option, eh_frame_hdr: usize, ) -> Option { unsafe { - let bases = BaseAddresses::default() - .set_text(text_base as _) - .set_eh_frame_hdr(eh_frame_hdr as _); + let mut bases = BaseAddresses::default().set_eh_frame_hdr(eh_frame_hdr as _); + if let Some(text_base) = text_base { + bases = bases.set_text(text_base as _); + } let eh_frame_hdr = EhFrameHdr::new( get_unlimited_slice(eh_frame_hdr as usize as _), NativeEndian, @@ -145,11 +146,16 @@ fn find_fde_with_eh_frame_hdr( } } -fn find_fde_with_eh_frame(pc: usize, text_base: usize, eh_frame: usize) -> Option { +fn find_fde_with_eh_frame( + pc: usize, + text_base: Option, + eh_frame: usize, +) -> Option { unsafe { - let bases = BaseAddresses::default() - .set_text(text_base as _) - .set_eh_frame(eh_frame as _); + let mut bases = BaseAddresses::default().set_eh_frame(eh_frame as _); + if let Some(text_base) = text_base { + bases = bases.set_text(text_base as _); + } let eh_frame = EhFrame::new(get_unlimited_slice(eh_frame as _), NativeEndian); if let Ok(fde) = eh_frame.fde_for_address(&bases, pc as _, EhFrame::cie_from_offset) {