Ver código fonte

DebugInfo: Add a CU metadata attribute for use of DWARF ranges base address specifiers

Summary:
Ranges base address specifiers can save a lot of object size in
relocation records especially in optimized builds.

For an optimized self-host build of Clang with split DWARF and debug
info compression in object files, but uncompressed debug info in the
executable, this change produces about 18% smaller object files and 6%
larger executable.

While it would've been nice to turn this on by default, gold's 32 bit
gdb-index support crashes on this input & I don't think there's any
perfect heuristic to implement solely in LLVM that would suffice - so
we'll need a flag one way or another (also possible people might want to
aggressively optimized for executable size that contains debug info
(even with compression this would still come at some cost to executable
size)) - so let's plumb it through.

Differential Revision: https://reviews.llvm.org/D54242

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346788 91177308-0d34-0410-b5e6-96231b3b80d8
David Blaikie 6 anos atrás
pai
commit
ecc582a8ce

+ 2 - 1
include/llvm/IR/DIBuilder.h

@@ -145,7 +145,8 @@ namespace llvm {
                       uint64_t DWOId = 0, bool SplitDebugInlining = true,
                       uint64_t DWOId = 0, bool SplitDebugInlining = true,
                       bool DebugInfoForProfiling = false,
                       bool DebugInfoForProfiling = false,
                       DICompileUnit::DebugNameTableKind NameTableKind =
                       DICompileUnit::DebugNameTableKind NameTableKind =
-                          DICompileUnit::DebugNameTableKind::Default);
+                          DICompileUnit::DebugNameTableKind::Default,
+                      bool RangesBaseAddress = false);
 
 
     /// Create a file descriptor to hold debugging information for a file.
     /// Create a file descriptor to hold debugging information for a file.
     /// \param Filename  File name.
     /// \param Filename  File name.

+ 32 - 25
include/llvm/IR/DebugInfoMetadata.h

@@ -1192,18 +1192,19 @@ private:
   bool SplitDebugInlining;
   bool SplitDebugInlining;
   bool DebugInfoForProfiling;
   bool DebugInfoForProfiling;
   unsigned NameTableKind;
   unsigned NameTableKind;
+  bool RangesBaseAddress;
 
 
   DICompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
   DICompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
                 bool IsOptimized, unsigned RuntimeVersion,
                 bool IsOptimized, unsigned RuntimeVersion,
                 unsigned EmissionKind, uint64_t DWOId, bool SplitDebugInlining,
                 unsigned EmissionKind, uint64_t DWOId, bool SplitDebugInlining,
                 bool DebugInfoForProfiling, unsigned NameTableKind,
                 bool DebugInfoForProfiling, unsigned NameTableKind,
-                ArrayRef<Metadata *> Ops)
+                bool RangesBaseAddress, ArrayRef<Metadata *> Ops)
       : DIScope(C, DICompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
       : DIScope(C, DICompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
         SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
         SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
         RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind),
         RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind),
         DWOId(DWOId), SplitDebugInlining(SplitDebugInlining),
         DWOId(DWOId), SplitDebugInlining(SplitDebugInlining),
         DebugInfoForProfiling(DebugInfoForProfiling),
         DebugInfoForProfiling(DebugInfoForProfiling),
-        NameTableKind(NameTableKind) {
+        NameTableKind(NameTableKind), RangesBaseAddress(RangesBaseAddress) {
     assert(Storage != Uniqued);
     assert(Storage != Uniqued);
   }
   }
   ~DICompileUnit() = default;
   ~DICompileUnit() = default;
@@ -1217,15 +1218,16 @@ private:
           DIGlobalVariableExpressionArray GlobalVariables,
           DIGlobalVariableExpressionArray GlobalVariables,
           DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
           DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
           uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
           uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
-          unsigned NameTableKind, StorageType Storage,
+          unsigned NameTableKind, bool RangesBaseAddress, StorageType Storage,
           bool ShouldCreate = true) {
           bool ShouldCreate = true) {
-    return getImpl(
-        Context, SourceLanguage, File, getCanonicalMDString(Context, Producer),
-        IsOptimized, getCanonicalMDString(Context, Flags), RuntimeVersion,
-        getCanonicalMDString(Context, SplitDebugFilename), EmissionKind,
-        EnumTypes.get(), RetainedTypes.get(), GlobalVariables.get(),
-        ImportedEntities.get(), Macros.get(), DWOId, SplitDebugInlining,
-        DebugInfoForProfiling, NameTableKind, Storage, ShouldCreate);
+    return getImpl(Context, SourceLanguage, File,
+                   getCanonicalMDString(Context, Producer), IsOptimized,
+                   getCanonicalMDString(Context, Flags), RuntimeVersion,
+                   getCanonicalMDString(Context, SplitDebugFilename),
+                   EmissionKind, EnumTypes.get(), RetainedTypes.get(),
+                   GlobalVariables.get(), ImportedEntities.get(), Macros.get(),
+                   DWOId, SplitDebugInlining, DebugInfoForProfiling,
+                   NameTableKind, RangesBaseAddress, Storage, ShouldCreate);
   }
   }
   static DICompileUnit *
   static DICompileUnit *
   getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
   getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
