From 2bcc13a9e28c92f68cfaf893afddf5134bf2dd39 Mon Sep 17 00:00:00 2001 From: Zhang Junyang Date: Wed, 19 Mar 2025 14:01:10 +0800 Subject: [PATCH] `force-unwind-tables=yes` instead of `panic=unwind` --- Cargo.toml | 4 ++++ osdk/src/commands/build/mod.rs | 5 ++--- osdk/src/commands/test.rs | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 04efe78a8..602ddf675 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,8 +50,12 @@ allow_attributes = "warn" # Cargo only looks at the profile settings # in the Cargo.toml manifest at the root of the workspace +[profile.dev] +panic = "unwind" + [profile.release] lto = "thin" +panic = "unwind" # Release profile configuration with Link Time Optimization (LTO) enabled. # diff --git a/osdk/src/commands/build/mod.rs b/osdk/src/commands/build/mod.rs index c862ccbd4..1b241f294 100644 --- a/osdk/src/commands/build/mod.rs +++ b/osdk/src/commands/build/mod.rs @@ -207,9 +207,8 @@ fn build_kernel_elf( &rustc_linker_script_arg, "-C relocation-model=static", "-C relro-level=off", - // We do not really allow unwinding except for kernel testing. However, we need to specify - // this to show backtraces when panicking. - "-C panic=unwind", + // Even if we disabled unwinding on panic, we need to specify this to show backtraces. + "-C force-unwind-tables=yes", // This is to let rustc know that "cfg(ktest)" is our well-known configuration. // See the [Rust Blog](https://blog.rust-lang.org/2024/05/06/check-cfg.html) for details. "--check-cfg cfg(ktest)", diff --git a/osdk/src/commands/test.rs b/osdk/src/commands/test.rs index 701351acb..aa0d2a612 100644 --- a/osdk/src/commands/test.rs +++ b/osdk/src/commands/test.rs @@ -98,7 +98,7 @@ pub static KTEST_CRATE_WHITELIST: Option<&[&str]> = Some(&{:#?}); &cargo_target_directory, config, ActionChoice::Test, - &["--cfg ktest"], + &["--cfg ktest", "-C panic=unwind"], ); std::env::remove_var("RUSTFLAGS"); drop(dir_guard);