Skip to content

Commit ecd9c4f

Browse files
committed
FIx review comments
1 parent 0471ed2 commit ecd9c4f

File tree

3 files changed

+21
-25
lines changed

3 files changed

+21
-25
lines changed

src/backend.rs

+17-21
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,21 @@ impl WriteMetadata for faerie::Artifact {
4242
}
4343

4444
impl WriteMetadata for object::write::Object {
45-
fn add_rustc_section(&mut self, symbol_name: String, data: Vec<u8>, is_like_osx: bool) {
45+
fn add_rustc_section(&mut self, symbol_name: String, data: Vec<u8>, _is_like_osx: bool) {
4646
let segment = self.segment_name(object::write::StandardSegment::Data).to_vec();
4747
let section_id = self.add_section(segment, b".rustc".to_vec(), object::SectionKind::Data);
4848
let offset = self.append_section_data(section_id, &data, 1);
49-
// FIXME implement faerie elf backend section custom symbols
50-
// For MachO this is necessary to prevent the linker from throwing away the .rustc section,
51-
// but for ELF it isn't.
52-
if is_like_osx {
53-
self.add_symbol(object::write::Symbol {
54-
name: symbol_name.into_bytes(),
55-
value: offset,
56-
size: data.len() as u64,
57-
kind: object::SymbolKind::Data,
58-
scope: object::SymbolScope::Compilation,
59-
weak: false,
60-
section: Some(section_id),
61-
});
62-
}
49+
// For MachO and probably PE this is necessary to prevent the linker from throwing away the
50+
// .rustc section. For ELF this isn't necessary, but it also doesn't harm.
51+
self.add_symbol(object::write::Symbol {
52+
name: symbol_name.into_bytes(),
53+
value: offset,
54+
size: data.len() as u64,
55+
kind: object::SymbolKind::Data,
56+
scope: object::SymbolScope::Compilation,
57+
weak: false,
58+
section: Some(section_id),
59+
});
6360
}
6461
}
6562

@@ -70,7 +67,7 @@ pub trait WriteDebugInfo {
7067
fn add_debug_reloc(
7168
&mut self,
7269
section_map: &HashMap<SectionId, Self::SectionId>,
73-
symbol_map: &indexmap::IndexSet<(String, FuncId)>,
70+
symbol_map: &indexmap::IndexMap<FuncId, String>,
7471
from: &Self::SectionId,
7572
reloc: &DebugReloc,
7673
);
@@ -87,7 +84,7 @@ impl WriteDebugInfo for FaerieProduct {
8784
fn add_debug_reloc(
8885
&mut self,
8986
_section_map: &HashMap<SectionId, Self::SectionId>,
90-
symbol_map: &indexmap::IndexSet<(String, FuncId)>,
87+
symbol_map: &indexmap::IndexMap<FuncId, String>,
9188
from: &Self::SectionId,
9289
reloc: &DebugReloc,
9390
) {
@@ -98,7 +95,7 @@ impl WriteDebugInfo for FaerieProduct {
9895
from: from.name(),
9996
to: match reloc.name {
10097
DebugRelocName::Section(id) => id.name(),
101-
DebugRelocName::Symbol(index) => &symbol_map.get_index(index).unwrap().0,
98+
DebugRelocName::Symbol(index) => &symbol_map.get_index(index).unwrap().1,
10299
},
103100
at: u64::from(reloc.offset),
104101
},
@@ -130,15 +127,14 @@ impl WriteDebugInfo for ObjectProduct {
130127
fn add_debug_reloc(
131128
&mut self,
132129
section_map: &HashMap<SectionId, Self::SectionId>,
133-
symbol_map: &indexmap::IndexSet<(String, FuncId)>,
130+
symbol_map: &indexmap::IndexMap<FuncId, String>,
134131
from: &Self::SectionId,
135132
reloc: &DebugReloc,
136133
) {
137134
let symbol = match reloc.name {
138135
DebugRelocName::Section(id) => section_map.get(&id).unwrap().1,
139136
DebugRelocName::Symbol(id) => {
140-
let (_func_name, func_id) = symbol_map.get_index(id).unwrap();
141-
self.function_symbol(*func_id)
137+
self.function_symbol(*symbol_map.get_index(id).unwrap().0)
142138
}
143139
};
144140
self.object.add_relocation(from.0, Relocation {

src/debuginfo.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub enum DebugRelocName {
7171

7272
pub struct DebugContext<'tcx> {
7373
endian: RunTimeEndian,
74-
symbols: indexmap::IndexSet<(String, FuncId)>,
74+
symbols: indexmap::IndexMap<FuncId, String>,
7575

7676
dwarf: DwarfUnit,
7777
unit_range_list: RangeList,
@@ -133,7 +133,7 @@ impl<'tcx> DebugContext<'tcx> {
133133

134134
DebugContext {
135135
endian: target_endian(tcx),
136-
symbols: indexmap::IndexSet::new(),
136+
symbols: indexmap::IndexMap::new(),
137137

138138
dwarf,
139139
unit_range_list: RangeList(Vec::new()),
@@ -216,7 +216,7 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
216216
name: &str,
217217
_sig: &Signature,
218218
) -> Self {
219-
let (symbol, _) = debug_context.symbols.insert_full((name.to_string(), func_id));
219+
let (symbol, _) = debug_context.symbols.insert_full(func_id, name.to_string());
220220

221221
// FIXME: add to appropriate scope intead of root
222222
let scope = debug_context.dwarf.unit.root();

src/driver.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ fn run_aot(
174174
let obj = product.emit();
175175
std::fs::write(&tmp_file, obj).unwrap();
176176
CompiledModule {
177-
name: name,
177+
name,
178178
kind,
179179
object: Some(tmp_file),
180180
bytecode: None,

0 commit comments

Comments
 (0)