Do not write a DWARF section if it is empty

There is no point in writing an empty DWARF section, and this will make our ELF
files a tiny bit smaller.
This commit is contained in:
Nick Fitzgerald
2021-09-03 15:43:55 -07:00
parent e26b91e890
commit dd0bc3237e

View File

@@ -54,6 +54,9 @@ fn emit_dwarf_sections(
sections.for_each_mut(|id, s| -> anyhow::Result<()> { sections.for_each_mut(|id, s| -> anyhow::Result<()> {
let name = id.name(); let name = id.name();
let body = s.writer.take(); let body = s.writer.take();
if body.is_empty() {
return Ok(());
}
let mut relocs = vec![]; let mut relocs = vec![];
::std::mem::swap(&mut relocs, &mut s.relocs); ::std::mem::swap(&mut relocs, &mut s.relocs);
result.push(DwarfSection { name, body, relocs }); result.push(DwarfSection { name, body, relocs });