[llvm] r191210 - Fixed debug_aranges handling for common symbols.

Richard Mitton richard at codersnotes.com
Mon Sep 23 10:56:20 PDT 2013


Author: rmitton
Date: Mon Sep 23 12:56:20 2013
New Revision: 191210

URL: http://llvm.org/viewvc/llvm-project?rev=191210&view=rev
Log:
Fixed debug_aranges handling for common symbols.

The size of common symbols is now tracked correctly, so they can be listed in the arange section without needing knowledge of other following symbols.

.comm (and .lcomm) do not indicate to the system assembler any particular section to use, so we have to treat them as having no section.

Test case update to account for this.

Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
    llvm/trunk/lib/MC/MCAsmStreamer.cpp
    llvm/trunk/test/DebugInfo/X86/dwarf-aranges.ll

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=191210&r1=191209&r2=191210&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Mon Sep 23 12:56:20 2013
@@ -292,6 +292,9 @@ void AsmPrinter::EmitGlobalVariable(cons
   // sections and expected to be contiguous (e.g. ObjC metadata).
   unsigned AlignLog = getGVAlignmentLog2(GV, *TD);
 
+  if (DD)
+    DD->setSymbolSize(GVSym, Size);
+
   // Handle common and BSS local symbols (.lcomm).
   if (GVKind.isCommon() || GVKind.isBSSLocal()) {
     if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=191210&r1=191209&r2=191210&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Mon Sep 23 12:56:20 2013
@@ -2838,12 +2838,17 @@ void DwarfDebug::emitDebugARanges() {
       Asm->EmitLabelReference(Span.Start, PtrSize);
 
       // Calculate the size as being from the span start to it's end.
-      // If we have no valid end symbol, then we just cover the first byte.
-      // (this sucks, but I can't seem to figure out how to get the size)
-      if (Span.End)
+      if (Span.End) {
         Asm->EmitLabelDifference(Span.End, Span.Start, PtrSize);
-      else
-        Asm->OutStreamer.EmitIntValue(1, PtrSize);
+      } else {
+        // 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);
+      }
     }
 
     Asm->OutStreamer.AddComment("ARange terminator");

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=191210&r1=191209&r2=191210&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h Mon Sep 23 12:56:20 2013
@@ -341,6 +341,9 @@ class DwarfDebug {
   // List of all labels used in the output.
   std::vector<SymbolCU> Labels;
 
+  // Size of each symbol emitted (for those symbols that have a specific size).
+  DenseMap <const MCSymbol *, uint64_t> SymSize;
+
   // Provides a unique id per text section.
   typedef DenseMap<const MCSection *, SmallVector<SymbolCU, 8> > SectionMapType;
   SectionMapType SectionMap;
@@ -682,6 +685,10 @@ public:
   /// \brief Add a label so that arange data can be generated for it.
   void addLabel(SymbolCU SCU) { Labels.push_back(SCU); }
 
+  /// \brief For symbols that have a size designated (e.g. common symbols),
+  /// this tracks that size.
+  void setSymbolSize(const MCSymbol *Sym, uint64_t Size) { SymSize[Sym] = Size;}
+
   /// \brief Look up the source id with the given directory and source file
   /// names. If none currently exists, create a new id and insert it in the
   /// SourceIds map.

Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=191210&r1=191209&r2=191210&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Mon Sep 23 12:56:20 2013
@@ -533,8 +533,8 @@ void MCAsmStreamer::EmitELFSize(MCSymbol
 
 void MCAsmStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
                                      unsigned ByteAlignment) {
-  const MCSection *Section = getContext().getObjectFileInfo()->getBSSSection();
-  AssignSection(Symbol, Section);
+  // Common symbols do not belong to any actual section.
+  AssignSection(Symbol, NULL);
 
   OS << "\t.comm\t" << *Symbol << ',' << Size;
   if (ByteAlignment != 0) {
@@ -552,8 +552,8 @@ void MCAsmStreamer::EmitCommonSymbol(MCS
 /// @param Size - The size of the common symbol.
 void MCAsmStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
                                           unsigned ByteAlign) {
-  const MCSection *Section = getContext().getObjectFileInfo()->getBSSSection();
-  AssignSection(Symbol, Section);
+  // Common symbols do not belong to any actual section.
+  AssignSection(Symbol, NULL);
 
   OS << "\t.lcomm\t" << *Symbol << ',' << Size;
   if (ByteAlign > 1) {

Modified: llvm/trunk/test/DebugInfo/X86/dwarf-aranges.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/dwarf-aranges.ll?rev=191210&r1=191209&r2=191210&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/dwarf-aranges.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/dwarf-aranges.ll Mon Sep 23 12:56:20 2013
@@ -18,27 +18,28 @@
 ; -- finish --
 ; CHECK-HEADER: # ARange terminator
 
-
+; <text section> - it should have made one span covering all functions in this CU.
 ; CHECK-CODE: .short 2 # DWARF Arange version number
 ; CHECK-CODE: .quad .Lfunc_begin0
+; CHECK-CODE-NEXT: .Lset1 = .L.text_end-.Lfunc_begin0
 ; CHECK-CODE: # ARange terminator
 
+; <data section> - it should have made one span covering all vars in this CU.
 ; CHECK-DATA: .short 2 # DWARF Arange version number
 ; CHECK-DATA: .quad some_data
 ; CHECK-DATA-NEXT: -some_data
-; CHECK-DATA-NEXT: .quad
 ; CHECK-DATA: # ARange terminator
 
+; <common symbols> - it should have made one span for each symbol.
 ; CHECK-BSS: .short 2 # DWARF Arange version number
 ; CHECK-BSS: .quad some_bss
-; CHECK-BSS-NEXT: -some_bss
-; CHECK-BSS-NEXT: .quad
+; CHECK-BSS-NEXT: .quad 4
 ; CHECK-BSS: # ARange terminator
 
+; <other sections> - it should have made one span covering all vars in this CU.
 ; CHECK-CUSTOM: .short 2 # DWARF Arange version number
 ; CHECK-CUSTOM: .quad some_other
 ; CHECK-CUSTOM-NEXT: -some_other
-; CHECK-CUSTOM-NEXT: .quad
 ; CHECK-CUSTOM: # ARange terminator
 
 





More information about the llvm-commits mailing list