Write object address and size in asm comments

Fixes #37
This commit is contained in:
Luke Street 2024-04-30 18:03:31 -06:00
parent 989293a477
commit bfa926ebbf
1 changed files with 22 additions and 8 deletions

View File

@ -209,7 +209,7 @@ where W: Write + ?Sized {
)?; )?;
} }
ObjSectionKind::Bss => { ObjSectionKind::Bss => {
write_bss(w, &symbols, entries, current_address, section_end)?; write_bss(w, &symbols, entries, section, current_address, section_end)?;
} }
} }
@ -219,7 +219,7 @@ where W: Write + ?Sized {
if entry.kind != SymbolEntryKind::End { if entry.kind != SymbolEntryKind::End {
continue; continue;
} }
write_symbol_entry(w, &symbols, entry)?; write_symbol_entry(w, &symbols, entry, section)?;
} }
} }
@ -359,8 +359,15 @@ where W: Write + ?Sized {
Ok(()) Ok(())
} }
fn write_symbol_entry<W>(w: &mut W, symbols: &[ObjSymbol], entry: &SymbolEntry) -> Result<()> fn write_symbol_entry<W>(
where W: Write + ?Sized { w: &mut W,
symbols: &[ObjSymbol],
entry: &SymbolEntry,
section: &ObjSection,
) -> Result<()>
where
W: Write + ?Sized,
{
let symbol = &symbols[entry.index]; let symbol = &symbols[entry.index];
// Skip writing certain symbols // Skip writing certain symbols
@ -398,6 +405,11 @@ where W: Write + ?Sized {
if symbol.kind != ObjSymbolKind::Unknown { if symbol.kind != ObjSymbolKind::Unknown {
writeln!(w)?; writeln!(w)?;
} }
write!(w, "# {}:{:#X}", section.name, symbol.address)?;
if let Some(section_address) = section.virtual_address {
write!(w, " | {:#X}", section_address + symbol.address)?;
}
writeln!(w, " | size: {:#X}", symbol.size)?;
if let Some(name) = &symbol.demangled_name { if let Some(name) = &symbol.demangled_name {
writeln!(w, "# {name}")?; writeln!(w, "# {name}")?;
} }
@ -456,7 +468,7 @@ where
if entry.kind == SymbolEntryKind::End && begin { if entry.kind == SymbolEntryKind::End && begin {
continue; continue;
} }
write_symbol_entry(w, symbols, entry)?; write_symbol_entry(w, symbols, entry, section)?;
} }
current_symbol_kind = find_symbol_kind(current_symbol_kind, symbols, vec)?; current_symbol_kind = find_symbol_kind(current_symbol_kind, symbols, vec)?;
current_data_kind = find_data_kind(current_data_kind, symbols, vec) current_data_kind = find_data_kind(current_data_kind, symbols, vec)
@ -790,6 +802,7 @@ fn write_bss<W>(
w: &mut W, w: &mut W,
symbols: &[ObjSymbol], symbols: &[ObjSymbol],
entries: &BTreeMap<u32, Vec<SymbolEntry>>, entries: &BTreeMap<u32, Vec<SymbolEntry>>,
section: &ObjSection,
start: u32, start: u32,
end: u32, end: u32,
) -> Result<()> ) -> Result<()>
@ -811,7 +824,7 @@ where
if entry.kind == SymbolEntryKind::End && begin { if entry.kind == SymbolEntryKind::End && begin {
continue; continue;
} }
write_symbol_entry(w, symbols, entry)?; write_symbol_entry(w, symbols, entry, section)?;
} }
entry = entry_iter.next(); entry = entry_iter.next();
} }
@ -841,9 +854,10 @@ where
let section_virtual_address = section.virtual_address.unwrap_or(0); let section_virtual_address = section.virtual_address.unwrap_or(0);
writeln!( writeln!(
w, w,
"\n# {:#010X} - {:#010X}", "\n# {:#010X}..{:#010X} | size: {:#X}",
start as u64 + section_virtual_address, start as u64 + section_virtual_address,
end as u64 + section_virtual_address end as u64 + section_virtual_address,
end - start
)?; )?;
match section.name.as_str() { match section.name.as_str() {
".text" if subsection == 0 => { ".text" if subsection == 0 => {