Make sure we emit a relocation to the debug_ranges section in the
authorEric Christopher <echristo@gmail.com>
Wed, 15 Jan 2014 00:04:29 +0000 (00:04 +0000)
committerEric Christopher <echristo@gmail.com>
Wed, 15 Jan 2014 00:04:29 +0000 (00:04 +0000)
presence of CU ranges.

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

lib/CodeGen/AsmPrinter/DwarfDebug.cpp
lib/CodeGen/AsmPrinter/DwarfDebug.h
test/DebugInfo/X86/cu-ranges.ll

index c895f17931d9a5176e8970db7656fd99cb645de1..f76e898cfb5aa63344a94affc755832e4a8b7ef4 100644 (file)
@@ -209,6 +209,10 @@ DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
   else
     HasDwarfPubSections = DwarfPubSections == Enable;
 
+  // For now only turn on CU ranges if we've explicitly asked for it
+  // or we have -ffunction-sections enabled.
+  HasCURanges = DwarfCURanges || TargetMachine::getFunctionSections();
+
   DwarfVersion = DwarfVersionNumber
                      ? DwarfVersionNumber
                      : getDwarfVersionFromModule(MMI->getModule());
@@ -1057,8 +1061,7 @@ void DwarfDebug::finalizeModuleInfo() {
       // FIXME: We should use ranges if we have multiple compile units or
       // allow reordering of code ala .subsections_via_symbols in mach-o.
       DwarfCompileUnit *U = SkCU ? SkCU : static_cast<DwarfCompileUnit *>(TheU);
-      if ((DwarfCURanges || TargetMachine::getFunctionSections()) &&
-          TheU->getRanges().size())
+      if (useCURanges() && TheU->getRanges().size())
         addSectionLabel(Asm, U, U->getUnitDie(), dwarf::DW_AT_ranges,
                         Asm->GetTempSymbol("cu_ranges", U->getUniqueID()),
                         DwarfDebugRangeSectionSym);
@@ -2910,7 +2913,7 @@ void DwarfDebug::emitDebugRanges() {
     }
 
     // Now emit a range for the CU itself.
-    if (DwarfCURanges) {
+    if (useCURanges()) {
       Asm->OutStreamer.EmitLabel(
           Asm->GetTempSymbol("cu_ranges", TheCU->getUniqueID()));
       const SmallVectorImpl<RangeSpan> &Ranges = TheCU->getRanges();
index 5a21106055420e7b8e29a7c5b31974d84b0a2dcd..516def804d1533f577900bbc1ce55479d8ec5930 100644 (file)
@@ -458,6 +458,9 @@ class DwarfDebug : public AsmPrinterHandler {
   // Whether to emit the pubnames/pubtypes sections.
   bool HasDwarfPubSections;
 
+  // Whether or not to use AT_ranges for compilation units.
+  bool HasCURanges;
+
   // Version of dwarf we're emitting.
   unsigned DwarfVersion;
 
@@ -733,6 +736,9 @@ public:
   /// split dwarf proposal support.
   bool useSplitDwarf() { return HasSplitDwarf; }
 
+  /// \brief Returns whether or not to use AT_ranges for compilation units.
+  bool useCURanges() { return HasCURanges; }
+
   /// Returns the Dwarf Version.
   unsigned getDwarfVersion() const { return DwarfVersion; }
 
index 77561a4e633309957b9deb56b5ad845c1fdd2e9c..e582ea733247f5a87a7737bd82c5fd7085cd92c5 100644 (file)
@@ -1,5 +1,6 @@
 ; RUN: llc -split-dwarf=Enable -O0 %s -ffunction-sections -mtriple=x86_64-unknown-linux-gnu -filetype=obj -o %t
 ; RUN: llvm-dwarfdump -debug-dump=all %t | FileCheck --check-prefix=FUNCTION-SECTIONS %s
+; RUN: llvm-readobj --relocations %t | FileCheck --check-prefix=FUNCTION-SECTIONS-RELOCS %s
 
 ; RUN: llc -split-dwarf=Enable -O0 %s -mtriple=x86_64-unknown-linux-gnu -filetype=obj -o %t
 ; RUN: llvm-dwarfdump -debug-dump=all %t | FileCheck --check-prefix=NO-FUNCTION-SECTIONS %s
@@ -12,6 +13,9 @@
 ; With function sections enabled make sure that we have a DW_AT_ranges attribute.
 ; FUNCTION-SECTIONS: DW_AT_ranges
 
+; Check that we have a relocation against the .debug_ranges section.
+; FUNCTION-SECTIONS-RELOCS: R_X86_64_32 .debug_ranges 0x0
+
 ; Without function sections enabled make sure that we have no DW_AT_ranges attribute.
 ; NO-FUNCTION-SECTIONS-NOT: DW_AT_ranges