Fixed debug_aranges handling for common symbols.
authorRichard Mitton <richard@codersnotes.com>
Mon, 23 Sep 2013 17:56:20 +0000 (17:56 +0000)
committerRichard Mitton <richard@codersnotes.com>
Mon, 23 Sep 2013 17:56:20 +0000 (17:56 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191210 91177308-0d34-0410-b5e6-96231b3b80d8

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

index e66237706bc053a1132c12996ce90e91fc550637..de08b77012b5d9deac4e92e69c2b954bddd11215 100644 (file)
@@ -292,6 +292,9 @@ void AsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) {
   // 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.
index 6414969774b2490b98639be80ba8299bd1529f6e..48a7c185ec2b5fbe1b9155cf5ee7ec577b38c465 100644 (file)
@@ -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");
index 8fe60c77be518788d4c6da8db70678ac538f1ad2..e774c653945d6b621ffc4e03659a2ca86140c1d1 100644 (file)
@@ -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.
index e57025e1019a8fce5233dfd4ebb29cedd78aa59a..80b0acec84650e73683744722a00f700141c43ee 100644 (file)
@@ -533,8 +533,8 @@ void MCAsmStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
 
 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(MCSymbol *Symbol, uint64_t Size,
 /// @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) {
index eae5c790d82019402e83d54bd056f7e1e1420bfd..a2f0059ed25514d34071f547905825f0d631e6d6 100644 (file)
 ; -- 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