Skip to content

Don't use mmap on macOS #302

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

Merged
merged 11 commits into from
Mar 10, 2020
4 changes: 3 additions & 1 deletion crates/backtrace-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ fn main() {

// `mmap` does not exist on Windows, so we use
// the less efficient `read`-based code.
if target.contains("windows") {
// Using `mmap` on macOS causes weird isseus - see
// https://github.com/rust-lang/rust/pull/45866
if target.contains("windows") || target.contains("darwin") {
build.file("src/libbacktrace/read.c");
} else {
build.file("src/libbacktrace/mmapio.c");
Expand Down
33 changes: 33 additions & 0 deletions tests/macos_frames.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copied from https://github.com/rust-lang/rust/blob/2cb0b8582ebbf9784db9cec06fff517badbf4553/src/test/ui/issues/issue-45731.rs
// This needs to go in its own file, since it modifies the dSYM
// for the entire test
#[test]
#[cfg(target_os = "macos")]
fn simple_test() {
use std::{env, fs, panic};

// Find our dSYM and replace the DWARF binary with an empty file
let mut dsym_path = env::current_exe().unwrap();
let executable_name = dsym_path.file_name().unwrap().to_str().unwrap().to_string();
assert!(dsym_path.pop()); // Pop executable
dsym_path.push(format!(
"{}.dSYM/Contents/Resources/DWARF/{0}",
executable_name
));
{
let _ = fs::OpenOptions::new()
.read(false)
.write(true)
.truncate(true)
.create(false)
.open(&dsym_path)
.unwrap();
}

env::set_var("RUST_BACKTRACE", "1");

// We don't need to die of panic, just trigger a backtrace
let _ = panic::catch_unwind(|| {
assert!(false);
});
}