@@ -1235,16 +1237,16 @@ private:
           Metadata *GlobalVariables, Metadata *ImportedEntities,
           Metadata *GlobalVariables, Metadata *ImportedEntities,
           Metadata *Macros, uint64_t DWOId, bool SplitDebugInlining,
           Metadata *Macros, uint64_t DWOId, bool SplitDebugInlining,
           bool DebugInfoForProfiling, unsigned NameTableKind,
           bool DebugInfoForProfiling, unsigned NameTableKind,
-          StorageType Storage, bool ShouldCreate = true);
+          bool RangesBaseAddress, StorageType Storage, bool ShouldCreate = true);
 
 
   TempDICompileUnit cloneImpl() const {
   TempDICompileUnit cloneImpl() const {
-    return getTemporary(getContext(), getSourceLanguage(), getFile(),
-                        getProducer(), isOptimized(), getFlags(),
-                        getRuntimeVersion(), getSplitDebugFilename(),
-                        getEmissionKind(), getEnumTypes(), getRetainedTypes(),
-                        getGlobalVariables(), getImportedEntities(),
-                        getMacros(), DWOId, getSplitDebugInlining(),
-                        getDebugInfoForProfiling(), getNameTableKind());
+    return getTemporary(
+        getContext(), getSourceLanguage(), getFile(), getProducer(),
+        isOptimized(), getFlags(), getRuntimeVersion(), getSplitDebugFilename(),
+        getEmissionKind(), getEnumTypes(), getRetainedTypes(),
+        getGlobalVariables(), getImportedEntities(), getMacros(), DWOId,
+        getSplitDebugInlining(), getDebugInfoForProfiling(), getNameTableKind(),
+        getRangesBaseAddress());
   }
   }
 
 
 public:
 public:
@@ -1260,11 +1262,11 @@ public:
        DIGlobalVariableExpressionArray GlobalVariables,
        DIGlobalVariableExpressionArray GlobalVariables,
        DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
        DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
        uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
        uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
-       DebugNameTableKind NameTableKind),
+       DebugNameTableKind NameTableKind, bool RangesBaseAddress),
       (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
       (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
        SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
        SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
        GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
        GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
-       DebugInfoForProfiling, (unsigned)NameTableKind))
+       DebugInfoForProfiling, (unsigned)NameTableKind, RangesBaseAddress))
   DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(
   DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(
       DICompileUnit,
       DICompileUnit,
       (unsigned SourceLanguage, Metadata *File, MDString *Producer,
       (unsigned SourceLanguage, Metadata *File, MDString *Producer,
@@ -1273,11 +1275,11 @@ public:
        Metadata *RetainedTypes, Metadata *GlobalVariables,
        Metadata *RetainedTypes, Metadata *GlobalVariables,
        Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId,
        Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId,
        bool SplitDebugInlining, bool DebugInfoForProfiling,
        bool SplitDebugInlining, bool DebugInfoForProfiling,
-       unsigned NameTableKind),
+       unsigned NameTableKind, bool RangesBaseAddress),
       (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
       (SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
        SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
        SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
        GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
        GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
-       DebugInfoForProfiling, NameTableKind))
+       DebugInfoForProfiling, NameTableKind, RangesBaseAddress))
 
 
   TempDICompileUnit clone() const { return cloneImpl(); }
   TempDICompileUnit clone() const { return cloneImpl(); }
 
 
@@ -1294,9 +1296,14 @@ public:
   DebugNameTableKind getNameTableKind() const {
   DebugNameTableKind getNameTableKind() const {
     return (DebugNameTableKind)NameTableKind;
     return (DebugNameTableKind)NameTableKind;
   }
   }
-  StringRef getProducer() const { return getStringOperand(1); }
-  StringRef getFlags() const { return getStringOperand(2); }
-  StringRef getSplitDebugFilename() const { return getStringOperand(3); }
+  bool getRangesBaseAddress() const {
+    return RangesBaseAddress; }
+  StringRef getProducer() const {
+    return getStringOperand(1); }
+  StringRef getFlags() const {
+    return getStringOperand(2); }
+  StringRef getSplitDebugFilename() const {
+    return getStringOperand(3); }
   DICompositeTypeArray getEnumTypes() const {
   DICompositeTypeArray getEnumTypes() const {
     return cast_or_null<MDTuple>(getRawEnumTypes());
     return cast_or_null<MDTuple>(getRawEnumTypes());
   }
   }

