From dd0bc3237e70f4c3f392e6c8960f2dcb1430261d Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Fri, 3 Sep 2021 15:43:55 -0700 Subject: [PATCH] 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. --- crates/cranelift/src/debug/write_debuginfo.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/cranelift/src/debug/write_debuginfo.rs b/crates/cranelift/src/debug/write_debuginfo.rs index a82796cb34..561b90ef00 100644 --- a/crates/cranelift/src/debug/write_debuginfo.rs +++ b/crates/cranelift/src/debug/write_debuginfo.rs @@ -54,6 +54,9 @@ fn emit_dwarf_sections( sections.for_each_mut(|id, s| -> anyhow::Result<()> { let name = id.name(); let body = s.writer.take(); + if body.is_empty() { + return Ok(()); + } let mut relocs = vec![]; ::std::mem::swap(&mut relocs, &mut s.relocs); result.push(DwarfSection { name, body, relocs });