Skip to content

Commit 7d0007d

Browse files
authored
Merge pull request #759 from bjorn3/fix_macho_debuginfo
Fix debuginfo for machO
2 parents 75c24b9 + 40178f6 commit 7d0007d

10 files changed

+58
-39
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,18 @@ features = ["compression", "read", "std"] # We don't need WASM support
4545
#[patch.crates-io]
4646
#gimli = { path = "../" }
4747

48+
[patch.crates-io]
49+
# FIXME switch back to crates.io once gimli-rs/object#133 is published
50+
object = { git = "https://github.com/gimli-rs/object.git" }
51+
4852
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
4953
cranelift-simplejit = { git = "https://github.com/CraneStation/cranelift.git" }
5054

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

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

@@ -62,14 +66,14 @@ opt-level = 0
6266
opt-level = 0
6367
debug = false
6468

65-
[profile.dev.overrides.cranelift-codegen-meta]
69+
[profile.dev.package.cranelift-codegen-meta]
6670
opt-level = 0
6771
debug = false
6872

69-
[profile.dev.overrides.syn]
73+
[profile.dev.package.syn]
7074
opt-level = 0
7175
debug = false
7276

73-
[profile.dev.overrides.synstructure]
77+
[profile.dev.package.synstructure]
7478
opt-level = 0
7579
debug = false

example/mini_core.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![feature(
22
no_core, lang_items, intrinsics, unboxed_closures, type_ascription, extern_types,
3-
untagged_unions, decl_macro, rustc_attrs
3+
untagged_unions, decl_macro, rustc_attrs, transparent_unions
44
)]
55
#![no_core]
66
#![allow(dead_code)]
@@ -448,10 +448,17 @@ pub trait Drop {
448448
fn drop(&mut self);
449449
}
450450

451-
#[allow(unions_with_drop_fields)]
451+
#[lang = "manually_drop"]
452+
#[repr(transparent)]
453+
pub struct ManuallyDrop<T: ?Sized> {
454+
pub value: T,
455+
}
456+
457+
#[lang = "maybe_uninit"]
458+
#[repr(transparent)]
452459
pub union MaybeUninit<T> {
453460
pub uninit: (),
454-
pub value: T,
461+
pub value: ManuallyDrop<T>,
455462
}
456463

