[PATCH] Fixed a bug with section names containing special characters.

Richard Mitton richard at codersnotes.com
Mon Sep 30 18:42:02 PDT 2013


Hi echristo,

Fixed a bug with section names containing special characters.

Changed the dwarf aranges code to not use getLabelEndName, as it turns out it's not reliable to call that given user-defined section names. Section names can have characters in that aren't representable as symbol names.

The dwarf-aranges test case has been updated to include a special character, to check this.

This fixes pr17416.


http://llvm-reviews.chandlerc.com/D1790

Files:
  lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  test/DebugInfo/X86/dwarf-aranges.ll
  test/DebugInfo/X86/multiple-aranges.ll

Index: lib/CodeGen/AsmPrinter/DwarfDebug.cpp
===================================================================
--- lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -312,6 +312,12 @@
   return In.slice(In.find(' ') + 1, In.find(']'));
 }
 
+static bool SectionSort(const MCSection *A, const MCSection *B) {
+    std::string LA = (A ? A->getLabelBeginName() : "");
+    std::string LB = (B ? B->getLabelBeginName() : "");
+    return LA < LB;
+}
+
 // Add the various names to the Dwarf accelerator table names.
 // TODO: Determine whether or not we should add names for programs
 // that do not have a DW_AT_name or DW_AT_linkage_name field - this
@@ -1095,14 +1101,25 @@
     }
   }
 
-  // Add terminating symbols for each section.
+  // Build a list of sections used.
+  std::vector<const MCSection *> Sections;
   for (SectionMapType::iterator it = SectionMap.begin(); it != SectionMap.end();
        it++) {
     const MCSection *Section = it->first;
+    Sections.push_back(Section);
+  }
+
+  // Sort the sections into order.
+  // This is only done to ensure consistent output order across different runs.
+  std::sort(Sections.begin(), Sections.end(), SectionSort);
+
+  // Add terminating symbols for each section.
+  for (unsigned ID=0;ID<Sections.size();ID++) {
+    const MCSection *Section = Sections[ID];
     MCSymbol *Sym = NULL;
 
     if (Section) {
-      Sym = Asm->GetTempSymbol(Section->getLabelEndName());
+      Sym = Asm->GetTempSymbol("debug_end", ID);
       Asm->OutStreamer.SwitchSection(Section);
       Asm->OutStreamer.EmitLabel(Sym);
     }
@@ -2708,12 +2725,6 @@
   }
 };
 
-static bool SectionSort(const MCSection *A, const MCSection *B) {
-    std::string LA = (A ? A->getLabelBeginName() : "");
-    std::string LB = (B ? B->getLabelBeginName() : "");
-    return LA < LB;
-}
-
 static bool CUSort(const CompileUnit *A, const CompileUnit *B) {
     return (A->getUniqueID() < B->getUniqueID());
 }
Index: test/DebugInfo/X86/dwarf-aranges.ll
===================================================================
--- test/DebugInfo/X86/dwarf-aranges.ll
+++ test/DebugInfo/X86/dwarf-aranges.ll
@@ -1,47 +1,38 @@
-; RUN: llc < %s | FileCheck -check-prefix=CHECK-HEADER %s
-; RUN: llc < %s | FileCheck -check-prefix=CHECK-CODE %s
-; RUN: llc < %s | FileCheck -check-prefix=CHECK-DATA %s
-; RUN: llc < %s | FileCheck -check-prefix=CHECK-BSS %s
-; RUN: llc < %s | FileCheck -check-prefix=CHECK-CUSTOM %s
+; RUN: llc < %s | FileCheck %s
 
 
 ; -- header --
-; CHECK-HEADER: .short 2 # DWARF Arange version number
-; CHECK-HEADER-NEXT: .long .L.debug_info_begin0
-; CHECK-HEADER-NEXT: .byte 8 # Address Size (in bytes)
-; CHECK-HEADER-NEXT: .byte 0 # Segment Size (in bytes)
+; CHECK: .short 2 # DWARF Arange version number
+; CHECK-NEXT: .long .L.debug_info_begin0
+; CHECK-NEXT: .byte 8 # Address Size (in bytes)
+; CHECK-NEXT: .byte 0 # Segment Size (in bytes)
 ; -- alignment --
-; CHECK-HEADER-NEXT: .byte
-; CHECK-HEADER-NEXT: .byte
-; CHECK-HEADER-NEXT: .byte
-; CHECK-HEADER-NEXT: .byte
-; -- finish --
-; CHECK-HEADER: # ARange terminator
+; CHECK-NEXT: .byte
+; CHECK-NEXT: .byte
+; CHECK-NEXT: .byte
+; CHECK-NEXT: .byte
+
+; <common symbols> - it should have made one span for each symbol.
+; CHECK-NEXT: .quad some_bss
+; CHECK-NEXT: .quad 4
+
+; <data section> - it should have made one span covering all vars in this CU.
+; CHECK-NEXT: .quad some_data
+; CHECK-NEXT: .Lset0 = .Ldebug_end1-some_data
+; CHECK-NEXT: .quad .Lset0
 
 ; <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: # 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: .quad 4
-; CHECK-BSS: # ARange terminator
+; CHECK-NEXT: .quad .Lfunc_begin0
+; CHECK-NEXT: .Lset1 = .Ldebug_end2-.Lfunc_begin0
+; CHECK-NEXT: .quad .Lset1
 
 ; <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: .Lstrange_section_end-some_other
-; CHECK-CUSTOM: # ARange terminator
+; CHECK-NEXT: .quad some_other
+; CHECK-NEXT: .Lset2 = .Ldebug_end3-some_other
+; CHECK-NEXT: .quad .Lset2
 
+; -- finish --
+; CHECK-NEXT: # ARange terminator
 
 
 
Index: test/DebugInfo/X86/multiple-aranges.ll
===================================================================
--- test/DebugInfo/X86/multiple-aranges.ll
+++ test/DebugInfo/X86/multiple-aranges.ll
@@ -27,7 +27,7 @@
 ; CHECK-NEXT: .byte   255
 ; CHECK-NEXT: .byte   255
 ; CHECK-NEXT: .quad   rainbows
-; CHECK-NEXT: .Lset1 = .L.data_end-rainbows
+; CHECK-NEXT: .Lset1 = .Ldebug_end0-rainbows
 ; CHECK-NEXT: .quad   .Lset1
 ; CHECK-NEXT: .quad   0                       # ARange terminator
 ; CHECK-NEXT: .quad   0
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1790.1.patch
Type: text/x-patch
Size: 5277 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130930/183181cb/attachment.bin>


More information about the llvm-commits mailing list