Skip to content
Draft
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
2 changes: 1 addition & 1 deletion src/debuginfo/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl DebugContext {
let _: Result<()> = sections.for_each(|id, section| {
if let Some(section_id) = section_map.get(&id) {
for reloc in &section.relocs {
product.add_debug_reloc(&section_map, section_id, reloc);
product.add_debug_reloc(&section_map, section_id, reloc, false);
}
}
Ok(())
Expand Down
54 changes: 31 additions & 23 deletions src/debuginfo/object.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cranelift_module::{DataId, FuncId};
use cranelift_object::ObjectProduct;
use gimli::SectionId;
use object::write::{Relocation, StandardSegment};
use object::write::{Relocation, StandardSection, StandardSegment};
use object::{RelocationEncoding, RelocationFlags, SectionKind};
use rustc_data_structures::fx::FxHashMap;

Expand All @@ -16,6 +16,7 @@ pub(super) trait WriteDebugInfo {
section_map: &FxHashMap<SectionId, Self::SectionId>,
from: &Self::SectionId,
reloc: &DebugReloc,
use_section_symbol: bool,
);
}

Expand All @@ -27,29 +28,31 @@ impl WriteDebugInfo for ObjectProduct {
id: SectionId,
data: Vec<u8>,
) -> (object::write::SectionId, object::write::SymbolId) {
let name = if self.object.format() == object::BinaryFormat::MachO {
id.name().replace('.', "__") // machO expects __debug_info instead of .debug_info
let (section_id, align);
if id == SectionId::EhFrame {
section_id = self.object.section_id(StandardSection::EhFrame);
align = 8;
} else {
id.name().to_string()
}
.into_bytes();

let segment = self.object.segment_name(StandardSegment::Debug).to_vec();
// FIXME use SHT_X86_64_UNWIND for .eh_frame
let section_id = self.object.add_section(
segment,
name,
if id == SectionId::DebugStr || id == SectionId::DebugLineStr {
SectionKind::DebugString
} else if id == SectionId::EhFrame {
SectionKind::ReadOnlyData
let name = if self.object.format() == object::BinaryFormat::MachO {
id.name().replace('.', "__") // machO expects __debug_info instead of .debug_info
} else {
SectionKind::Debug
},
);
self.object
.section_mut(section_id)
.set_data(data, if id == SectionId::EhFrame { 8 } else { 1 });
id.name().to_string()
}
.into_bytes();

let segment = self.object.segment_name(StandardSegment::Debug).to_vec();
section_id = self.object.add_section(
segment,
name,
if id == SectionId::DebugStr || id == SectionId::DebugLineStr {
SectionKind::DebugString
} else {
SectionKind::Debug
},
);
align = 1;
}
self.object.section_mut(section_id).set_data(data, align);
let symbol_id = self.object.section_symbol(section_id);
(section_id, symbol_id)
}
Expand All @@ -59,6 +62,7 @@ impl WriteDebugInfo for ObjectProduct {
section_map: &FxHashMap<SectionId, Self::SectionId>,
from: &Self::SectionId,
reloc: &DebugReloc,
use_section_symbol: bool,
) {
let (symbol, symbol_offset) = match reloc.name {
DebugRelocName::Section(id) => (section_map.get(&id).unwrap().1, 0),
Expand All @@ -69,7 +73,11 @@ impl WriteDebugInfo for ObjectProduct {
} else {
self.data_symbol(DataId::from_u32(id & !(1 << 31)))
};
self.object.symbol_section_and_offset(symbol_id).unwrap_or((symbol_id, 0))
if use_section_symbol {
self.object.symbol_section_and_offset(symbol_id).unwrap_or((symbol_id, 0))
} else {
(symbol_id, 0)
}
}
};
self.object
Expand Down
12 changes: 6 additions & 6 deletions src/debuginfo/unwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,12 @@ impl UnwindContext {
func_id: FuncId,
context: &Context,
) {
if let target_lexicon::OperatingSystem::MacOSX { .. } =
module.isa().triple().operating_system
let triple = module.isa().triple();
if matches!(triple.operating_system, target_lexicon::OperatingSystem::MacOSX { .. })
&& triple.architecture == target_lexicon::Architecture::X86_64
{
// The object crate doesn't currently support DW_GNU_EH_PE_absptr, which macOS
// requires for unwinding tables. In addition on arm64 it currently doesn't
// support 32bit relocations as we currently use for the unwinding table.
// See gimli-rs/object#415 and rust-lang/rustc_codegen_cranelift#1371
// requires for unwinding tables. See gimli-rs/object#415.
return;
}

Expand Down Expand Up @@ -250,8 +249,9 @@ impl UnwindContext {
let mut section_map = FxHashMap::default();
section_map.insert(id, section_id);

let use_section_symbol = product.object.format() != object::BinaryFormat::MachO;
for reloc in &eh_frame.0.relocs {
product.add_debug_reloc(&section_map, &section_id, reloc);
product.add_debug_reloc(&section_map, &section_id, reloc, use_section_symbol);
}
}
}
Expand Down
Loading