+ 4 - 2
lib/AsmParser/LLParser.cpp

@@ -4497,7 +4497,8 @@ bool LLParser::ParseDICompileUnit(MDNode *&Result, bool IsDistinct) {
   OPTIONAL(dwoId, MDUnsignedField, );                                          \
   OPTIONAL(dwoId, MDUnsignedField, );                                          \
   OPTIONAL(splitDebugInlining, MDBoolField, = true);                           \
   OPTIONAL(splitDebugInlining, MDBoolField, = true);                           \
   OPTIONAL(debugInfoForProfiling, MDBoolField, = false);                       \
   OPTIONAL(debugInfoForProfiling, MDBoolField, = false);                       \
-  OPTIONAL(nameTableKind, NameTableKindField, );
+  OPTIONAL(nameTableKind, NameTableKindField, );                               \
+  OPTIONAL(debugBaseAddress, MDBoolField, = false);
   PARSE_MD_FIELDS();
   PARSE_MD_FIELDS();
 #undef VISIT_MD_FIELDS
 #undef VISIT_MD_FIELDS
 
 
@@ -4505,7 +4506,8 @@ bool LLParser::ParseDICompileUnit(MDNode *&Result, bool IsDistinct) {
       Context, language.Val, file.Val, producer.Val, isOptimized.Val, flags.Val,
       Context, language.Val, file.Val, producer.Val, isOptimized.Val, flags.Val,
       runtimeVersion.Val, splitDebugFilename.Val, emissionKind.Val, enums.Val,
       runtimeVersion.Val, splitDebugFilename.Val, emissionKind.Val, enums.Val,
       retainedTypes.Val, globals.Val, imports.Val, macros.Val, dwoId.Val,
       retainedTypes.Val, globals.Val, imports.Val, macros.Val, dwoId.Val,
-      splitDebugInlining.Val, debugInfoForProfiling.Val, nameTableKind.Val);
+      splitDebugInlining.Val, debugInfoForProfiling.Val, nameTableKind.Val,
+      debugBaseAddress.Val);
   return false;
   return false;
 }
 }
 
 

+ 2 - 1
lib/Bitcode/Reader/MetadataLoader.cpp

@@ -1395,7 +1395,8 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
         Record.size() <= 14 ? 0 : Record[14],
         Record.size() <= 14 ? 0 : Record[14],
         Record.size() <= 16 ? true : Record[16],
         Record.size() <= 16 ? true : Record[16],
         Record.size() <= 17 ? false : Record[17],
         Record.size() <= 17 ? false : Record[17],
-        Record.size() <= 18 ? 0 : Record[18]);
+        Record.size() <= 18 ? 0 : Record[18],
+        Record.size() <= 19 ? 0 : Record[19]);
 
 
     MetadataList.assignValue(CU, NextMetadataNo);
     MetadataList.assignValue(CU, NextMetadataNo);
     NextMetadataNo++;
     NextMetadataNo++;

+ 1 - 1
lib/CodeGen/AsmPrinter/DwarfDebug.cpp

