[PATCH] D126010: Make sure the AsmPrinter doesn't emit any zero-sized symbols to `.debug_aranges`.

Patrick Walton via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 19 13:06:47 PDT 2022


pcwalton created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
pcwalton requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This commit modifies the AsmPrinter to avoid emitting any zero-sized symbols to
the `.debug_aranges` table. Such symbols violate the DWARF 5 spec, which
states:

> Each descriptor is a triple consisting of a segment selector, the beginning
> address within that segment of a range of text or data covered by some entry
> owned by the corresponding compilation unit, followed by the non-zero length
> of that range.

In practice, these zero-sized entries produce annoying warnings in lld and
cause GNU binutils to truncate the table when parsing it.

Other parts of LLVM, such as DWARFDebugARanges in the DebugInfo module
(specifically the `appendRange` method), already avoid emitting zero-sized
symbols to `.debug_aranges`, but not comprehensively in the AsmPrinter. In
fact, the AsmPrinter does try to avoid emitting such zero-sized symbols when
labels aren't involved, but doesn't when the symbol to emitted is a difference
of two labels; this patch extends that logic to handle the case in which the
symbol is defined via labels.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126010

Files:
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp


Index: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ 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);
       }
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126010.430785.patch
Type: text/x-patch
Size: 978 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220519/0a3d689c/attachment.bin>


More information about the llvm-commits mailing list