Skip to content

Fix debuginfo for machO #759

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 3 commits into from
Oct 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,18 @@ features = ["compression", "read", "std"] # We don't need WASM support
#[patch.crates-io]
#gimli = { path = "../" }

[patch.crates-io]
# FIXME switch back to crates.io once gimli-rs/object#133 is published
object = { git = "https://github.com/gimli-rs/object.git" }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
cranelift-simplejit = { git = "https://github.com/CraneStation/cranelift.git" }

[profile.dev]
# By compiling dependencies with optimizations, performing tests gets much faster.
opt-level = 3

[profile.dev.overrides."rustc_codegen_cranelift"]
[profile.dev.package.rustc_codegen_cranelift]
# Disabling optimizations for cg_clif itself makes compilation after a change faster.
opt-level = 0

Expand All @@ -62,14 +66,14 @@ opt-level = 0
opt-level = 0
debug = false

[profile.dev.overrides.cranelift-codegen-meta]
[profile.dev.package.cranelift-codegen-meta]
opt-level = 0
debug = false

[profile.dev.overrides.syn]
[profile.dev.package.syn]
opt-level = 0
debug = false

[profile.dev.overrides.synstructure]
[profile.dev.package.synstructure]
opt-level = 0
debug = false
13 changes: 10 additions & 3 deletions example/mini_core.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![feature(
no_core, lang_items, intrinsics, unboxed_closures, type_ascription, extern_types,
untagged_unions, decl_macro, rustc_attrs
untagged_unions, decl_macro, rustc_attrs, transparent_unions
)]
#![no_core]
#![allow(dead_code)]
Expand Down Expand Up @@ -448,10 +448,17 @@ pub trait Drop {
fn drop(&mut self);
}

#[allow(unions_with_drop_fields)]
#[lang = "manually_drop"]
#[repr(transparent)]
pub struct ManuallyDrop<T: ?Sized> {
pub value: T,
}

#[lang = "maybe_uninit"]
#[repr(transparent)]
pub union MaybeUninit<T> {
pub uninit: (),
pub value: T,
pub value: ManuallyDrop<T>,
}