@@ -2287,7 +2287,7 @@ static void emitRangeList(DwarfDebug &DD, AsmPrinter *Asm,
     // contributions.
     // contributions.
     auto *Base = CUBase;
     auto *Base = CUBase;
     if (!Base && (P.second.size() > 1 || DwarfVersion < 5) &&
     if (!Base && (P.second.size() > 1 || DwarfVersion < 5) &&
-        (UseDwarfRangesBaseAddressSpecifier || DwarfVersion >= 5)) {
+        (CU.getCUNode()->getRangesBaseAddress() || DwarfVersion >= 5)) {
       BaseIsSet = true;
       BaseIsSet = true;
       // FIXME/use care: This may not be a useful base address if it's not
       // FIXME/use care: This may not be a useful base address if it's not
       // the lowest address/range in this object.
       // the lowest address/range in this object.

+ 1 - 0
lib/IR/AsmWriter.cpp

@@ -1910,6 +1910,7 @@ static void writeDICompileUnit(raw_ostream &Out, const DICompileUnit *N,
   Printer.printBool("debugInfoForProfiling", N->getDebugInfoForProfiling(),
   Printer.printBool("debugInfoForProfiling", N->getDebugInfoForProfiling(),
                     false);
                     false);
   Printer.printNameTableKind("nameTableKind", N->getNameTableKind());
   Printer.printNameTableKind("nameTableKind", N->getNameTableKind());
+  Printer.printBool("rangesBaseAddress", N->getRangesBaseAddress(), false);
   Out << ")";
   Out << ")";
 }
 }
 
 

+ 3 - 2
lib/IR/DIBuilder.cpp

@@ -140,7 +140,7 @@ DICompileUnit *DIBuilder::createCompileUnit(
     StringRef Flags, unsigned RunTimeVer, StringRef SplitName,
     StringRef Flags, unsigned RunTimeVer, StringRef SplitName,
     DICompileUnit::DebugEmissionKind Kind, uint64_t DWOId,
     DICompileUnit::DebugEmissionKind Kind, uint64_t DWOId,
     bool SplitDebugInlining, bool DebugInfoForProfiling,
     bool SplitDebugInlining, bool DebugInfoForProfiling,
-    DICompileUnit::DebugNameTableKind NameTableKind) {
+    DICompileUnit::DebugNameTableKind NameTableKind, bool RangesBaseAddress) {
 
 
   assert(((Lang <= dwarf::DW_LANG_Fortran08 && Lang >= dwarf::DW_LANG_C89) ||
   assert(((Lang <= dwarf::DW_LANG_Fortran08 && Lang >= dwarf::DW_LANG_C89) ||
           (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) &&
           (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) &&
@@ -150,7 +150,8 @@ DICompileUnit *DIBuilder::createCompileUnit(
   CUNode = DICompileUnit::getDistinct(
   CUNode = DICompileUnit::getDistinct(
       VMContext, Lang, File, Producer, isOptimized, Flags, RunTimeVer,
       VMContext, Lang, File, Producer, isOptimized, Flags, RunTimeVer,
       SplitName, Kind, nullptr, nullptr, nullptr, nullptr, nullptr, DWOId,
       SplitName, Kind, nullptr, nullptr, nullptr, nullptr, nullptr, DWOId,
-      SplitDebugInlining, DebugInfoForProfiling, NameTableKind);
+      SplitDebugInlining, DebugInfoForProfiling, NameTableKind,
+      RangesBaseAddress);
 
 
   // Create a named metadata so that it is easier to find cu in a module.
   // Create a named metadata so that it is easier to find cu in a module.
   NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
   NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");

+ 2 - 1
lib/IR/DebugInfo.cpp

@@ -491,7 +491,8 @@ private:
         CU->getSplitDebugFilename(), DICompileUnit::LineTablesOnly, EnumTypes,
         CU->getSplitDebugFilename(), DICompileUnit::LineTablesOnly, EnumTypes,
         RetainedTypes, GlobalVariables, ImportedEntities, CU->getMacros(),
         RetainedTypes, GlobalVariables, ImportedEntities, CU->getMacros(),
         CU->getDWOId(), CU->getSplitDebugInlining(),
         CU->getDWOId(), CU->getSplitDebugInlining(),
-        CU->getDebugInfoForProfiling(), CU->getNameTableKind());
+        CU->getDebugInfoForProfiling(), CU->getNameTableKind(),
+        CU->getRangesBaseAddress());
   }
   }
 
 
   DILocation *getReplacementMDLocation(DILocation *MLD) {
   DILocation *getReplacementMDLocation(DILocation *MLD) {

+ 4 - 2
lib/IR/DebugInfoMetadata.cpp

@@ -470,7 +470,8 @@ DICompileUnit *DICompileUnit::getImpl(
     unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
     unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
     Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata *Macros,
     Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata *Macros,
     uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
     uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
-    unsigned NameTableKind, StorageType Storage, bool ShouldCreate) {
+    unsigned NameTableKind, bool RangesBaseAddress, StorageType Storage,
+    bool ShouldCreate) {
   assert(Storage != Uniqued && "Cannot unique DICompileUnit");
   assert(Storage != Uniqued && "Cannot unique DICompileUnit");
   assert(isCanonical(Producer) && "Expected canonical MDString");
   assert(isCanonical(Producer) && "Expected canonical MDString");
   assert(isCanonical(Flags) && "Expected canonical MDString");
   assert(isCanonical(Flags) && "Expected canonical MDString");
@@ -483,7 +484,8 @@ DICompileUnit *DICompileUnit::getImpl(
   return storeImpl(new (array_lengthof(Ops)) DICompileUnit(
   return storeImpl(new (array_lengthof(Ops)) DICompileUnit(
                        Context, Storage, SourceLanguage, IsOptimized,
                        Context, Storage, SourceLanguage, IsOptimized,
                        RuntimeVersion, EmissionKind, DWOId, SplitDebugInlining,
                        RuntimeVersion, EmissionKind, DWOId, SplitDebugInlining,
-                       DebugInfoForProfiling, NameTableKind, Ops),
+                       DebugInfoForProfiling, NameTableKind, RangesBaseAddress,
+                       Ops),
                    Storage);
                    Storage);
 }
 }
 
 

+ 103 - 67
test/DebugInfo/X86/range_reloc.ll

@@ -1,5 +1,4 @@
-; RUN: llc -filetype=asm -mtriple=x86_64-pc-linux-gnu %s -o - -use-dwarf-ranges-base-address-specifier | FileCheck --check-prefix=COMMON --check-prefix=BASE %s
-; RUN: llc -filetype=asm -mtriple=x86_64-pc-linux-gnu %s -o - | FileCheck --check-prefix=COMMON --check-prefix=NOBASE %s
+; RUN: llc -filetype=asm -mtriple=x86_64-pc-linux-gnu %s -o - | FileCheck %s
 ; RUN: llc -filetype=asm -mtriple=x86_64-pc-linux-gnu %s -o - -dwarf-version 5 | FileCheck --check-prefix=DWARF5 %s
 ; RUN: llc -filetype=asm -mtriple=x86_64-pc-linux-gnu %s -o - -dwarf-version 5 | FileCheck --check-prefix=DWARF5 %s
 
 
 ; Group ranges in a range list that apply to the same section and use a base
 ; Group ranges in a range list that apply to the same section and use a base
@@ -15,38 +14,51 @@
 ; in the linked executable. Without compression in the objects, the win would be
 ; in the linked executable. Without compression in the objects, the win would be
 ; smaller (the growth of debug_ranges itself would be more significant).
 ; smaller (the growth of debug_ranges itself would be more significant).
 
 
-; COMMON: {{^.Ldebug_ranges0}}
-; NOBASE-NEXT:   .quad   .Lfunc_begin0
-; NOBASE-NEXT:   .quad   .Lfunc_end0
-; NOBASE-NEXT:   .quad   .Lfunc_begin1
-; NOBASE-NEXT:   .quad   .Lfunc_end1
-; NOBASE-NEXT:   .quad   .Lfunc_begin3
-; NOBASE-NEXT:   .quad   .Lfunc_end3
-; NOBASE-NEXT:   .quad   .Lfunc_begin4
-; NOBASE-NEXT:   .quad   .Lfunc_end4
-; NOBASE-NEXT:   .quad   .Lfunc_begin5
-; NOBASE-NEXT:   .quad   .Lfunc_end5
-
-; BASE-NEXT:   .quad   -1
-; BASE-NEXT:   .quad   .Lfunc_begin0
-; BASE-NEXT:   .quad   .Lfunc_begin0-.Lfunc_begin0
-; BASE-NEXT:   .quad   .Lfunc_end0-.Lfunc_begin0
-; BASE-NEXT:   .quad   -1
-; BASE-NEXT:   .quad   .Lfunc_begin1
-; BASE-NEXT:   .quad   .Lfunc_begin1-.Lfunc_begin1
-; BASE-NEXT:   .quad   .Lfunc_end1-.Lfunc_begin1
-; BASE-NEXT:   .quad   .Lfunc_begin3-.Lfunc_begin1
-; BASE-NEXT:   .quad   .Lfunc_end3-.Lfunc_begin1
-; BASE-NEXT:   .quad   -1
-; BASE-NEXT:   .quad   .Lfunc_begin4
-; BASE-NEXT:   .quad   .Lfunc_begin4-.Lfunc_begin4
-; BASE-NEXT:   .quad   .Lfunc_end4-.Lfunc_begin4
-; BASE-NEXT:   .quad   -1
-; BASE-NEXT:   .quad   .Lfunc_begin5
-; BASE-NEXT:   .quad   .Lfunc_begin5-.Lfunc_begin5
-; BASE-NEXT:   .quad   .Lfunc_end5-.Lfunc_begin5
-; COMMON-NEXT:   .quad   0
-; COMMON-NEXT:   .quad   0
+; This is a merged module containing two CUs, one that uses range base address
+; specifiers and exercises different cases there, and another that does not
+
+; ranges.cpp
+; Single range entry
+; __attribute__((section("a"))) void f1() {}
+; Single address with two ranges due to the whole caused by f3
+; __attribute__((section("b"))) void f2() {}
+; __attribute__((section("b"))) __attribute__((nodebug)) void f3() {}
+; __attribute__((section("b"))) void f4() {}
+; Reset the base address & emit a couple more single range entries
+; __attribute__((section("c"))) void f5() {}
+; __attribute__((section("d"))) void f6() {}
+; ranges_no_base.cpp:
+; Include enough complexity to cause ranges to be emitted, so it can be checked
+; that those ranges don't use base address specifiers
+; __attribute__((section("e"))) void f7() {}
+; __attribute__((section("f"))) void f8() {}
+
+; CHECK: {{^.Ldebug_ranges0}}
+; CHECK-NEXT:   .quad   -1
+; CHECK-NEXT:   .quad   .Lfunc_begin0
+; CHECK-NEXT:   .quad   .Lfunc_begin0-.Lfunc_begin0
+; CHECK-NEXT:   .quad   .Lfunc_end0-.Lfunc_begin0
+; CHECK-NEXT:   .quad   -1
+; CHECK-NEXT:   .quad   .Lfunc_begin1
+; CHECK-NEXT:   .quad   .Lfunc_begin1-.Lfunc_begin1
+; CHECK-NEXT:   .quad   .Lfunc_end1-.Lfunc_begin1
+; CHECK-NEXT:   .quad   .Lfunc_begin3-.Lfunc_begin1
+; CHECK-NEXT:   .quad   .Lfunc_end3-.Lfunc_begin1
+; CHECK-NEXT:   .quad   -1
+; CHECK-NEXT:   .quad   .Lfunc_begin4
+; CHECK-NEXT:   .quad   .Lfunc_begin4-.Lfunc_begin4
+; CHECK-NEXT:   .quad   .Lfunc_end4-.Lfunc_begin4
+; CHECK-NEXT:   .quad   -1
+; CHECK-NEXT:   .quad   .Lfunc_begin5
+; CHECK-NEXT:   .quad   .Lfunc_begin5-.Lfunc_begin5
+; CHECK-NEXT:   .quad   .Lfunc_end5-.Lfunc_begin5
+; CHECK-NEXT:   .quad   0
+; CHECK-NEXT:   .quad   0
+; CHECK-NEXT: {{^.Ldebug_ranges1}}
+; CHECK-NEXT:   .quad   .Lfunc_begin6
+; CHECK-NEXT:   .quad   .Lfunc_end6
+; CHECK-NEXT:   .quad   .Lfunc_begin7
+; CHECK-NEXT:   .quad   .Lfunc_end7
 
 
 ; DWARF5: {{^.Ldebug_ranges0}}
 ; DWARF5: {{^.Ldebug_ranges0}}
 ; DWARF5-NEXT:                                      # DW_RLE_startx_length
 ; DWARF5-NEXT:                                      # DW_RLE_startx_length
@@ -67,65 +79,89 @@
 ; DWARF5-NEXT: .byte 4                              #   start index
 ; DWARF5-NEXT: .byte 4                              #   start index
 ; DWARF5-NEXT: .uleb128 .Lfunc_end5-.Lfunc_begin5   #   length
 ; DWARF5-NEXT: .uleb128 .Lfunc_end5-.Lfunc_begin5   #   length
 ; DWARF5-NEXT:                                      # DW_RLE_end_of_list
 ; DWARF5-NEXT:                                      # DW_RLE_end_of_list
+; DWARF5-NEXT: {{^.Ldebug_ranges1}}
+; DWARF5-NEXT:                                      # DW_RLE_startx_length
+; DWARF5-NEXT: .byte 5                              #   start index
+; DWARF5-NEXT: .uleb128 .Lfunc_end6-.Lfunc_begin6   #   length
+; DWARF5-NEXT:                                      # DW_RLE_startx_length
+; DWARF5-NEXT: .byte 6                              #   start index
+; DWARF5-NEXT: .uleb128 .Lfunc_end7-.Lfunc_begin7   #   length
+; DWARF5-NEXT:                                      # DW_RLE_end_of_list
 
 
 ; Function Attrs: noinline nounwind optnone uwtable
 ; Function Attrs: noinline nounwind optnone uwtable
-define void @_Z2f1v() #0 section "a" !dbg !7 {
+define dso_local void @_Z2f1v() section "a" !dbg !9 {
 entry:
 entry:
-  ret void, !dbg !10
+  ret void, !dbg !12
 }
 }
 
 
 ; Function Attrs: noinline nounwind optnone uwtable
 ; Function Attrs: noinline nounwind optnone uwtable
-define void @_Z2f2v() #0 section "b" !dbg !11 {
+define dso_local void @_Z2f2v() section "b" !dbg !13 {
 entry:
 entry:
-  ret void, !dbg !12
+  ret void, !dbg !14
 }
 }
 
 
 ; Function Attrs: noinline nounwind optnone uwtable
 ; Function Attrs: noinline nounwind optnone uwtable
-define void @_Z2f3v() #0 section "b" {
+define dso_local void @_Z2f3v() section "b" {
 entry:
 entry:
   ret void
   ret void
 }
 }
 
 
 ; Function Attrs: noinline nounwind optnone uwtable
 ; Function Attrs: noinline nounwind optnone uwtable
-define void @_Z2f4v() #0 section "b" !dbg !13 {
+define dso_local void @_Z2f4v() section "b" !dbg !15 {
 entry:
 entry:
-  ret void, !dbg !14
+  ret void, !dbg !16
 }
 }
 
 
 ; Function Attrs: noinline nounwind optnone uwtable
 ; Function Attrs: noinline nounwind optnone uwtable
-define void @_Z2f5v() #0 section "e" !dbg !15 {
+define dso_local void @_Z2f5v() section "c" !dbg !17 {
 entry:
 entry:
-  ret void, !dbg !16
+  ret void, !dbg !18
 }
 }
 
 
 ; Function Attrs: noinline nounwind optnone uwtable
 ; Function Attrs: noinline nounwind optnone uwtable
-define void @_Z2f6v() #0 section "f" !dbg !17 {
+define dso_local void @_Z2f6v() section "d" !dbg !19 {
 entry:
 entry:
-  ret void, !dbg !18
+  ret void, !dbg !20
+}
+
+; Function Attrs: noinline nounwind optnone uwtable
+define dso_local void @_Z2f7v() section "e" !dbg !21 {
+entry:
+  ret void, !dbg !22
 }
 }
 
 
