Index: include/llvm/DebugInfo/DWARF/DWARFObject.h
===================================================================
--- include/llvm/DebugInfo/DWARF/DWARFObject.h
+++ include/llvm/DebugInfo/DWARF/DWARFObject.h
@@ -29,6 +29,7 @@
   virtual ~DWARFObject() = default;
   virtual StringRef getFileName() const { llvm_unreachable("unimplemented"); }
   virtual const object::ObjectFile *getFile() const { return nullptr; }
+  virtual ArrayRef<SectionInfo> getSections() const { return {}; }
   virtual bool isLittleEndian() const = 0;
   virtual uint8_t getAddressSize() const { llvm_unreachable("unimplemented"); }
   virtual const DWARFSection &getInfoSection() const { return Dummy; }
Index: include/llvm/DebugInfo/DWARF/DWARFSection.h
===================================================================
--- include/llvm/DebugInfo/DWARF/DWARFSection.h
+++ include/llvm/DebugInfo/DWARF/DWARFSection.h
@@ -19,6 +19,11 @@
   StringRef Data;
 };
 
+struct SectionInfo {
+  StringRef Name;
+  bool IsNameUnique;
+};
+
 } // end namespace llvm
 
 #endif // LLVM_DEBUGINFO_DWARF_DWARFSECTION_H
Index: lib/DebugInfo/DWARF/DWARFContext.cpp
===================================================================
--- lib/DebugInfo/DWARF/DWARFContext.cpp
+++ lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -934,6 +934,7 @@
   uint8_t AddressSize;
   StringRef FileName;
   const object::ObjectFile *Obj = nullptr;
+  std::vector<SectionInfo> Sections;
 
   using TypeSectionMap = MapVector<object::SectionRef, DWARFSectionMap,
                                    std::map<object::SectionRef, unsigned>>;
@@ -1055,9 +1056,14 @@
         AddressSize(Obj.getBytesInAddress()), FileName(Obj.getFileName()),
         Obj(&Obj) {
 
+    StringMap<unsigned> SectionAmountMap;
     for (const SectionRef &Section : Obj.sections()) {
       StringRef Name;
       Section.getName(Name);
+
+      ++SectionAmountMap[Name];
+      Sections.push_back({Name, true});
+
       // Skip BSS and Virtual sections, they aren't interesting.
       if (Section.isBSS() || Section.isVirtual())
         continue;
@@ -1179,6 +1185,10 @@
         Map->insert({Reloc.getOffset(), Rel});
       }
     }
+
+    for (SectionInfo &Info : Sections)
+      if (SectionAmountMap[Info.Name] > 1)
+        Info.IsNameUnique = false;
   }
 
   Optional<RelocAddrEntry> find(const DWARFSection &S,
@@ -1192,6 +1202,8 @@
 
   const object::ObjectFile *getFile() const override { return Obj; }
 
+  ArrayRef<SectionInfo> getSections() const override { return Sections; }
+
   bool isLittleEndian() const override { return IsLittleEndian; }
   StringRef getAbbrevDWOSection() const override { return AbbrevDWOSection; }
   const DWARFSection &getLineDWOSection() const override {
Index: lib/DebugInfo/DWARF/DWARFDie.cpp
===================================================================
--- lib/DebugInfo/DWARF/DWARFDie.cpp
+++ lib/DebugInfo/DWARF/DWARFDie.cpp
@@ -57,18 +57,9 @@
                        const DWARFAddressRangesVector &Ranges,
                        unsigned AddressSize, unsigned Indent,
                        const DIDumpOptions &DumpOpts) {
-  StringMap<unsigned> SectionAmountMap;
-  std::vector<StringRef> SectionNames;
-  if (Obj.getFile() && !DumpOpts.Brief) {
-    for (const SectionRef &Section : Obj.getFile()->sections()) {
-      StringRef Name;
-      if (Section.getName(Name))
-        Name = "<error>";
-
-      ++SectionAmountMap[Name];
-      SectionNames.push_back(Name);
-    }
-  }
+  ArrayRef<SectionInfo> Sections;
+  if (!DumpOpts.Brief)
+    Sections = Obj.getSections();
 
   for (size_t I = 0; I < Ranges.size(); ++I) {
     const DWARFAddressRange &R = Ranges[I];
@@ -78,16 +69,14 @@
     OS << format("[0x%0*" PRIx64 " - 0x%0*" PRIx64 ")", AddressSize * 2,
                  R.LowPC, AddressSize * 2, R.HighPC);
 
-    if (SectionNames.empty() || R.SectionIndex == -1ULL)
+    if (DumpOpts.Brief || Sections.empty() || R.SectionIndex == -1ULL)
       continue;
 
-    StringRef Name = R.SectionIndex < SectionNames.size()
-                         ? SectionNames[R.SectionIndex]
-                         : "<error>";
+    StringRef Name = Sections[R.SectionIndex].Name;
     OS << format(" \"%s\"", Name.str().c_str());
 
-    // Print section index if there is more than one section with this name.
-    if (SectionAmountMap[Name] > 1)
+    // Print section index if name is not unique.
+    if (!Sections[R.SectionIndex].IsNameUnique)
       OS << format(" [%u]", R.SectionIndex);
   }
 }