- Notifications
You must be signed in to change notification settings - Fork 13.9k
Ensure the personality does not panic #148105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -10,8 +10,6 @@ | |
| #[cfg(test)] | ||
| mod tests; | ||
| | ||
| pub mod eh; | ||
| | ||
| pub struct DwarfReader { | ||
| pub ptr: *const u8, | ||
| } | ||
| | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| [package] | ||
| name = "add" | ||
| version = "0.1.0" | ||
| edition = "2024" | ||
| | ||
| [lib] | ||
| path = "lib.rs" | ||
| crate-type = ["cdylib"] | ||
| | ||
| [profile.release] | ||
| lto = "fat" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #![crate_type = "cdylib"] | ||
| | ||
| pub extern "C" fn add(a: u64, b: u64) -> u64 { | ||
| a + b | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // This ensures that a cdylib that uses std and panic=unwind but does not | ||
| // have any panics itself will not have *any* panic-related code in the final | ||
| // binary, at least when using fat LTO | ||
| // (since all the necessary nounwind propagation requires fat LTO). | ||
| // | ||
| // This code used to be pulled in via a landing pad in the personality function, | ||
| // (since that is `extern "C"` and therefore panics if something unwinds), so | ||
| // if this failed because you modified the personality function, ensure it contains | ||
| // no potentially unwinding calls. | ||
| | ||
| use run_make_support::{cargo, dynamic_lib_name, llvm_nm, path, rustc, target}; | ||
| | ||
| fn main() { | ||
| let target_dir = path("target"); | ||
| | ||
| // We use build-std to ensure that the sysroot does not have debug assertions, | ||
| // as this doesn't work with debug assertions. | ||
| cargo() | ||
| .args(&[ | ||
| "build", | ||
| "--manifest-path", | ||
| "Cargo.toml", | ||
| "--release", | ||
| "-Zbuild-std=std", | ||
| "--target", | ||
| &target(), | ||
| ]) | ||
| .env("CARGO_TARGET_DIR", &target_dir) | ||
| .env("RUSTC_BOOTSTRAP", "1") | ||
| .run(); | ||
| | ||
| let output_path = target_dir.join(target()).join("release").join(dynamic_lib_name("add")); | ||
| | ||
| llvm_nm() | ||
| .input(output_path) | ||
| .run() | ||
| // a collection of panic-related strings. if this appears in the output | ||
| // for other reasons than having panic symbols, I am sorry. | ||
| Comment on lines +37 to +38 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, but what if these symbols aren't found for reasons other than not having panic symbols? E.g. this test gets subtly broken after a refactor or something else changes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems unlikely to me that all of these symbols would disappear for a reason other than panic machinery being gone, especially the "panic" one. But I'd be open to better suggestions for how to write it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put a panic behind a cfg switch and compile it twice? Then check for presence and absence respectively? | ||
| .assert_stdout_not_contains("panic") | ||
| .assert_stdout_not_contains("addr2line") | ||
| .assert_stdout_not_contains("backtrace") | ||
| .assert_stdout_not_contains("gimli"); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this not work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does, but I prefer the self style because it makes it explicit that it's not a crate but a module, and makes rustfmt group it as such