-attributes #0 = { noinline nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
+; Function Attrs: noinline nounwind optnone uwtable
+define dso_local void @_Z2f8v() section "f" !dbg !23 {
+entry:
+  ret void, !dbg !24
+}
 
 
-!llvm.dbg.cu = !{!0}
-!llvm.module.flags = !{!3, !4, !5}
-!llvm.ident = !{!6}
+!llvm.dbg.cu = !{!0, !3}
+!llvm.ident = !{!5, !5}
+!llvm.module.flags = !{!6, !7, !8}
 
 
-!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 6.0.0 (trunk 309523) (llvm/trunk 309526)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
-!1 = !DIFile(filename: "funcs.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch")
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 8.0.0 (trunk 346343) (llvm/trunk 346350)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None, debugBaseAddress: true)
+!1 = !DIFile(filename: "ranges.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch")
 !2 = !{}
 !2 = !{}
-!3 = !{i32 2, !"Dwarf Version", i32 4}
-!4 = !{i32 2, !"Debug Info Version", i32 3}
-!5 = !{i32 1, !"wchar_size", i32 4}
-!6 = !{!"clang version 6.0.0 (trunk 309523) (llvm/trunk 309526)"}
-!7 = distinct !DISubprogram(name: "f1", linkageName: "_Z2f1v", scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
-!8 = !DISubroutineType(types: !9)
-!9 = !{null}
-!10 = !DILocation(line: 1, column: 42, scope: !7)
-!11 = distinct !DISubprogram(name: "f2", linkageName: "_Z2f2v", scope: !1, file: !1, line: 2, type: !8, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
-!12 = !DILocation(line: 2, column: 42, scope: !11)
-!13 = distinct !DISubprogram(name: "f4", linkageName: "_Z2f4v", scope: !1, file: !1, line: 4, type: !8, isLocal: false, isDefinition: true, scopeLine: 4, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
-!14 = !DILocation(line: 4, column: 42, scope: !13)
-!15 = distinct !DISubprogram(name: "f5", linkageName: "_Z2f5v", scope: !1, file: !1, line: 5, type: !8, isLocal: false, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
-!16 = !DILocation(line: 5, column: 42, scope: !15)
-!17 = distinct !DISubprogram(name: "f6", linkageName: "_Z2f6v", scope: !1, file: !1, line: 6, type: !8, isLocal: false, isDefinition: true, scopeLine: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
-!18 = !DILocation(line: 6, column: 42, scope: !17)
+!3 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !4, producer: "clang version 8.0.0 (trunk 346343) (llvm/trunk 346350)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
+!4 = !DIFile(filename: "ranges_no_base.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch")
+!5 = !{!"clang version 8.0.0 (trunk 346343) (llvm/trunk 346350)"}
+!6 = !{i32 2, !"Dwarf Version", i32 4}
+!7 = !{i32 2, !"Debug Info Version", i32 3}
+!8 = !{i32 1, !"wchar_size", i32 4}
+!9 = distinct !DISubprogram(name: "f1", linkageName: "_Z2f1v", scope: !1, file: !1, line: 1, type: !10, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
+!10 = !DISubroutineType(types: !11)
+!11 = !{null}
+!12 = !DILocation(line: 1, column: 42, scope: !9)
+!13 = distinct !DISubprogram(name: "f2", linkageName: "_Z2f2v", scope: !1, file: !1, line: 2, type: !10, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
+!14 = !DILocation(line: 2, column: 42, scope: !13)
+!15 = distinct !DISubprogram(name: "f4", linkageName: "_Z2f4v", scope: !1, file: !1, line: 4, type: !10, isLocal: false, isDefinition: true, scopeLine: 4, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
+!16 = !DILocation(line: 4, column: 42, scope: !15)
+!17 = distinct !DISubprogram(name: "f5", linkageName: "_Z2f5v", scope: !1, file: !1, line: 5, type: !10, isLocal: false, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
+!18 = !DILocation(line: 5, column: 42, scope: !17)
+!19 = distinct !DISubprogram(name: "f6", linkageName: "_Z2f6v", scope: !1, file: !1, line: 6, type: !10, isLocal: false, isDefinition: true, scopeLine: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
+!20 = !DILocation(line: 6, column: 42, scope: !19)
+!21 = distinct !DISubprogram(name: "f7", linkageName: "_Z2f7v", scope: !4, file: !4, line: 1, type: !10, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, unit: !3, retainedNodes: !2)
+!22 = !DILocation(line: 1, column: 42, scope: !21)
+!23 = distinct !DISubprogram(name: "f8", linkageName: "_Z2f8v", scope: !4, file: !4, line: 2, type: !10, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: false, unit: !3, retainedNodes: !2)
+!24 = !DILocation(line: 2, column: 42, scope: !23)

+ 3 - 3
unittests/IR/MetadataTest.cpp

@@ -96,7 +96,7 @@ protected:
         Context, 1, getFile(), "clang", false, "-g", 2, "",
         Context, 1, getFile(), "clang", false, "-g", 2, "",
         DICompileUnit::FullDebug, getTuple(), getTuple(), getTuple(),
         DICompileUnit::FullDebug, getTuple(), getTuple(), getTuple(),
         getTuple(), getTuple(), 0, true, false,
         getTuple(), getTuple(), 0, true, false,
-        DICompileUnit::DebugNameTableKind::Default);
+        DICompileUnit::DebugNameTableKind::Default, false);
   }
   }
   DIType *getBasicType(StringRef Name) {
   DIType *getBasicType(StringRef Name) {
     return DIBasicType::get(Context, dwarf::DW_TAG_unspecified_type, Name);
     return DIBasicType::get(Context, dwarf::DW_TAG_unspecified_type, Name);
@@ -1607,7 +1607,7 @@ TEST_F(DICompileUnitTest, get) {
       Context, SourceLanguage, File, Producer, IsOptimized, Flags,
       Context, SourceLanguage, File, Producer, IsOptimized, Flags,
       RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes,
       RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes,
       RetainedTypes, GlobalVariables, ImportedEntities, Macros, DWOId, true,
       RetainedTypes, GlobalVariables, ImportedEntities, Macros, DWOId, true,
-      false, DICompileUnit::DebugNameTableKind::Default);
+      false, DICompileUnit::DebugNameTableKind::Default, false);
 
 
   EXPECT_EQ(dwarf::DW_TAG_compile_unit, N->getTag());
   EXPECT_EQ(dwarf::DW_TAG_compile_unit, N->getTag());
   EXPECT_EQ(SourceLanguage, N->getSourceLanguage());
   EXPECT_EQ(SourceLanguage, N->getSourceLanguage());
@@ -1665,7 +1665,7 @@ TEST_F(DICompileUnitTest, replaceArrays) {
       Context, SourceLanguage, File, Producer, IsOptimized, Flags,
       Context, SourceLanguage, File, Producer, IsOptimized, Flags,
       RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes,
       RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes,
       RetainedTypes, nullptr, ImportedEntities, nullptr, DWOId, true, false,
       RetainedTypes, nullptr, ImportedEntities, nullptr, DWOId, true, false,
-      DICompileUnit::DebugNameTableKind::Default);
+      DICompileUnit::DebugNameTableKind::Default, false);
 
 
   auto *GlobalVariables = MDTuple::getDistinct(Context, None);
   auto *GlobalVariables = MDTuple::getDistinct(Context, None);
   EXPECT_EQ(nullptr, N->getGlobalVariables().get());
   EXPECT_EQ(nullptr, N->getGlobalVariables().get());