pub mod intrinsics {
Expand Down
2 changes: 1 addition & 1 deletion example/mini_core_hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ fn main() {
}

unsafe fn uninitialized<T>() -> T {
MaybeUninit { uninit: () }.value
MaybeUninit { uninit: () }.value.value
}

zeroed::<(u8, u8)>();
Expand Down
26 changes: 13 additions & 13 deletions patches/0017-Fix-libtest-compilation.patch
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ index 8b76080..9e65de2 100644
--- a/src/libtest/lib.rs
+++ b/src/libtest/lib.rs
@@ -52,7 +52,7 @@ use std::fmt;
use std::fs::File;
use std::io;
use std::io::prelude::*;
-use std::panic::{self, catch_unwind, AssertUnwindSafe, PanicInfo};
+use std::panic::{self, PanicInfo};
use std::path::PathBuf;
use std::process;
use std::process::{ExitStatus, Command, Termination};
env,
io,
io::prelude::Write,
- panic::{self, catch_unwind, AssertUnwindSafe, PanicInfo},
+ panic::{self, PanicInfo},
process,
process::{Command, Termination},
sync::mpsc::{channel, Sender},
@@ -1493,7 +1493,7 @@ pub fn run_test(
fn run_test_inner(
desc: TestDesc,
monitor_ch: Sender<MonitorMsg>,
monitor_ch: Sender<CompletedTest>,
- testfn: Box<dyn FnOnce() + Send>,
+ testfn: Box<impl FnOnce() + Send + 'static>,
opts: TestRunOpts,
Expand Down Expand Up @@ -65,8 +65,8 @@ index 8b76080..9e65de2 100644
report_time: bool,
- testfn: Box<dyn FnOnce() + Send>,
+ testfn: Box<impl FnOnce() + Send + 'static>,
monitor_ch: Sender<MonitorMsg>,
time_opts: Option<TestTimeOptions>,
monitor_ch: Sender<CompletedTest>,
time_opts: Option<time::TestTimeOptions>,
) {
// Buffer for capturing standard I/O
let data = Arc::new(Mutex::new(Vec::new()));
Expand All @@ -75,12 +75,12 @@ index 8b76080..9e65de2 100644
None
};
- let result = catch_unwind(AssertUnwindSafe(testfn));
+ let result = Ok::<(), Box<dyn Any + Send>>(testfn());
+ let result = Ok::<(), Box<dyn std::any::Any + Send>>(testfn());
let exec_time = start.map(|start| {
let duration = start.elapsed();
TestExecTime(duration)
@@ -1688,10 +1676,10 @@ fn spawn_test_subprocess(desc: TestDesc, report_time: bool, monitor_ch: Sender<M
monitor_ch.send((desc.clone(), result, exec_time, test_output)).unwrap();
monitor_ch.send(message).unwrap();
}

fn run_test_in_spawned_subprocess(
Expand Down
2 changes: 1 addition & 1 deletion prepare.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash --verbose
set -e

rustup component add rust-src
rustup component add rust-src rustc-dev
./build_sysroot/prepare_sysroot_src.sh
cargo install hyperfine || echo "Skipping hyperfine install"

Expand Down
19 changes: 14 additions & 5 deletions src/backend.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::HashMap;
use std::convert::TryFrom;

use rustc::session::Session;

Expand Down Expand Up @@ -122,8 +123,13 @@ impl WriteDebugInfo for ObjectProduct {
id: SectionId,
data: Vec<u8>,
) -> (object::write::SectionId, object::write::SymbolId) {
let name = if self.object.format() == target_lexicon::BinaryFormat::Macho {
id.name().replace('.', "__") // machO expects __debug_info instead of .debug_info
} else {
id.name().to_string()
}.into_bytes();

let segment = self.object.segment_name(StandardSegment::Debug).to_vec();
let name = id.name().as_bytes().to_vec();
let section_id = self.object.add_section(segment, name, SectionKind::Debug);
self.object.section_mut(section_id).set_data(data, 1);
let symbol_id = self.object.section_symbol(section_id);
Expand All @@ -137,10 +143,13 @@ impl WriteDebugInfo for ObjectProduct {
from: &Self::SectionId,
reloc: &DebugReloc,
) {
let symbol = match reloc.name {
DebugRelocName::Section(id) => section_map.get(&id).unwrap().1,
let (symbol, symbol_offset) = match reloc.name {
DebugRelocName::Section(id) => {
(section_map.get(&id).unwrap().1, 0)
}
DebugRelocName::Symbol(id) => {
self.function_symbol(*symbol_map.get_index(id).unwrap().0)
let symbol_id = self.function_symbol(*symbol_map.get_index(id).unwrap().0);
self.object.symbol_section_and_offset(symbol_id).expect("Debug reloc for undef sym???")
}
};
self.object.add_relocation(from.0, Relocation {
Expand All @@ -149,7 +158,7 @@ impl WriteDebugInfo for ObjectProduct {
kind: RelocationKind::Absolute,
encoding: RelocationEncoding::Generic,
size: reloc.size * 8,
addend: reloc.addend,
addend: i64::try_from(symbol_offset).unwrap() + reloc.addend,
}).unwrap();
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,9 @@ pub struct FunctionCx<'clif, 'tcx, B: Backend + 'static> {
pub clif_comments: crate::pretty_clif::CommentWriter,
pub constants_cx: &'clif mut crate::constant::ConstantCx,
pub caches: &'clif mut Caches<'tcx>,
pub source_info_set: indexmap::IndexSet<SourceInfo>,

// FIXME switch back to `SourceInfo`, once it derives `Eq` and `Hash` again.
pub source_info_set: indexmap::IndexSet<(Span, mir::SourceScope)>,
}

impl<'tcx, B: Backend> LayoutOf for FunctionCx<'_, 'tcx, B> {
Expand Down Expand Up @@ -365,7 +367,7 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
}

pub fn set_debug_loc(&mut self, source_info: mir::SourceInfo) {
let (index, _) = self.source_info_set.insert_full(source_info);
let (index, _) = self.source_info_set.insert_full((source_info.span, source_info.scope));
self.bcx.set_srcloc(SourceLoc::new(index as u32));
}
}
4 changes: 2 additions & 2 deletions src/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
tcx: TyCtxt,
context: &Context,
isa: &dyn cranelift::codegen::isa::TargetIsa,
source_info_set: &indexmap::IndexSet<SourceInfo>,
source_info_set: &indexmap::IndexSet<(Span, mir::SourceScope)>,
) {
let line_program = &mut self.debug_context.dwarf.unit.line_program;

Expand Down Expand Up @@ -292,7 +292,7 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
line_program.row().address_offset = offset as u64;
if !srcloc.is_default() {
let source_info = *source_info_set.get_index(srcloc.bits() as usize).unwrap();
create_row_for_span(line_program, source_info.span);
create_row_for_span(line_program, source_info.0);
} else {
create_row_for_span(line_program, self.mir_span);
}
Expand Down
5 changes: 1 addition & 4 deletions src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,7 @@ fn run_aot(

let mut module = new_module("some_file".to_string());

let mut debug = if tcx.sess.opts.debuginfo != DebugInfo::None
// macOS debuginfo doesn't work yet (see #303)
&& !tcx.sess.target.target.options.is_like_osx
{
let mut debug = if tcx.sess.opts.debuginfo != DebugInfo::None {
let debug = DebugContext::new(
tcx,
module.target_config().pointer_type().bytes() as u8,
Expand Down