[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
Fri May 20 13:38:23 PDT 2022


pcwalton updated this revision to Diff 431041.
pcwalton added a comment.

Added a test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126010/new/

https://reviews.llvm.org/D126010

Files:
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  llvm/test/CodeGen/Generic/dwarf-aranges-zero-size.ll


Index: llvm/test/CodeGen/Generic/dwarf-aranges-zero-size.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/Generic/dwarf-aranges-zero-size.ll
@@ -0,0 +1,23 @@
+; Ensures that the AsmPrinter doesn't emit zero-sized symbols into `.debug_aranges`.
+;
+; RUN: llc --generate-arange-section < %s | FileCheck %s
+; CHECK: .section .debug_aranges
+; CHECK-NOT: .quad EXAMPLE
+; CHECK: .section
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at EXAMPLE = constant <{ [0 x i8] }> zeroinitializer, align 1, !dbg !0
+
+!llvm.module.flags = !{!3}
+!llvm.dbg.cu = !{!4}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "EXAMPLE", linkageName: "EXAMPLE", scope: null, file: null, line: 161, type: !2, isLocal: false, isDefinition: true, align: 1)
+!2 = !DIBasicType(name: "()", encoding: DW_ATE_unsigned)
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = distinct !DICompileUnit(language: DW_LANG_Rust, file: !5, producer: "rustc", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: null, globals: !6)
+!5 = !DIFile(filename: "foo", directory: "")
+!6 = !{!0}
+
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.431041.patch
Type: text/x-patch
Size: 2256 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220520/19f85ace/attachment.bin>


More information about the llvm-commits mailing list