diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -2914,6 +2914,11 @@ // Filter labels by section. for (const SymbolCU &SCU : ArangeLabels) { + // Ignore zero-sized symbols so that we don't end up emitting any aranges + // that have zero length, which would violate the DWARF spec. + if (SymSize[SCU.Sym] == 0) + continue; + if (SCU.Sym->isInSection()) { // Make a note of this symbol and it's section. MCSection *Section = &SCU.Sym->getSection(); @@ -3049,9 +3054,6 @@ // For symbols without an end marker (e.g. common), we // write a single arange entry containing just that one symbol. uint64_t Size = SymSize[Span.Start]; - if (Size == 0) - Size = 1; - Asm->OutStreamer->emitIntValue(Size, PtrSize); } }