457464
pub mod intrinsics {

example/mini_core_hello_world.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ fn main() {
196196
}
197197

198198
unsafe fn uninitialized<T>() -> T {
199-
MaybeUninit { uninit: () }.value
199+
MaybeUninit { uninit: () }.value.value
200200
}
201201

202202
zeroed::<(u8, u8)>();

patches/0017-Fix-libtest-compilation.patch

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ index 8b76080..9e65de2 100644
1212
--- a/src/libtest/lib.rs
1313
+++ b/src/libtest/lib.rs
1414
@@ -52,7 +52,7 @@ use std::fmt;
15-
use std::fs::File;
16-
use std::io;
17-
use std::io::prelude::*;
18-
-use std::panic::{self, catch_unwind, AssertUnwindSafe, PanicInfo};
19-
+use std::panic::{self, PanicInfo};
20-
use std::path::PathBuf;
21-
use std::process;
22-
use std::process::{ExitStatus, Command, Termination};
15+
env,
16+
io,
17+
io::prelude::Write,
18+
- panic::{self, catch_unwind, AssertUnwindSafe, PanicInfo},
19+
+ panic::{self, PanicInfo},
20+
process,
21+
process::{Command, Termination},
22+
sync::mpsc::{channel, Sender},
2323
@@ -1493,7 +1493,7 @@ pub fn run_test(
2424
fn run_test_inner(
2525
desc: TestDesc,
26-
monitor_ch: Sender<MonitorMsg>,
26+
monitor_ch: Sender<CompletedTest>,
2727
- testfn: Box<dyn FnOnce() + Send>,
2828
+ testfn: Box<impl FnOnce() + Send + 'static>,
2929
opts: TestRunOpts,
@@ -65,8 +65,8 @@ index 8b76080..9e65de2 100644
6565
report_time: bool,
6666
- testfn: Box<dyn FnOnce() + Send>,
6767
+ testfn: Box<impl FnOnce() + Send + 'static>,
68-
monitor_ch: Sender<MonitorMsg>,
69-
time_opts: Option<TestTimeOptions>,
68+
monitor_ch: Sender<CompletedTest>,
69+
time_opts: Option<time::TestTimeOptions>,
7070
) {
7171
// Buffer for capturing standard I/O
7272
let data = Arc::new(Mutex::new(Vec::new()));
@@ -75,12 +75,12 @@ index 8b76080..9e65de2 100644
7575
None
7676
};
7777
- let result = catch_unwind(AssertUnwindSafe(testfn));
78-
+ let result = Ok::<(), Box<dyn Any + Send>>(testfn());
78+
+ let result = Ok::<(), Box<dyn std::any::Any + Send>>(testfn());
7979
let exec_time = start.map(|start| {
8080
let duration = start.elapsed();
8181
TestExecTime(duration)
8282
@@ -1688,10 +1676,10 @@ fn spawn_test_subprocess(desc: TestDesc, report_time: bool, monitor_ch: Sender<M
83-
monitor_ch.send((desc.clone(), result, exec_time, test_output)).unwrap();
83+
monitor_ch.send(message).unwrap();
8484
}
8585

8686
fn run_test_in_spawned_subprocess(

prepare.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash --verbose
22
set -e
33

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

src/backend.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::collections::HashMap;
2+
use std::convert::TryFrom;
23

34
use rustc::session::Session;
45

@@ -122,8 +123,13 @@ impl WriteDebugInfo for ObjectProduct {
122123
id: SectionId,
123124
data: Vec<u8>,
124125
) -> (object::write::SectionId, object::write::SymbolId) {
126+
let name = if self.object.format() == target_lexicon::BinaryFormat::Macho {
127+
id.name().replace('.', "__") // machO expects __debug_info instead of .debug_info
128+
} else {
129+
id.name().to_string()
130+
}.into_bytes();
131+
125132
let segment = self.object.segment_name(StandardSegment::Debug).to_vec();
126-
let name = id.name().as_bytes().to_vec();
127133
let section_id = self.object.add_section(segment, name, SectionKind::Debug);
128134
self.object.section_mut(section_id).set_data(data, 1);
129135
let symbol_id = self.object.section_symbol(section_id);
@@ -137,10 +143,13 @@ impl WriteDebugInfo for ObjectProduct {
137143
from: &Self::SectionId,
138144
reloc: &DebugReloc,
139145
) {
140-
let symbol = match reloc.name {
141-
DebugRelocName::Section(id) => section_map.get(&id).unwrap().1,
146+
let (symbol, symbol_offset) = match reloc.name {
147+
DebugRelocName::Section(id) => {
148+
(section_map.get(&id).unwrap().1, 0)
149+
}
142150
DebugRelocName::Symbol(id) => {
143-
self.function_symbol(*symbol_map.get_index(id).unwrap().0)
151+
let symbol_id = self.function_symbol(*symbol_map.get_index(id).unwrap().0);
152+
self.object.symbol_section_and_offset(symbol_id).expect("Debug reloc for undef sym???")
144153
}
145154
};
146155
self.object.add_relocation(from.0, Relocation {
@@ -149,7 +158,7 @@ impl WriteDebugInfo for ObjectProduct {
149158
kind: RelocationKind::Absolute,
150159
encoding: RelocationEncoding::Generic,
151160
size: reloc.size * 8,
152-
addend: reloc.addend,
161+
addend: i64::try_from(symbol_offset).unwrap() + reloc.addend,
153162
}).unwrap();
154163
}
155164
}

src/common.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,9 @@ pub struct FunctionCx<'clif, 'tcx, B: Backend + 'static> {
286286
pub clif_comments: crate::pretty_clif::CommentWriter,
287287
pub constants_cx: &'clif mut crate::constant::ConstantCx,
288288
pub caches: &'clif mut Caches<'tcx>,
289-
pub source_info_set: indexmap::IndexSet<SourceInfo>,
289+
290+
// FIXME switch back to `SourceInfo`, once it derives `Eq` and `Hash` again.
291+
pub source_info_set: indexmap::IndexSet<(Span, mir::SourceScope)>,
290292
}
291293

292294
impl<'tcx, B: Backend> LayoutOf for FunctionCx<'_, 'tcx, B> {
@@ -365,7 +367,7 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
365367
}
366368

367369
pub fn set_debug_loc(&mut self, source_info: mir::SourceInfo) {
368-
let (index, _) = self.source_info_set.insert_full(source_info);
370+
let (index, _) = self.source_info_set.insert_full((source_info.span, source_info.scope));
369371
self.bcx.set_srcloc(SourceLoc::new(index as u32));
370372
}
371373
}

src/debuginfo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
252252
tcx: TyCtxt,
253253
context: &Context,
254254
isa: &dyn cranelift::codegen::isa::TargetIsa,
255-
source_info_set: &indexmap::IndexSet<SourceInfo>,
255+
source_info_set: &indexmap::IndexSet<(Span, mir::SourceScope)>,
256256
) {
257257
let line_program = &mut self.debug_context.dwarf.unit.line_program;
258258

@@ -292,7 +292,7 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
292292
line_program.row().address_offset = offset as u64;
293293
if !srcloc.is_default() {
294294
let source_info = *source_info_set.get_index(srcloc.bits() as usize).unwrap();
295-
create_row_for_span(line_program, source_info.span);
295+
create_row_for_span(line_program, source_info.0);
296296
} else {
297297
create_row_for_span(line_program, self.mir_span);
298298
}

src/driver.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,7 @@ fn run_aot(
184184

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

187-
let mut debug = if tcx.sess.opts.debuginfo != DebugInfo::None
188-
// macOS debuginfo doesn't work yet (see #303)
189-
&& !tcx.sess.target.target.options.is_like_osx
190-
{
187+
let mut debug = if tcx.sess.opts.debuginfo != DebugInfo::None {
191188
let debug = DebugContext::new(
192189
tcx,
193190
module.target_config().pointer_type().bytes() as u8,

0 commit comments

Comments
 (0)