[llvm] r305371 - Revert "[codeview] Make obj2yaml/yaml2obj support .debug$S..."

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 13 23:24:24 PDT 2017


Author: zturner
Date: Wed Jun 14 01:24:24 2017
New Revision: 305371

URL: http://llvm.org/viewvc/llvm-project?rev=305371&view=rev
Log:
Revert "[codeview] Make obj2yaml/yaml2obj support .debug$S..."

This is causing failures on linux bots with an invalid stream
read.  It doesn't repro in any configuration on Windows, so
reverting until I have a chance to investigate on Linux.

Removed:
    llvm/trunk/include/llvm/DebugInfo/CodeView/StringsAndChecksums.h
    llvm/trunk/lib/DebugInfo/CodeView/StringsAndChecksums.cpp
Modified:
    llvm/trunk/include/llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h
    llvm/trunk/include/llvm/DebugInfo/CodeView/DebugSubsectionRecord.h
    llvm/trunk/include/llvm/DebugInfo/CodeView/DebugSubsectionVisitor.h
    llvm/trunk/include/llvm/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.h
    llvm/trunk/include/llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h
    llvm/trunk/include/llvm/ObjectYAML/COFFYAML.h
    llvm/trunk/include/llvm/ObjectYAML/CodeViewYAMLDebugSections.h
    llvm/trunk/include/llvm/ObjectYAML/CodeViewYAMLTypes.h
    llvm/trunk/lib/DebugInfo/CodeView/CMakeLists.txt
    llvm/trunk/lib/DebugInfo/CodeView/DebugStringTableSubsection.cpp
    llvm/trunk/lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp
    llvm/trunk/lib/DebugInfo/CodeView/DebugSubsectionVisitor.cpp
    llvm/trunk/lib/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.cpp
    llvm/trunk/lib/DebugInfo/PDB/Native/PDBStringTableBuilder.cpp
    llvm/trunk/lib/ObjectYAML/COFFYAML.cpp
    llvm/trunk/lib/ObjectYAML/CodeViewYAMLDebugSections.cpp
    llvm/trunk/lib/ObjectYAML/CodeViewYAMLTypes.cpp
    llvm/trunk/tools/llvm-pdbutil/LLVMOutputStyle.cpp
    llvm/trunk/tools/llvm-pdbutil/YAMLOutputStyle.cpp
    llvm/trunk/tools/llvm-pdbutil/llvm-pdbutil.cpp
    llvm/trunk/tools/obj2yaml/coff2yaml.cpp
    llvm/trunk/tools/yaml2obj/yaml2coff.cpp

Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h?rev=305371&r1=305370&r2=305371&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h Wed Jun 14 01:24:24 2017
@@ -49,7 +49,6 @@ public:
   Error commit(BinaryStreamWriter &Writer) const override;
 
   void addFrameData(const FrameData &Frame);
-  void setFrames(ArrayRef<FrameData> Frames);
 
 private:
   std::vector<FrameData> Frames;

Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/DebugSubsectionRecord.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/DebugSubsectionRecord.h?rev=305371&r1=305370&r2=305371&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/DebugSubsectionRecord.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/DebugSubsectionRecord.h Wed Jun 14 01:24:24 2017
@@ -49,13 +49,13 @@ private:
 
 class DebugSubsectionRecordBuilder {
 public:
-  DebugSubsectionRecordBuilder(std::shared_ptr<DebugSubsection> Subsection,
+  DebugSubsectionRecordBuilder(std::unique_ptr<DebugSubsection> Subsection,
                                CodeViewContainer Container);
   uint32_t calculateSerializedLength();
   Error commit(BinaryStreamWriter &Writer) const;
 
 private:
-  std::shared_ptr<DebugSubsection> Subsection;
+  std::unique_ptr<DebugSubsection> Subsection;
   CodeViewContainer Container;
 };
 
@@ -64,9 +64,6 @@ private:
 template <> struct VarStreamArrayExtractor<codeview::DebugSubsectionRecord> {
   Error operator()(BinaryStreamRef Stream, uint32_t &Length,
                    codeview::DebugSubsectionRecord &Info) {
-    // FIXME: We need to pass the container type through to this function.  In
-    // practice this isn't super important since the subsection header describes
-    // its length and we can just skip it.  It's more important when writing.
     if (auto EC = codeview::DebugSubsectionRecord::initialize(
             Stream, Info, codeview::CodeViewContainer::Pdb))
       return EC;

Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/DebugSubsectionVisitor.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/DebugSubsectionVisitor.h?rev=305371&r1=305370&r2=305371&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/DebugSubsectionVisitor.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/DebugSubsectionVisitor.h Wed Jun 14 01:24:24 2017
@@ -12,7 +12,6 @@
 
 #include "llvm/DebugInfo/CodeView/CodeView.h"
 #include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h"
-#include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
 #include "llvm/Support/Error.h"
 #include <cstdint>
 
@@ -31,7 +30,56 @@ class DebugStringTableSubsectionRef;
 class DebugSymbolRVASubsectionRef;
 class DebugSymbolsSubsectionRef;
 class DebugUnknownSubsectionRef;
-class StringsAndChecksumsRef;
+
+struct DebugSubsectionState {
+public:
+  // If no subsections are known about initially, we find as much as we can.
+  DebugSubsectionState();
+
+  // If only a string table subsection is given, we find a checksums subsection.
+  explicit DebugSubsectionState(const DebugStringTableSubsectionRef &Strings);
+
+  // If both subsections are given, we don't need to find anything.
+  DebugSubsectionState(const DebugStringTableSubsectionRef &Strings,
+                       const DebugChecksumsSubsectionRef &Checksums);
+
+  template <typename T> void initialize(T &&FragmentRange) {
+    for (const DebugSubsectionRecord &R : FragmentRange) {
+      if (Strings && Checksums)
+        return;
+      if (R.kind() == DebugSubsectionKind::FileChecksums) {
+        initializeChecksums(R);
+        continue;
+      }
+      if (R.kind() == DebugSubsectionKind::StringTable && !Strings) {
+        // While in practice we should never encounter a string table even
+        // though the string table is already initialized, in theory it's
+        // possible.  PDBs are supposed to have one global string table and
+        // then this subsection should not appear.  Whereas object files are
+        // supposed to have this subsection appear exactly once.  However,
+        // for testing purposes it's nice to be able to test this subsection
+        // independently of one format or the other, so for some tests we
+        // manually construct a PDB that contains this subsection in addition
+        // to a global string table.
+        initializeStrings(R);
+        continue;
+      }
+    }
+  }
+
+  const DebugStringTableSubsectionRef &strings() const { return *Strings; }
+  const DebugChecksumsSubsectionRef &checksums() const { return *Checksums; }
+
+private:
+  void initializeStrings(const DebugSubsectionRecord &SR);
+  void initializeChecksums(const DebugSubsectionRecord &FCR);
+
+  std::unique_ptr<DebugStringTableSubsectionRef> OwnedStrings;
+  std::unique_ptr<DebugChecksumsSubsectionRef> OwnedChecksums;
+
+  const DebugStringTableSubsectionRef *Strings = nullptr;
+  const DebugChecksumsSubsectionRef *Checksums = nullptr;
+};
 
 class DebugSubsectionVisitor {
 public:
@@ -41,38 +89,38 @@ public:
     return Error::success();
   }
   virtual Error visitLines(DebugLinesSubsectionRef &Lines,
-                           const StringsAndChecksumsRef &State) = 0;
+                           const DebugSubsectionState &State) = 0;
   virtual Error visitFileChecksums(DebugChecksumsSubsectionRef &Checksums,
-                                   const StringsAndChecksumsRef &State) = 0;
+                                   const DebugSubsectionState &State) = 0;
   virtual Error visitInlineeLines(DebugInlineeLinesSubsectionRef &Inlinees,
-                                  const StringsAndChecksumsRef &State) = 0;
+                                  const DebugSubsectionState &State) = 0;
   virtual Error
   visitCrossModuleExports(DebugCrossModuleExportsSubsectionRef &CSE,
-                          const StringsAndChecksumsRef &State) = 0;
+                          const DebugSubsectionState &State) = 0;
   virtual Error
   visitCrossModuleImports(DebugCrossModuleImportsSubsectionRef &CSE,
-                          const StringsAndChecksumsRef &State) = 0;
+                          const DebugSubsectionState &State) = 0;
 
   virtual Error visitStringTable(DebugStringTableSubsectionRef &ST,
-                                 const StringsAndChecksumsRef &State) = 0;
+                                 const DebugSubsectionState &State) = 0;
 
   virtual Error visitSymbols(DebugSymbolsSubsectionRef &CSE,
-                             const StringsAndChecksumsRef &State) = 0;
+                             const DebugSubsectionState &State) = 0;
 
   virtual Error visitFrameData(DebugFrameDataSubsectionRef &FD,
-                               const StringsAndChecksumsRef &State) = 0;
+                               const DebugSubsectionState &State) = 0;
   virtual Error visitCOFFSymbolRVAs(DebugSymbolRVASubsectionRef &RVAs,
-                                    const StringsAndChecksumsRef &State) = 0;
+                                    const DebugSubsectionState &State) = 0;
 };
 
 Error visitDebugSubsection(const DebugSubsectionRecord &R,
                            DebugSubsectionVisitor &V,
-                           const StringsAndChecksumsRef &State);
+                           const DebugSubsectionState &State);
 
 namespace detail {
 template <typename T>
 Error visitDebugSubsections(T &&FragmentRange, DebugSubsectionVisitor &V,
-                            StringsAndChecksumsRef &State) {
+                            DebugSubsectionState &State) {
   State.initialize(std::forward<T>(FragmentRange));
 
   for (const DebugSubsectionRecord &L : FragmentRange) {
@@ -85,7 +133,7 @@ Error visitDebugSubsections(T &&Fragment
 
 template <typename T>
 Error visitDebugSubsections(T &&FragmentRange, DebugSubsectionVisitor &V) {
-  StringsAndChecksumsRef State;
+  DebugSubsectionState State;
   return detail::visitDebugSubsections(std::forward<T>(FragmentRange), V,
                                        State);
 }
@@ -93,7 +141,7 @@ Error visitDebugSubsections(T &&Fragment
 template <typename T>
 Error visitDebugSubsections(T &&FragmentRange, DebugSubsectionVisitor &V,
                             const DebugStringTableSubsectionRef &Strings) {
-  StringsAndChecksumsRef State(Strings);
+  DebugSubsectionState State(Strings);
   return detail::visitDebugSubsections(std::forward<T>(FragmentRange), V,
                                        State);
 }
@@ -102,7 +150,7 @@ template <typename T>
 Error visitDebugSubsections(T &&FragmentRange, DebugSubsectionVisitor &V,
                             const DebugStringTableSubsectionRef &Strings,
                             const DebugChecksumsSubsectionRef &Checksums) {
-  StringsAndChecksumsRef State(Strings, Checksums);
+  DebugSubsectionState State(Strings, Checksums);
   return detail::visitDebugSubsections(std::forward<T>(FragmentRange), V,
                                        State);
 }

Removed: llvm/trunk/include/llvm/DebugInfo/CodeView/StringsAndChecksums.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/StringsAndChecksums.h?rev=305370&view=auto
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/StringsAndChecksums.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/StringsAndChecksums.h (removed)
@@ -1,104 +0,0 @@
-//===- StringsAndChecksums.h ------------------------------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_DEBUGINFO_CODEVIEW_STRINGS_AND_CHECKSUMS_H
-#define LLVM_DEBUGINFO_CODEVIEW_STRINGS_AND_CHECKSUMS_H
-
-#include "llvm/DebugInfo/CodeView/CodeView.h"
-#include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h"
-
-#include <memory>
-
-namespace llvm {
-namespace codeview {
-
-class DebugSubsectionRecord;
-class DebugChecksumsSubsectionRef;
-class DebugStringTableSubsectionRef;
-class DebugChecksumsSubsection;
-class DebugStringTableSubsection;
-
-class StringsAndChecksumsRef {
-public:
-  // If no subsections are known about initially, we find as much as we can.
-  StringsAndChecksumsRef();
-
-  // If only a string table subsection is given, we find a checksums subsection.
-  explicit StringsAndChecksumsRef(const DebugStringTableSubsectionRef &Strings);
-
-  // If both subsections are given, we don't need to find anything.
-  StringsAndChecksumsRef(const DebugStringTableSubsectionRef &Strings,
-                         const DebugChecksumsSubsectionRef &Checksums);
-
-  template <typename T> void initialize(T &&FragmentRange) {
-    for (const DebugSubsectionRecord &R : FragmentRange) {
-      if (Strings && Checksums)
-        return;
-      if (R.kind() == DebugSubsectionKind::FileChecksums) {
-        initializeChecksums(R);
-        continue;
-      }
-      if (R.kind() == DebugSubsectionKind::StringTable && !Strings) {
-        // While in practice we should never encounter a string table even
-        // though the string table is already initialized, in theory it's
-        // possible.  PDBs are supposed to have one global string table and
-        // then this subsection should not appear.  Whereas object files are
-        // supposed to have this subsection appear exactly once.  However,
-        // for testing purposes it's nice to be able to test this subsection
-        // independently of one format or the other, so for some tests we
-        // manually construct a PDB that contains this subsection in addition
-        // to a global string table.
-        initializeStrings(R);
-        continue;
-      }
-    }
-  }
-
-  const DebugStringTableSubsectionRef &strings() const { return *Strings; }
-  const DebugChecksumsSubsectionRef &checksums() const { return *Checksums; }
-
-  bool hasStrings() const { return Strings != nullptr; }
-  bool hasChecksums() const { return Checksums != nullptr; }
-
-private:
-  void initializeStrings(const DebugSubsectionRecord &SR);
-  void initializeChecksums(const DebugSubsectionRecord &FCR);
-
-  std::unique_ptr<DebugStringTableSubsectionRef> OwnedStrings;
-  std::unique_ptr<DebugChecksumsSubsectionRef> OwnedChecksums;
-
-  const DebugStringTableSubsectionRef *Strings = nullptr;
-  const DebugChecksumsSubsectionRef *Checksums = nullptr;
-};
-
-class StringsAndChecksums {
-public:
-  using StringsPtr = std::shared_ptr<DebugStringTableSubsection>;
-  using ChecksumsPtr = std::shared_ptr<DebugChecksumsSubsection>;
-  // If no subsections are known about initially, we find as much as we can.
-  StringsAndChecksums() {}
-
-  void setStrings(const StringsPtr &SP) { Strings = SP; }
-  void setChecksums(const ChecksumsPtr &CP) { Checksums = CP; }
-
-  const StringsPtr &strings() const { return Strings; }
-  const ChecksumsPtr &checksums() const { return Checksums; }
-
-  bool hasStrings() const { return Strings != nullptr; }
-  bool hasChecksums() const { return Checksums != nullptr; }
-
-private:
-  StringsPtr Strings;
-  ChecksumsPtr Checksums;
-};
-
-} // namespace codeview
-} // namespace llvm
-
-#endif

Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.h?rev=305371&r1=305370&r2=305371&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.h Wed Jun 14 01:24:24 2017
@@ -50,7 +50,7 @@ public:
   void addSymbol(codeview::CVSymbol Symbol);
 
   void
-  addDebugSubsection(std::shared_ptr<codeview::DebugSubsection> Subsection);
+  addDebugSubsection(std::unique_ptr<codeview::DebugSubsection> Subsection);
 
   uint16_t getStreamIndex() const;
   StringRef getModuleName() const { return ModuleName; }

Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h?rev=305371&r1=305370&r2=305371&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h Wed Jun 14 01:24:24 2017
@@ -41,7 +41,10 @@ public:
   uint32_t calculateSerializedSize() const;
   Error commit(BinaryStreamWriter &Writer) const;
 
-  void setStrings(const codeview::DebugStringTableSubsection &Strings);
+  codeview::DebugStringTableSubsection &getStrings() { return Strings; }
+  const codeview::DebugStringTableSubsection &getStrings() const {
+    return Strings;
+  }
 
 private:
   uint32_t calculateHashTableSize() const;

Modified: llvm/trunk/include/llvm/ObjectYAML/COFFYAML.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ObjectYAML/COFFYAML.h?rev=305371&r1=305370&r2=305371&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ObjectYAML/COFFYAML.h (original)
+++ llvm/trunk/include/llvm/ObjectYAML/COFFYAML.h Wed Jun 14 01:24:24 2017
@@ -16,8 +16,6 @@
 
 #include "llvm/ADT/Optional.h"
 #include "llvm/BinaryFormat/COFF.h"
-#include "llvm/ObjectYAML/CodeViewYAMLDebugSections.h"
-#include "llvm/ObjectYAML/CodeViewYAMLTypes.h"
 #include "llvm/ObjectYAML/YAML.h"
 
 namespace llvm {
@@ -58,8 +56,6 @@ namespace COFFYAML {
     COFF::section Header;
     unsigned Alignment = 0;
     yaml::BinaryRef SectionData;
-    std::vector<CodeViewYAML::YAMLDebugSubsection> DebugS;
-    std::vector<CodeViewYAML::LeafRecord> DebugT;
     std::vector<Relocation> Relocations;
     StringRef Name;
     Section();

Modified: llvm/trunk/include/llvm/ObjectYAML/CodeViewYAMLDebugSections.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ObjectYAML/CodeViewYAMLDebugSections.h?rev=305371&r1=305370&r2=305371&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ObjectYAML/CodeViewYAMLDebugSections.h (original)
+++ llvm/trunk/include/llvm/ObjectYAML/CodeViewYAMLDebugSections.h Wed Jun 14 01:24:24 2017
@@ -28,8 +28,6 @@ class DebugStringTableSubsectionRef;
 class DebugChecksumsSubsectionRef;
 class DebugStringTableSubsection;
 class DebugChecksumsSubsection;
-class StringsAndChecksums;
-class StringsAndChecksumsRef;
 }
 namespace CodeViewYAML {
 
@@ -105,24 +103,25 @@ struct InlineeInfo {
 
 struct YAMLDebugSubsection {
   static Expected<YAMLDebugSubsection>
-  fromCodeViewSubection(const codeview::StringsAndChecksumsRef &SC,
+  fromCodeViewSubection(const codeview::DebugStringTableSubsectionRef &Strings,
+                        const codeview::DebugChecksumsSubsectionRef &Checksums,
                         const codeview::DebugSubsectionRecord &SS);
 
   std::shared_ptr<detail::YAMLSubsectionBase> Subsection;
 };
 
-struct DebugSubsectionState {};
-
-Expected<std::vector<std::shared_ptr<codeview::DebugSubsection>>>
+Expected<std::vector<std::unique_ptr<codeview::DebugSubsection>>>
 toCodeViewSubsectionList(BumpPtrAllocator &Allocator,
                          ArrayRef<YAMLDebugSubsection> Subsections,
-                         const codeview::StringsAndChecksums &SC);
-
-std::vector<YAMLDebugSubsection>
-fromDebugS(ArrayRef<uint8_t> Data, const codeview::StringsAndChecksumsRef &SC);
+                         codeview::DebugStringTableSubsection &Strings);
+Expected<std::vector<std::unique_ptr<codeview::DebugSubsection>>>
+toCodeViewSubsectionList(
+    BumpPtrAllocator &Allocator, ArrayRef<YAMLDebugSubsection> Subsections,
+    std::unique_ptr<codeview::DebugStringTableSubsection> &TakeStrings,
+    codeview::DebugStringTableSubsection *StringsRef);
 
-void initializeStringsAndChecksums(ArrayRef<YAMLDebugSubsection> Sections,
-                                   codeview::StringsAndChecksums &SC);
+std::unique_ptr<codeview::DebugStringTableSubsection>
+findStringTable(ArrayRef<YAMLDebugSubsection> Sections);
 
 } // namespace CodeViewYAML
 } // namespace llvm

Modified: llvm/trunk/include/llvm/ObjectYAML/CodeViewYAMLTypes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ObjectYAML/CodeViewYAMLTypes.h?rev=305371&r1=305370&r2=305371&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ObjectYAML/CodeViewYAMLTypes.h (original)
+++ llvm/trunk/include/llvm/ObjectYAML/CodeViewYAMLTypes.h Wed Jun 14 01:24:24 2017
@@ -41,9 +41,6 @@ struct LeafRecord {
   codeview::CVType toCodeViewRecord(codeview::TypeTableBuilder &TS) const;
   static Expected<LeafRecord> fromCodeViewRecord(codeview::CVType Type);
 };
-
-std::vector<LeafRecord> fromDebugT(ArrayRef<uint8_t> DebugT);
-ArrayRef<uint8_t> toDebugT(ArrayRef<LeafRecord>, BumpPtrAllocator &Alloc);
 } // namespace CodeViewYAML
 } // namespace llvm
 

Modified: llvm/trunk/lib/DebugInfo/CodeView/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/CMakeLists.txt?rev=305371&r1=305370&r2=305371&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/CMakeLists.txt (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/CMakeLists.txt Wed Jun 14 01:24:24 2017
@@ -20,7 +20,6 @@ add_llvm_library(LLVMDebugInfoCodeView
   LazyRandomTypeCollection.cpp
   Line.cpp
   RecordSerialization.cpp
-  StringsAndChecksums.cpp
   SymbolRecordMapping.cpp
   SymbolDumper.cpp
   SymbolSerializer.cpp
@@ -33,7 +32,7 @@ add_llvm_library(LLVMDebugInfoCodeView
   TypeSerializer.cpp
   TypeStreamMerger.cpp
   TypeTableCollection.cpp
-
+  
   ADDITIONAL_HEADER_DIRS
   ${LLVM_MAIN_INCLUDE_DIR}/llvm/DebugInfo/CodeView
   )

Modified: llvm/trunk/lib/DebugInfo/CodeView/DebugStringTableSubsection.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/DebugStringTableSubsection.cpp?rev=305371&r1=305370&r2=305371&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/DebugStringTableSubsection.cpp (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/DebugStringTableSubsection.cpp Wed Jun 14 01:24:24 2017
@@ -58,10 +58,6 @@ Error DebugStringTableSubsection::commit
   uint32_t Begin = Writer.getOffset();
   uint32_t End = Begin + StringSize;
 
-  // Write a null string at the beginning.
-  if (auto EC = Writer.writeCString(StringRef()))
-    return EC;
-
   for (auto &Pair : Strings) {
     StringRef S = Pair.getKey();
     uint32_t Offset = Begin + Pair.getValue();
@@ -72,7 +68,6 @@ Error DebugStringTableSubsection::commit
   }
 
   Writer.setOffset(End);
-  assert((End - Begin) == StringSize);
   return Error::success();
 }
 

Modified: llvm/trunk/lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp?rev=305371&r1=305370&r2=305371&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp Wed Jun 14 01:24:24 2017
@@ -50,7 +50,7 @@ DebugSubsectionKind DebugSubsectionRecor
 BinaryStreamRef DebugSubsectionRecord::getRecordData() const { return Data; }
 
 DebugSubsectionRecordBuilder::DebugSubsectionRecordBuilder(
-    std::shared_ptr<DebugSubsection> Subsection, CodeViewContainer Container)
+    std::unique_ptr<DebugSubsection> Subsection, CodeViewContainer Container)
     : Subsection(std::move(Subsection)), Container(Container) {}
 
 uint32_t DebugSubsectionRecordBuilder::calculateSerializedLength() {

Modified: llvm/trunk/lib/DebugInfo/CodeView/DebugSubsectionVisitor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/DebugSubsectionVisitor.cpp?rev=305371&r1=305370&r2=305371&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/DebugSubsectionVisitor.cpp (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/DebugSubsectionVisitor.cpp Wed Jun 14 01:24:24 2017
@@ -26,9 +26,40 @@
 using namespace llvm;
 using namespace llvm::codeview;
 
-Error llvm::codeview::visitDebugSubsection(
-    const DebugSubsectionRecord &R, DebugSubsectionVisitor &V,
-    const StringsAndChecksumsRef &State) {
+DebugSubsectionState::DebugSubsectionState() {}
+
+DebugSubsectionState::DebugSubsectionState(
+    const DebugStringTableSubsectionRef &Strings)
+    : Strings(&Strings) {}
+
+DebugSubsectionState::DebugSubsectionState(
+    const DebugStringTableSubsectionRef &Strings,
+    const DebugChecksumsSubsectionRef &Checksums)
+    : Strings(&Strings), Checksums(&Checksums) {}
+
+void DebugSubsectionState::initializeStrings(const DebugSubsectionRecord &SR) {
+  assert(SR.kind() == DebugSubsectionKind::StringTable);
+  assert(!Strings && "Found a string table even though we already have one!");
+
+  OwnedStrings = llvm::make_unique<DebugStringTableSubsectionRef>();
+  consumeError(OwnedStrings->initialize(SR.getRecordData()));
+  Strings = OwnedStrings.get();
+}
+
+void DebugSubsectionState::initializeChecksums(
+    const DebugSubsectionRecord &FCR) {
+  assert(FCR.kind() == DebugSubsectionKind::FileChecksums);
+  if (Checksums)
+    return;
+
+  OwnedChecksums = llvm::make_unique<DebugChecksumsSubsectionRef>();
+  consumeError(OwnedChecksums->initialize(FCR.getRecordData()));
+  Checksums = OwnedChecksums.get();
+}
+
+Error llvm::codeview::visitDebugSubsection(const DebugSubsectionRecord &R,
+                                           DebugSubsectionVisitor &V,
+                                           const DebugSubsectionState &State) {
   BinaryStreamReader Reader(R.getRecordData());
   switch (R.kind()) {
   case DebugSubsectionKind::Lines: {

Removed: llvm/trunk/lib/DebugInfo/CodeView/StringsAndChecksums.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/StringsAndChecksums.cpp?rev=305370&view=auto
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/StringsAndChecksums.cpp (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/StringsAndChecksums.cpp (removed)
@@ -1,48 +0,0 @@
-//===- StringsAndChecksums.cpp ----------------------------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
-#include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
-#include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h"
-#include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h"
-
-using namespace llvm;
-using namespace llvm::codeview;
-
-StringsAndChecksumsRef::StringsAndChecksumsRef() {}
-
-StringsAndChecksumsRef::StringsAndChecksumsRef(
-    const DebugStringTableSubsectionRef &Strings)
-    : Strings(&Strings) {}
-
-StringsAndChecksumsRef::StringsAndChecksumsRef(
-    const DebugStringTableSubsectionRef &Strings,
-    const DebugChecksumsSubsectionRef &Checksums)
-    : Strings(&Strings), Checksums(&Checksums) {}
-
-void StringsAndChecksumsRef::initializeStrings(
-    const DebugSubsectionRecord &SR) {
-  assert(SR.kind() == DebugSubsectionKind::StringTable);
-  assert(!Strings && "Found a string table even though we already have one!");
-
-  OwnedStrings = llvm::make_unique<DebugStringTableSubsectionRef>();
-  consumeError(OwnedStrings->initialize(SR.getRecordData()));
-  Strings = OwnedStrings.get();
-}
-
-void StringsAndChecksumsRef::initializeChecksums(
-    const DebugSubsectionRecord &FCR) {
-  assert(FCR.kind() == DebugSubsectionKind::FileChecksums);
-  if (Checksums)
-    return;
-
-  OwnedChecksums = llvm::make_unique<DebugChecksumsSubsectionRef>();
-  consumeError(OwnedChecksums->initialize(FCR.getRecordData()));
-  Checksums = OwnedChecksums.get();
-}

Modified: llvm/trunk/lib/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.cpp?rev=305371&r1=305370&r2=305371&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.cpp Wed Jun 14 01:24:24 2017
@@ -177,7 +177,7 @@ Error DbiModuleDescriptorBuilder::commit
 }
 
 void DbiModuleDescriptorBuilder::addDebugSubsection(
-    std::shared_ptr<DebugSubsection> Subsection) {
+    std::unique_ptr<DebugSubsection> Subsection) {
   assert(Subsection);
   C13Builders.push_back(llvm::make_unique<DebugSubsectionRecordBuilder>(
       std::move(Subsection), CodeViewContainer::Pdb));

Modified: llvm/trunk/lib/DebugInfo/PDB/Native/PDBStringTableBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Native/PDBStringTableBuilder.cpp?rev=305371&r1=305370&r2=305371&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Native/PDBStringTableBuilder.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Native/PDBStringTableBuilder.cpp Wed Jun 14 01:24:24 2017
@@ -52,11 +52,6 @@ uint32_t PDBStringTableBuilder::calculat
   return Size;
 }
 
-void PDBStringTableBuilder::setStrings(
-    const codeview::DebugStringTableSubsection &Strings) {
-  this->Strings = Strings;
-}
-
 Error PDBStringTableBuilder::writeHeader(BinaryStreamWriter &Writer) const {
   // Write a header
   PDBStringTableHeader H;

Modified: llvm/trunk/lib/ObjectYAML/COFFYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/COFFYAML.cpp?rev=305371&r1=305370&r2=305371&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/COFFYAML.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/COFFYAML.cpp Wed Jun 14 01:24:24 2017
@@ -488,16 +488,7 @@ void MappingTraits<COFFYAML::Section>::m
   IO.mapOptional("VirtualAddress", Sec.Header.VirtualAddress, 0U);
   IO.mapOptional("VirtualSize", Sec.Header.VirtualSize, 0U);
   IO.mapOptional("Alignment", Sec.Alignment, 0U);
-
-  // If this is a .debug$S or .debug$T section parse the semantic representation
-  // of the symbols/types.  If it is any other kind of section, just deal in raw
-  // bytes.
-  IO.mapOptional("SectionData", Sec.SectionData);
-  if (Sec.Name == ".debug$S")
-    IO.mapOptional("Subsections", Sec.DebugS);
-  else if (Sec.Name == ".debug$T")
-    IO.mapOptional("Types", Sec.DebugT);
-
+  IO.mapRequired("SectionData", Sec.SectionData);
   IO.mapOptional("Relocations", Sec.Relocations);
 }
 

Modified: llvm/trunk/lib/ObjectYAML/CodeViewYAMLDebugSections.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/CodeViewYAMLDebugSections.cpp?rev=305371&r1=305370&r2=305371&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/CodeViewYAMLDebugSections.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/CodeViewYAMLDebugSections.cpp Wed Jun 14 01:24:24 2017
@@ -28,7 +28,6 @@
 #include "llvm/DebugInfo/CodeView/DebugSymbolRVASubsection.h"
 #include "llvm/DebugInfo/CodeView/DebugSymbolsSubsection.h"
 #include "llvm/DebugInfo/CodeView/EnumTables.h"
-#include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
 #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
 #include "llvm/DebugInfo/CodeView/SymbolSerializer.h"
 #include "llvm/ObjectYAML/CodeViewYAMLSymbols.h"
@@ -76,9 +75,10 @@ struct YAMLSubsectionBase {
   virtual ~YAMLSubsectionBase() {}
 
   virtual void map(IO &IO) = 0;
-  virtual std::shared_ptr<DebugSubsection>
+  virtual std::unique_ptr<DebugSubsection>
   toCodeViewSubsection(BumpPtrAllocator &Allocator,
-                       const codeview::StringsAndChecksums &SC) const = 0;
+                       DebugStringTableSubsection *UseStrings,
+                       DebugChecksumsSubsection *UseChecksums) const = 0;
 };
 }
 }
@@ -90,9 +90,10 @@ struct YAMLChecksumsSubsection : public
       : YAMLSubsectionBase(DebugSubsectionKind::FileChecksums) {}
 
   void map(IO &IO) override;
-  std::shared_ptr<DebugSubsection>
+  std::unique_ptr<DebugSubsection>
   toCodeViewSubsection(BumpPtrAllocator &Allocator,
-                       const codeview::StringsAndChecksums &SC) const override;
+                       DebugStringTableSubsection *Strings,
+                       DebugChecksumsSubsection *Checksums) const override;
   static Expected<std::shared_ptr<YAMLChecksumsSubsection>>
   fromCodeViewSubsection(const DebugStringTableSubsectionRef &Strings,
                          const DebugChecksumsSubsectionRef &FC);
@@ -104,9 +105,10 @@ struct YAMLLinesSubsection : public YAML
   YAMLLinesSubsection() : YAMLSubsectionBase(DebugSubsectionKind::Lines) {}
 
   void map(IO &IO) override;
-  std::shared_ptr<DebugSubsection>
+  std::unique_ptr<DebugSubsection>
   toCodeViewSubsection(BumpPtrAllocator &Allocator,
-                       const codeview::StringsAndChecksums &SC) const override;
+                       DebugStringTableSubsection *Strings,
+                       DebugChecksumsSubsection *Checksums) const override;
   static Expected<std::shared_ptr<YAMLLinesSubsection>>
   fromCodeViewSubsection(const DebugStringTableSubsectionRef &Strings,
                          const DebugChecksumsSubsectionRef &Checksums,
@@ -120,9 +122,10 @@ struct YAMLInlineeLinesSubsection : publ
       : YAMLSubsectionBase(DebugSubsectionKind::InlineeLines) {}
 
   void map(IO &IO) override;
-  std::shared_ptr<DebugSubsection>
+  std::unique_ptr<DebugSubsection>
   toCodeViewSubsection(BumpPtrAllocator &Allocator,
-                       const codeview::StringsAndChecksums &SC) const override;
+                       DebugStringTableSubsection *Strings,
+                       DebugChecksumsSubsection *Checksums) const override;
   static Expected<std::shared_ptr<YAMLInlineeLinesSubsection>>
   fromCodeViewSubsection(const DebugStringTableSubsectionRef &Strings,
                          const DebugChecksumsSubsectionRef &Checksums,
@@ -136,9 +139,10 @@ struct YAMLCrossModuleExportsSubsection
       : YAMLSubsectionBase(DebugSubsectionKind::CrossScopeExports) {}
 
   void map(IO &IO) override;
-  std::shared_ptr<DebugSubsection>
+  std::unique_ptr<DebugSubsection>
   toCodeViewSubsection(BumpPtrAllocator &Allocator,
-                       const codeview::StringsAndChecksums &SC) const override;
+                       DebugStringTableSubsection *Strings,
+                       DebugChecksumsSubsection *Checksums) const override;
   static Expected<std::shared_ptr<YAMLCrossModuleExportsSubsection>>
   fromCodeViewSubsection(const DebugCrossModuleExportsSubsectionRef &Exports);
 
@@ -150,9 +154,10 @@ struct YAMLCrossModuleImportsSubsection
       : YAMLSubsectionBase(DebugSubsectionKind::CrossScopeImports) {}
 
   void map(IO &IO) override;
-  std::shared_ptr<DebugSubsection>
+  std::unique_ptr<DebugSubsection>
   toCodeViewSubsection(BumpPtrAllocator &Allocator,
-                       const codeview::StringsAndChecksums &SC) const override;
+                       DebugStringTableSubsection *Strings,
+                       DebugChecksumsSubsection *Checksums) const override;
   static Expected<std::shared_ptr<YAMLCrossModuleImportsSubsection>>
   fromCodeViewSubsection(const DebugStringTableSubsectionRef &Strings,
                          const DebugCrossModuleImportsSubsectionRef &Imports);
@@ -164,9 +169,10 @@ struct YAMLSymbolsSubsection : public YA
   YAMLSymbolsSubsection() : YAMLSubsectionBase(DebugSubsectionKind::Symbols) {}
 
   void map(IO &IO) override;
-  std::shared_ptr<DebugSubsection>
+  std::unique_ptr<DebugSubsection>
   toCodeViewSubsection(BumpPtrAllocator &Allocator,
-                       const codeview::StringsAndChecksums &SC) const override;
+                       DebugStringTableSubsection *Strings,
+                       DebugChecksumsSubsection *Checksums) const override;
   static Expected<std::shared_ptr<YAMLSymbolsSubsection>>
   fromCodeViewSubsection(const DebugSymbolsSubsectionRef &Symbols);
 
@@ -178,9 +184,10 @@ struct YAMLStringTableSubsection : publi
       : YAMLSubsectionBase(DebugSubsectionKind::StringTable) {}
 
   void map(IO &IO) override;
-  std::shared_ptr<DebugSubsection>
+  std::unique_ptr<DebugSubsection>
   toCodeViewSubsection(BumpPtrAllocator &Allocator,
-                       const codeview::StringsAndChecksums &SC) const override;
+                       DebugStringTableSubsection *Strings,
+                       DebugChecksumsSubsection *Checksums) const override;
   static Expected<std::shared_ptr<YAMLStringTableSubsection>>
   fromCodeViewSubsection(const DebugStringTableSubsectionRef &Strings);
 
@@ -192,9 +199,10 @@ struct YAMLFrameDataSubsection : public
       : YAMLSubsectionBase(DebugSubsectionKind::FrameData) {}
 
   void map(IO &IO) override;
-  std::shared_ptr<DebugSubsection>
+  std::unique_ptr<DebugSubsection>
   toCodeViewSubsection(BumpPtrAllocator &Allocator,
-                       const codeview::StringsAndChecksums &SC) const override;
+                       DebugStringTableSubsection *Strings,
+                       DebugChecksumsSubsection *Checksums) const override;
   static Expected<std::shared_ptr<YAMLFrameDataSubsection>>
   fromCodeViewSubsection(const DebugStringTableSubsectionRef &Strings,
                          const DebugFrameDataSubsectionRef &Frames);
@@ -207,9 +215,10 @@ struct YAMLCoffSymbolRVASubsection : pub
       : YAMLSubsectionBase(DebugSubsectionKind::CoffSymbolRVA) {}
 
   void map(IO &IO) override;
-  std::shared_ptr<DebugSubsection>
+  std::unique_ptr<DebugSubsection>
   toCodeViewSubsection(BumpPtrAllocator &Allocator,
-                       const codeview::StringsAndChecksums &SC) const override;
+                       DebugStringTableSubsection *Strings,
+                       DebugChecksumsSubsection *Checksums) const override;
   static Expected<std::shared_ptr<YAMLCoffSymbolRVASubsection>>
   fromCodeViewSubsection(const DebugSymbolRVASubsectionRef &RVAs);
 
@@ -391,23 +400,23 @@ findChecksums(ArrayRef<YAMLDebugSubsecti
   return nullptr;
 }
 
-std::shared_ptr<DebugSubsection> YAMLChecksumsSubsection::toCodeViewSubsection(
-    BumpPtrAllocator &Allocator,
-    const codeview::StringsAndChecksums &SC) const {
-  assert(SC.hasStrings());
-  auto Result = std::make_shared<DebugChecksumsSubsection>(*SC.strings());
+std::unique_ptr<DebugSubsection> YAMLChecksumsSubsection::toCodeViewSubsection(
+    BumpPtrAllocator &Allocator, DebugStringTableSubsection *UseStrings,
+    DebugChecksumsSubsection *UseChecksums) const {
+  assert(UseStrings && !UseChecksums);
+  auto Result = llvm::make_unique<DebugChecksumsSubsection>(*UseStrings);
   for (const auto &CS : Checksums) {
     Result->addChecksum(CS.FileName, CS.Kind, CS.ChecksumBytes.Bytes);
   }
-  return Result;
+  return std::move(Result);
 }
 
-std::shared_ptr<DebugSubsection> YAMLLinesSubsection::toCodeViewSubsection(
-    BumpPtrAllocator &Allocator,
-    const codeview::StringsAndChecksums &SC) const {
-  assert(SC.hasStrings() && SC.hasChecksums());
+std::unique_ptr<DebugSubsection> YAMLLinesSubsection::toCodeViewSubsection(
+    BumpPtrAllocator &Allocator, DebugStringTableSubsection *UseStrings,
+    DebugChecksumsSubsection *UseChecksums) const {
+  assert(UseStrings && UseChecksums);
   auto Result =
-      std::make_shared<DebugLinesSubsection>(*SC.checksums(), *SC.strings());
+      llvm::make_unique<DebugLinesSubsection>(*UseChecksums, *UseStrings);
   Result->setCodeSize(Lines.CodeSize);
   Result->setRelocationAddress(Lines.RelocSegment, Lines.RelocOffset);
   Result->setFlags(Lines.Flags);
@@ -429,16 +438,16 @@ std::shared_ptr<DebugSubsection> YAMLLin
       }
     }
   }
-  return Result;
+  return llvm::cast<DebugSubsection>(std::move(Result));
 }
 
-std::shared_ptr<DebugSubsection>
+std::unique_ptr<DebugSubsection>
 YAMLInlineeLinesSubsection::toCodeViewSubsection(
-    BumpPtrAllocator &Allocator,
-    const codeview::StringsAndChecksums &SC) const {
-  assert(SC.hasChecksums());
-  auto Result = std::make_shared<DebugInlineeLinesSubsection>(
-      *SC.checksums(), InlineeLines.HasExtraFiles);
+    BumpPtrAllocator &Allocator, DebugStringTableSubsection *UseStrings,
+    DebugChecksumsSubsection *UseChecksums) const {
+  assert(UseChecksums);
+  auto Result = llvm::make_unique<DebugInlineeLinesSubsection>(
+      *UseChecksums, InlineeLines.HasExtraFiles);
 
   for (const auto &Site : InlineeLines.Sites) {
     Result->addInlineSite(TypeIndex(Site.Inlinee), Site.FileName,
@@ -450,60 +459,56 @@ YAMLInlineeLinesSubsection::toCodeViewSu
       Result->addExtraFile(EF);
     }
   }
-  return Result;
+  return llvm::cast<DebugSubsection>(std::move(Result));
 }
 
-std::shared_ptr<DebugSubsection>
+std::unique_ptr<DebugSubsection>
 YAMLCrossModuleExportsSubsection::toCodeViewSubsection(
-    BumpPtrAllocator &Allocator,
-    const codeview::StringsAndChecksums &SC) const {
-  auto Result = std::make_shared<DebugCrossModuleExportsSubsection>();
+    BumpPtrAllocator &Allocator, DebugStringTableSubsection *Strings,
+    DebugChecksumsSubsection *Checksums) const {
+  auto Result = llvm::make_unique<DebugCrossModuleExportsSubsection>();
   for (const auto &M : Exports)
     Result->addMapping(M.Local, M.Global);
-  return Result;
+  return llvm::cast<DebugSubsection>(std::move(Result));
 }
 
-std::shared_ptr<DebugSubsection>
+std::unique_ptr<DebugSubsection>
 YAMLCrossModuleImportsSubsection::toCodeViewSubsection(
-    BumpPtrAllocator &Allocator,
-    const codeview::StringsAndChecksums &SC) const {
-  assert(SC.hasStrings());
-
-  auto Result =
-      std::make_shared<DebugCrossModuleImportsSubsection>(*SC.strings());
+    BumpPtrAllocator &Allocator, DebugStringTableSubsection *Strings,
+    DebugChecksumsSubsection *Checksums) const {
+  auto Result = llvm::make_unique<DebugCrossModuleImportsSubsection>(*Strings);
   for (const auto &M : Imports) {
     for (const auto Id : M.ImportIds)
       Result->addImport(M.ModuleName, Id);
   }
-  return Result;
+  return llvm::cast<DebugSubsection>(std::move(Result));
 }
 
-std::shared_ptr<DebugSubsection> YAMLSymbolsSubsection::toCodeViewSubsection(
-    BumpPtrAllocator &Allocator,
-    const codeview::StringsAndChecksums &SC) const {
-  auto Result = std::make_shared<DebugSymbolsSubsection>();
+std::unique_ptr<DebugSubsection> YAMLSymbolsSubsection::toCodeViewSubsection(
+    BumpPtrAllocator &Allocator, DebugStringTableSubsection *Strings,
+    DebugChecksumsSubsection *Checksums) const {
+  auto Result = llvm::make_unique<DebugSymbolsSubsection>();
   for (const auto &Sym : Symbols)
     Result->addSymbol(
         Sym.toCodeViewSymbol(Allocator, CodeViewContainer::ObjectFile));
-  return Result;
+  return std::move(Result);
 }
 
-std::shared_ptr<DebugSubsection>
+std::unique_ptr<DebugSubsection>
 YAMLStringTableSubsection::toCodeViewSubsection(
-    BumpPtrAllocator &Allocator,
-    const codeview::StringsAndChecksums &SC) const {
-  auto Result = std::make_shared<DebugStringTableSubsection>();
+    BumpPtrAllocator &Allocator, DebugStringTableSubsection *Strings,
+    DebugChecksumsSubsection *Checksums) const {
+  auto Result = llvm::make_unique<DebugStringTableSubsection>();
   for (const auto &Str : this->Strings)
     Result->insert(Str);
-  return Result;
+  return std::move(Result);
 }
 
-std::shared_ptr<DebugSubsection> YAMLFrameDataSubsection::toCodeViewSubsection(
-    BumpPtrAllocator &Allocator,
-    const codeview::StringsAndChecksums &SC) const {
-  assert(SC.hasStrings());
-
-  auto Result = std::make_shared<DebugFrameDataSubsection>();
+std::unique_ptr<DebugSubsection> YAMLFrameDataSubsection::toCodeViewSubsection(
+    BumpPtrAllocator &Allocator, DebugStringTableSubsection *Strings,
+    DebugChecksumsSubsection *Checksums) const {
+  assert(Strings);
+  auto Result = llvm::make_unique<DebugFrameDataSubsection>();
   for (const auto &YF : Frames) {
     codeview::FrameData F;
     F.CodeSize = YF.CodeSize;
@@ -514,20 +519,20 @@ std::shared_ptr<DebugSubsection> YAMLFra
     F.PrologSize = YF.PrologSize;
     F.RvaStart = YF.RvaStart;
     F.SavedRegsSize = YF.SavedRegsSize;
-    F.FrameFunc = SC.strings()->insert(YF.FrameFunc);
+    F.FrameFunc = Strings->insert(YF.FrameFunc);
     Result->addFrameData(F);
   }
-  return Result;
+  return std::move(Result);
 }
 
-std::shared_ptr<DebugSubsection>
+std::unique_ptr<DebugSubsection>
 YAMLCoffSymbolRVASubsection::toCodeViewSubsection(
-    BumpPtrAllocator &Allocator,
-    const codeview::StringsAndChecksums &SC) const {
-  auto Result = std::make_shared<DebugSymbolRVASubsection>();
+    BumpPtrAllocator &Allocator, DebugStringTableSubsection *Strings,
+    DebugChecksumsSubsection *Checksums) const {
+  auto Result = llvm::make_unique<DebugSymbolRVASubsection>();
   for (const auto &RVA : RVAs)
     Result->addRVA(RVA);
-  return Result;
+  return std::move(Result);
 }
 
 static Expected<SourceFileChecksumEntry>
@@ -736,17 +741,63 @@ YAMLCoffSymbolRVASubsection::fromCodeVie
   return Result;
 }
 
-Expected<std::vector<std::shared_ptr<DebugSubsection>>>
+Expected<std::vector<std::unique_ptr<DebugSubsection>>>
 llvm::CodeViewYAML::toCodeViewSubsectionList(
     BumpPtrAllocator &Allocator, ArrayRef<YAMLDebugSubsection> Subsections,
-    const codeview::StringsAndChecksums &SC) {
-  std::vector<std::shared_ptr<DebugSubsection>> Result;
+    DebugStringTableSubsection &Strings) {
+  std::vector<std::unique_ptr<DebugSubsection>> Result;
   if (Subsections.empty())
     return std::move(Result);
 
+  auto Checksums = findChecksums(Subsections);
+  std::unique_ptr<DebugSubsection> ChecksumsBase;
+  if (Checksums)
+    ChecksumsBase =
+        Checksums->toCodeViewSubsection(Allocator, &Strings, nullptr);
+  DebugChecksumsSubsection *CS =
+      static_cast<DebugChecksumsSubsection *>(ChecksumsBase.get());
   for (const auto &SS : Subsections) {
-    std::shared_ptr<DebugSubsection> CVS;
-    CVS = SS.Subsection->toCodeViewSubsection(Allocator, SC);
+    // We've already converted the checksums subsection, don't do it
+    // twice.
+    std::unique_ptr<DebugSubsection> CVS;
+    if (SS.Subsection->Kind == DebugSubsectionKind::FileChecksums)
+      CVS = std::move(ChecksumsBase);
+    else
+      CVS = SS.Subsection->toCodeViewSubsection(Allocator, &Strings, CS);
+    assert(CVS != nullptr);
+    Result.push_back(std::move(CVS));
+  }
+  return std::move(Result);
+}
+
+Expected<std::vector<std::unique_ptr<codeview::DebugSubsection>>>
+llvm::CodeViewYAML::toCodeViewSubsectionList(
+    BumpPtrAllocator &Allocator, ArrayRef<YAMLDebugSubsection> Subsections,
+    std::unique_ptr<DebugStringTableSubsection> &TakeStrings,
+    DebugStringTableSubsection *StringsRef) {
+  std::vector<std::unique_ptr<DebugSubsection>> Result;
+  if (Subsections.empty())
+    return std::move(Result);
+
+  auto Checksums = findChecksums(Subsections);
+
+  std::unique_ptr<DebugSubsection> ChecksumsBase;
+  if (Checksums)
+    ChecksumsBase =
+        Checksums->toCodeViewSubsection(Allocator, StringsRef, nullptr);
+  DebugChecksumsSubsection *CS =
+      static_cast<DebugChecksumsSubsection *>(ChecksumsBase.get());
+  for (const auto &SS : Subsections) {
+    // We've already converted the checksums and string table subsection, don't
+    // do it twice.
+    std::unique_ptr<DebugSubsection> CVS;
+    if (SS.Subsection->Kind == DebugSubsectionKind::FileChecksums)
+      CVS = std::move(ChecksumsBase);
+    else if (SS.Subsection->Kind == DebugSubsectionKind::StringTable) {
+      assert(TakeStrings && "No string table!");
+      CVS = std::move(TakeStrings);
+    } else
+      CVS = SS.Subsection->toCodeViewSubsection(Allocator, StringsRef, CS);
     assert(CVS != nullptr);
     Result.push_back(std::move(CVS));
   }
@@ -759,23 +810,23 @@ struct SubsectionConversionVisitor : pub
 
   Error visitUnknown(DebugUnknownSubsectionRef &Unknown) override;
   Error visitLines(DebugLinesSubsectionRef &Lines,
-                   const StringsAndChecksumsRef &State) override;
+                   const DebugSubsectionState &State) override;
   Error visitFileChecksums(DebugChecksumsSubsectionRef &Checksums,
-                           const StringsAndChecksumsRef &State) override;
+                           const DebugSubsectionState &State) override;
   Error visitInlineeLines(DebugInlineeLinesSubsectionRef &Inlinees,
-                          const StringsAndChecksumsRef &State) override;
+                          const DebugSubsectionState &State) override;
   Error visitCrossModuleExports(DebugCrossModuleExportsSubsectionRef &Checksums,
-                                const StringsAndChecksumsRef &State) override;
+                                const DebugSubsectionState &State) override;
   Error visitCrossModuleImports(DebugCrossModuleImportsSubsectionRef &Inlinees,
-                                const StringsAndChecksumsRef &State) override;
+                                const DebugSubsectionState &State) override;
   Error visitStringTable(DebugStringTableSubsectionRef &ST,
-                         const StringsAndChecksumsRef &State) override;
+                         const DebugSubsectionState &State) override;
   Error visitSymbols(DebugSymbolsSubsectionRef &Symbols,
-                     const StringsAndChecksumsRef &State) override;
+                     const DebugSubsectionState &State) override;
   Error visitFrameData(DebugFrameDataSubsectionRef &Symbols,
-                       const StringsAndChecksumsRef &State) override;
+                       const DebugSubsectionState &State) override;
   Error visitCOFFSymbolRVAs(DebugSymbolRVASubsectionRef &Symbols,
-                            const StringsAndChecksumsRef &State) override;
+                            const DebugSubsectionState &State) override;
 
   YAMLDebugSubsection Subsection;
 };
@@ -786,7 +837,7 @@ Error SubsectionConversionVisitor::visit
 }
 
 Error SubsectionConversionVisitor::visitLines(
-    DebugLinesSubsectionRef &Lines, const StringsAndChecksumsRef &State) {
+    DebugLinesSubsectionRef &Lines, const DebugSubsectionState &State) {
   auto Result = YAMLLinesSubsection::fromCodeViewSubsection(
       State.strings(), State.checksums(), Lines);
   if (!Result)
@@ -796,8 +847,7 @@ Error SubsectionConversionVisitor::visit
 }
 
 Error SubsectionConversionVisitor::visitFileChecksums(
-    DebugChecksumsSubsectionRef &Checksums,
-    const StringsAndChecksumsRef &State) {
+    DebugChecksumsSubsectionRef &Checksums, const DebugSubsectionState &State) {
   auto Result = YAMLChecksumsSubsection::fromCodeViewSubsection(State.strings(),
                                                                 Checksums);
   if (!Result)
@@ -808,7 +858,7 @@ Error SubsectionConversionVisitor::visit
 
 Error SubsectionConversionVisitor::visitInlineeLines(
     DebugInlineeLinesSubsectionRef &Inlinees,
-    const StringsAndChecksumsRef &State) {
+    const DebugSubsectionState &State) {
   auto Result = YAMLInlineeLinesSubsection::fromCodeViewSubsection(
       State.strings(), State.checksums(), Inlinees);
   if (!Result)
@@ -819,7 +869,7 @@ Error SubsectionConversionVisitor::visit
 
 Error SubsectionConversionVisitor::visitCrossModuleExports(
     DebugCrossModuleExportsSubsectionRef &Exports,
-    const StringsAndChecksumsRef &State) {
+    const DebugSubsectionState &State) {
   auto Result =
       YAMLCrossModuleExportsSubsection::fromCodeViewSubsection(Exports);
   if (!Result)
@@ -830,7 +880,7 @@ Error SubsectionConversionVisitor::visit
 
 Error SubsectionConversionVisitor::visitCrossModuleImports(
     DebugCrossModuleImportsSubsectionRef &Imports,
-    const StringsAndChecksumsRef &State) {
+    const DebugSubsectionState &State) {
   auto Result = YAMLCrossModuleImportsSubsection::fromCodeViewSubsection(
       State.strings(), Imports);
   if (!Result)
@@ -840,8 +890,7 @@ Error SubsectionConversionVisitor::visit
 }
 
 Error SubsectionConversionVisitor::visitStringTable(
-    DebugStringTableSubsectionRef &Strings,
-    const StringsAndChecksumsRef &State) {
+    DebugStringTableSubsectionRef &Strings, const DebugSubsectionState &State) {
   auto Result = YAMLStringTableSubsection::fromCodeViewSubsection(Strings);
   if (!Result)
     return Result.takeError();
@@ -850,7 +899,7 @@ Error SubsectionConversionVisitor::visit
 }
 
 Error SubsectionConversionVisitor::visitSymbols(
-    DebugSymbolsSubsectionRef &Symbols, const StringsAndChecksumsRef &State) {
+    DebugSymbolsSubsectionRef &Symbols, const DebugSubsectionState &State) {
   auto Result = YAMLSymbolsSubsection::fromCodeViewSubsection(Symbols);
   if (!Result)
     return Result.takeError();
@@ -859,7 +908,7 @@ Error SubsectionConversionVisitor::visit
 }
 
 Error SubsectionConversionVisitor::visitFrameData(
-    DebugFrameDataSubsectionRef &Frames, const StringsAndChecksumsRef &State) {
+    DebugFrameDataSubsectionRef &Frames, const DebugSubsectionState &State) {
   auto Result =
       YAMLFrameDataSubsection::fromCodeViewSubsection(State.strings(), Frames);
   if (!Result)
@@ -869,7 +918,7 @@ Error SubsectionConversionVisitor::visit
 }
 
 Error SubsectionConversionVisitor::visitCOFFSymbolRVAs(
-    DebugSymbolRVASubsectionRef &RVAs, const StringsAndChecksumsRef &State) {
+    DebugSymbolRVASubsectionRef &RVAs, const DebugSubsectionState &State) {
   auto Result = YAMLCoffSymbolRVASubsection::fromCodeViewSubsection(RVAs);
   if (!Result)
     return Result.takeError();
@@ -878,71 +927,29 @@ Error SubsectionConversionVisitor::visit
 }
 }
 
-Expected<YAMLDebugSubsection>
-YAMLDebugSubsection::fromCodeViewSubection(const StringsAndChecksumsRef &SC,
-                                           const DebugSubsectionRecord &SS) {
+Expected<YAMLDebugSubsection> YAMLDebugSubsection::fromCodeViewSubection(
+    const DebugStringTableSubsectionRef &Strings,
+    const DebugChecksumsSubsectionRef &Checksums,
+    const DebugSubsectionRecord &SS) {
+  DebugSubsectionState State(Strings, Checksums);
   SubsectionConversionVisitor V;
-  if (auto EC = visitDebugSubsection(SS, V, SC))
+  if (auto EC = visitDebugSubsection(SS, V, State))
     return std::move(EC);
 
   return V.Subsection;
 }
 
-std::vector<YAMLDebugSubsection>
-llvm::CodeViewYAML::fromDebugS(ArrayRef<uint8_t> Data,
-                               const StringsAndChecksumsRef &SC) {
-  BinaryStreamReader Reader(Data, support::little);
-  uint32_t Magic;
-
-  ExitOnError Err("Invalid .debug$S section!");
-  Err(Reader.readInteger(Magic));
-  assert(Magic == COFF::DEBUG_SECTION_MAGIC && "Invalid .debug$S section!");
-
-  DebugSubsectionArray Subsections;
-  Err(Reader.readArray(Subsections, Reader.bytesRemaining()));
-
-  std::vector<YAMLDebugSubsection> Result;
-
-  for (const auto &SS : Subsections) {
-    auto YamlSS = Err(YAMLDebugSubsection::fromCodeViewSubection(SC, SS));
-    Result.push_back(YamlSS);
-  }
-  return Result;
-}
-
-void llvm::CodeViewYAML::initializeStringsAndChecksums(
-    ArrayRef<YAMLDebugSubsection> Sections, codeview::StringsAndChecksums &SC) {
-  // String Table and Checksums subsections don't use the allocator.
-  BumpPtrAllocator Allocator;
-
-  // It's possible for checksums and strings to even appear in different debug$S
-  // sections, so we have to make this a stateful function that can build up
-  // the strings and checksums field over multiple iterations.
-
-  // File Checksums require the string table, but may become before it, so we
-  // have to scan for strings first, then scan for checksums again from the
-  // beginning.
-  if (!SC.hasStrings()) {
-    for (const auto &SS : Sections) {
-      if (SS.Subsection->Kind != DebugSubsectionKind::StringTable)
-        continue;
-
-      auto Result = SS.Subsection->toCodeViewSubsection(Allocator, SC);
-      SC.setStrings(
-          std::static_pointer_cast<DebugStringTableSubsection>(Result));
-      break;
-    }
-  }
+std::unique_ptr<DebugStringTableSubsection>
+llvm::CodeViewYAML::findStringTable(ArrayRef<YAMLDebugSubsection> Sections) {
+  for (const auto &SS : Sections) {
+    if (SS.Subsection->Kind != DebugSubsectionKind::StringTable)
+      continue;
 
-  if (SC.hasStrings() && !SC.hasChecksums()) {
-    for (const auto &SS : Sections) {
-      if (SS.Subsection->Kind != DebugSubsectionKind::FileChecksums)
-        continue;
-
-      auto Result = SS.Subsection->toCodeViewSubsection(Allocator, SC);
-      SC.setChecksums(
-          std::static_pointer_cast<DebugChecksumsSubsection>(Result));
-      break;
-    }
+    // String Table doesn't use the allocator.
+    BumpPtrAllocator Allocator;
+    auto Result =
+        SS.Subsection->toCodeViewSubsection(Allocator, nullptr, nullptr);
+    return llvm::cast<DebugStringTableSubsection>(std::move(Result));
   }
+  return nullptr;
 }

Modified: llvm/trunk/lib/ObjectYAML/CodeViewYAMLTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/CodeViewYAMLTypes.cpp?rev=305371&r1=305370&r2=305371&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/CodeViewYAMLTypes.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/CodeViewYAMLTypes.cpp Wed Jun 14 01:24:24 2017
@@ -714,43 +714,3 @@ void MappingTraits<MemberRecord>::mappin
   default: { llvm_unreachable("Unknown member kind!"); }
   }
 }
-
-std::vector<LeafRecord>
-llvm::CodeViewYAML::fromDebugT(ArrayRef<uint8_t> DebugT) {
-  ExitOnError Err("Invalid .debug$T section!");
-  BinaryStreamReader Reader(DebugT, support::little);
-  CVTypeArray Types;
-  uint32_t Magic;
-
-  Err(Reader.readInteger(Magic));
-  assert(Magic == COFF::DEBUG_SECTION_MAGIC && "Invalid .debug$T section!");
-
-  std::vector<LeafRecord> Result;
-  Err(Reader.readArray(Types, Reader.bytesRemaining()));
-  for (const auto &T : Types) {
-    auto CVT = Err(LeafRecord::fromCodeViewRecord(T));
-    Result.push_back(CVT);
-  }
-  return Result;
-}
-
-ArrayRef<uint8_t> llvm::CodeViewYAML::toDebugT(ArrayRef<LeafRecord> Leafs,
-                                               BumpPtrAllocator &Alloc) {
-  TypeTableBuilder TTB(Alloc, false);
-  uint32_t Size = sizeof(uint32_t);
-  for (const auto &Leaf : Leafs) {
-    CVType T = Leaf.toCodeViewRecord(TTB);
-    Size += T.length();
-    assert(T.length() % 4 == 0 && "Improper type record alignment!");
-  }
-  uint8_t *ResultBuffer = Alloc.Allocate<uint8_t>(Size);
-  MutableArrayRef<uint8_t> Output(ResultBuffer, Size);
-  BinaryStreamWriter Writer(Output, support::little);
-  ExitOnError Err("Error writing type record to .debug$T section");
-  Err(Writer.writeInteger<uint32_t>(COFF::DEBUG_SECTION_MAGIC));
-  for (const auto &R : TTB.records()) {
-    Err(Writer.writeBytes(R));
-  }
-  assert(Writer.bytesRemaining() == 0 && "Didn't write all type record bytes!");
-  return Output;
-}

Modified: llvm/trunk/tools/llvm-pdbutil/LLVMOutputStyle.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbutil/LLVMOutputStyle.cpp?rev=305371&r1=305370&r2=305371&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbutil/LLVMOutputStyle.cpp (original)
+++ llvm/trunk/tools/llvm-pdbutil/LLVMOutputStyle.cpp Wed Jun 14 01:24:24 2017
@@ -28,7 +28,6 @@
 #include "llvm/DebugInfo/CodeView/EnumTables.h"
 #include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
 #include "llvm/DebugInfo/CodeView/Line.h"
-#include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
 #include "llvm/DebugInfo/CodeView/SymbolDumper.h"
 #include "llvm/DebugInfo/CodeView/TypeDatabaseVisitor.h"
 #include "llvm/DebugInfo/CodeView/TypeDumpVisitor.h"
@@ -106,7 +105,7 @@ public:
   }
 
   Error visitLines(DebugLinesSubsectionRef &Lines,
-                   const StringsAndChecksumsRef &State) override {
+                   const DebugSubsectionState &State) override {
     if (!opts::checkModuleSubsection(opts::ModuleSubsection::Lines))
       return Error::success();
 
@@ -147,7 +146,7 @@ public:
   }
 
   Error visitFileChecksums(DebugChecksumsSubsectionRef &Checksums,
-                           const StringsAndChecksumsRef &State) override {
+                           const DebugSubsectionState &State) override {
     if (!opts::checkModuleSubsection(opts::ModuleSubsection::FileChecksums))
       return Error::success();
 
@@ -165,7 +164,7 @@ public:
   }
 
   Error visitInlineeLines(DebugInlineeLinesSubsectionRef &Inlinees,
-                          const StringsAndChecksumsRef &State) override {
+                          const DebugSubsectionState &State) override {
     if (!opts::checkModuleSubsection(opts::ModuleSubsection::InlineeLines))
       return Error::success();
 
@@ -192,7 +191,7 @@ public:
   }
 
   Error visitCrossModuleExports(DebugCrossModuleExportsSubsectionRef &CSE,
-                                const StringsAndChecksumsRef &State) override {
+                                const DebugSubsectionState &State) override {
     if (!opts::checkModuleSubsection(opts::ModuleSubsection::CrossScopeExports))
       return Error::success();
 
@@ -206,7 +205,7 @@ public:
   }
 
   Error visitCrossModuleImports(DebugCrossModuleImportsSubsectionRef &CSI,
-                                const StringsAndChecksumsRef &State) override {
+                                const DebugSubsectionState &State) override {
     if (!opts::checkModuleSubsection(opts::ModuleSubsection::CrossScopeImports))
       return Error::success();
 
@@ -223,7 +222,7 @@ public:
   }
 
   Error visitFrameData(DebugFrameDataSubsectionRef &FD,
-                       const StringsAndChecksumsRef &State) override {
+                       const DebugSubsectionState &State) override {
     if (!opts::checkModuleSubsection(opts::ModuleSubsection::FrameData))
       return Error::success();
 
@@ -249,7 +248,7 @@ public:
   }
 
   Error visitSymbols(DebugSymbolsSubsectionRef &Symbols,
-                     const StringsAndChecksumsRef &State) override {
+                     const DebugSubsectionState &State) override {
     if (!opts::checkModuleSubsection(opts::ModuleSubsection::Symbols))
       return Error::success();
     ListScope L(P, "Symbols");
@@ -271,7 +270,7 @@ public:
   }
 
   Error visitStringTable(DebugStringTableSubsectionRef &Strings,
-                         const StringsAndChecksumsRef &State) override {
+                         const DebugSubsectionState &State) override {
     if (!opts::checkModuleSubsection(opts::ModuleSubsection::StringTable))
       return Error::success();
 
@@ -289,7 +288,7 @@ public:
   }
 
   Error visitCOFFSymbolRVAs(DebugSymbolRVASubsectionRef &RVAs,
-                            const StringsAndChecksumsRef &State) override {
+                            const DebugSubsectionState &State) override {
     if (!opts::checkModuleSubsection(opts::ModuleSubsection::CoffSymbolRVAs))
       return Error::success();
 
@@ -310,7 +309,7 @@ private:
           return EC;
       }
     }
-
+    
     if (!Success) {
       P.printString(
           llvm::formatv("Index: {0:x} (unknown function)", Index.getIndex())
@@ -319,7 +318,7 @@ private:
     return Error::success();
   }
   Error printFileName(StringRef Label, uint32_t Offset,
-                      const StringsAndChecksumsRef &State) {
+                      const DebugSubsectionState &State) {
     if (auto Result = getNameFromChecksumsBuffer(Offset, State)) {
       P.printString(Label, *Result);
       return Error::success();
@@ -328,13 +327,13 @@ private:
   }
 
   Expected<StringRef>
-  getNameFromStringTable(uint32_t Offset, const StringsAndChecksumsRef &State) {
+  getNameFromStringTable(uint32_t Offset, const DebugSubsectionState &State) {
     return State.strings().getString(Offset);
   }
 
   Expected<StringRef>
   getNameFromChecksumsBuffer(uint32_t Offset,
-                             const StringsAndChecksumsRef &State) {
+                             const DebugSubsectionState &State) {
     auto Array = State.checksums().getArray();
     auto ChecksumIter = Array.at(Offset);
     if (ChecksumIter == Array.end())

Modified: llvm/trunk/tools/llvm-pdbutil/YAMLOutputStyle.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbutil/YAMLOutputStyle.cpp?rev=305371&r1=305370&r2=305371&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbutil/YAMLOutputStyle.cpp (original)
+++ llvm/trunk/tools/llvm-pdbutil/YAMLOutputStyle.cpp Wed Jun 14 01:24:24 2017
@@ -18,7 +18,6 @@
 #include "llvm/DebugInfo/CodeView/DebugSubsection.h"
 #include "llvm/DebugInfo/CodeView/DebugUnknownSubsection.h"
 #include "llvm/DebugInfo/CodeView/Line.h"
-#include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
 #include "llvm/DebugInfo/MSF/MappedBlockStream.h"
 #include "llvm/DebugInfo/PDB/Native/DbiStream.h"
 #include "llvm/DebugInfo/PDB/Native/InfoStream.h"
@@ -237,16 +236,14 @@ Error YAMLOutputStyle::dumpDbiStream() {
         if (!ExpectedChecksums)
           return ExpectedChecksums.takeError();
 
-        StringsAndChecksumsRef SC(ExpectedST->getStringTable(),
-                                  *ExpectedChecksums);
-
         for (const auto &SS : ModS.subsections()) {
           opts::ModuleSubsection OptionKind = convertSubsectionKind(SS.kind());
           if (!opts::checkModuleSubsection(OptionKind))
             continue;
 
           auto Converted =
-              CodeViewYAML::YAMLDebugSubsection::fromCodeViewSubection(SC, SS);
+              CodeViewYAML::YAMLDebugSubsection::fromCodeViewSubection(
+                  ExpectedST->getStringTable(), *ExpectedChecksums, SS);
           if (!Converted)
             return Converted.takeError();
           DMI.Subsections.push_back(*Converted);

Modified: llvm/trunk/tools/llvm-pdbutil/llvm-pdbutil.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbutil/llvm-pdbutil.cpp?rev=305371&r1=305370&r2=305371&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbutil/llvm-pdbutil.cpp (original)
+++ llvm/trunk/tools/llvm-pdbutil/llvm-pdbutil.cpp Wed Jun 14 01:24:24 2017
@@ -35,7 +35,6 @@
 #include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h"
 #include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h"
 #include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
-#include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
 #include "llvm/DebugInfo/CodeView/TypeStreamMerger.h"
 #include "llvm/DebugInfo/CodeView/TypeTableBuilder.h"
 #include "llvm/DebugInfo/MSF/MSFBuilder.h"
@@ -512,12 +511,10 @@ static void yamlToPdb(StringRef Path) {
   for (uint32_t I = 0; I < kSpecialStreamCount; ++I)
     ExitOnErr(Builder.getMsfBuilder().addStream(0));
 
-  StringsAndChecksums Strings;
-  Strings.setStrings(std::make_shared<DebugStringTableSubsection>());
-
   if (YamlObj.StringTable.hasValue()) {
+    auto &Strings = Builder.getStringTableBuilder();
     for (auto S : *YamlObj.StringTable)
-      Strings.strings()->insert(S);
+      Strings.insert(S);
   }
 
   pdb::yaml::PdbInfoStream DefaultInfoStream;
@@ -535,6 +532,8 @@ static void yamlToPdb(StringRef Path) {
   for (auto F : Info.Features)
     InfoBuilder.addFeature(F);
 
+  auto &Strings = Builder.getStringTableBuilder().getStrings();
+
   const auto &Dbi = YamlObj.DbiStream.getValueOr(DefaultDbiStream);
   auto &DbiBuilder = Builder.getDbiBuilder();
   DbiBuilder.setAge(Dbi.Age);
@@ -558,14 +557,10 @@ static void yamlToPdb(StringRef Path) {
       }
     }
 
-    // Each module has its own checksum subsection, so scan for it every time.
-    Strings.setChecksums(nullptr);
-    CodeViewYAML::initializeStringsAndChecksums(MI.Subsections, Strings);
-
     auto CodeViewSubsections = ExitOnErr(CodeViewYAML::toCodeViewSubsectionList(
         Allocator, MI.Subsections, Strings));
     for (auto &SS : CodeViewSubsections) {
-      ModiBuilder.addDebugSubsection(SS);
+      ModiBuilder.addDebugSubsection(std::move(SS));
     }
   }
 
@@ -585,8 +580,6 @@ static void yamlToPdb(StringRef Path) {
     IpiBuilder.addTypeRecord(Type.RecordData, None);
   }
 
-  Builder.getStringTableBuilder().setStrings(*Strings.strings());
-
   ExitOnErr(Builder.commit(opts::yaml2pdb::YamlPdbOutputFile));
 }
 

Modified: llvm/trunk/tools/obj2yaml/coff2yaml.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/obj2yaml/coff2yaml.cpp?rev=305371&r1=305370&r2=305371&view=diff
==============================================================================
--- llvm/trunk/tools/obj2yaml/coff2yaml.cpp (original)
+++ llvm/trunk/tools/obj2yaml/coff2yaml.cpp Wed Jun 14 01:24:24 2017
@@ -8,13 +8,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "obj2yaml.h"
-#include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
-#include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h"
-#include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
 #include "llvm/Object/COFF.h"
 #include "llvm/ObjectYAML/COFFYAML.h"
-#include "llvm/ObjectYAML/CodeViewYAMLSymbols.h"
-#include "llvm/ObjectYAML/CodeViewYAMLTypes.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/YAMLTraits.h"
 
@@ -104,45 +99,8 @@ void COFFDumper::dumpHeader() {
   YAMLObj.Header.Characteristics = Obj.getCharacteristics();
 }
 
-static void
-initializeFileAndStringTable(const llvm::object::COFFObjectFile &Obj,
-                             codeview::StringsAndChecksumsRef &SC) {
-
-  ExitOnError Err("Invalid .debug$S section!");
-  // Iterate all .debug$S sections looking for the checksums and string table.
-  // Exit as soon as both sections are found.
-  for (const auto &S : Obj.sections()) {
-    if (SC.hasStrings() && SC.hasChecksums())
-      break;
-
-    StringRef SectionName;
-    S.getName(SectionName);
-    ArrayRef<uint8_t> sectionData;
-    if (SectionName != ".debug$S")
-      continue;
-
-    const object::coff_section *COFFSection = Obj.getCOFFSection(S);
-
-    Obj.getSectionContents(COFFSection, sectionData);
-
-    BinaryStreamReader Reader(sectionData, support::little);
-    uint32_t Magic;
-
-    Err(Reader.readInteger(Magic));
-    assert(Magic == COFF::DEBUG_SECTION_MAGIC && "Invalid .debug$S section!");
-
-    codeview::DebugSubsectionArray Subsections;
-    Err(Reader.readArray(Subsections, Reader.bytesRemaining()));
-
-    SC.initialize(Subsections);
-  }
-}
-
 void COFFDumper::dumpSections(unsigned NumSections) {
   std::vector<COFFYAML::Section> &YAMLSections = YAMLObj.Sections;
-  codeview::StringsAndChecksumsRef SC;
-  initializeFileAndStringTable(Obj, SC);
-
   for (const auto &ObjSection : Obj.sections()) {
     const object::coff_section *COFFSection = Obj.getCOFFSection(ObjSection);
     COFFYAML::Section NewYAMLSection;
@@ -150,16 +108,6 @@ void COFFDumper::dumpSections(unsigned N
     NewYAMLSection.Header.Characteristics = COFFSection->Characteristics;
     NewYAMLSection.Header.VirtualAddress = ObjSection.getAddress();
     NewYAMLSection.Header.VirtualSize = COFFSection->VirtualSize;
-    NewYAMLSection.Header.NumberOfLineNumbers =
-        COFFSection->NumberOfLinenumbers;
-    NewYAMLSection.Header.NumberOfRelocations =
-        COFFSection->NumberOfRelocations;
-    NewYAMLSection.Header.PointerToLineNumbers =
-        COFFSection->PointerToLinenumbers;
-    NewYAMLSection.Header.PointerToRawData = COFFSection->PointerToRawData;
-    NewYAMLSection.Header.PointerToRelocations =
-        COFFSection->PointerToRelocations;
-    NewYAMLSection.Header.SizeOfRawData = COFFSection->SizeOfRawData;
     NewYAMLSection.Alignment = ObjSection.getAlignment();
     assert(NewYAMLSection.Alignment <= 8192);
 
@@ -168,11 +116,6 @@ void COFFDumper::dumpSections(unsigned N
       Obj.getSectionContents(COFFSection, sectionData);
     NewYAMLSection.SectionData = yaml::BinaryRef(sectionData);
 
-    if (NewYAMLSection.Name == ".debug$S")
-      NewYAMLSection.DebugS = CodeViewYAML::fromDebugS(sectionData, SC);
-    else if (NewYAMLSection.Name == ".debug$T")
-      NewYAMLSection.DebugT = CodeViewYAML::fromDebugT(sectionData);
-
     std::vector<COFFYAML::Relocation> Relocations;
     for (const auto &Reloc : ObjSection.relocations()) {
       const object::coff_relocation *reloc = Obj.getCOFFRelocation(Reloc);

Modified: llvm/trunk/tools/yaml2obj/yaml2coff.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2coff.cpp?rev=305371&r1=305370&r2=305371&view=diff
==============================================================================
--- llvm/trunk/tools/yaml2obj/yaml2coff.cpp (original)
+++ llvm/trunk/tools/yaml2obj/yaml2coff.cpp Wed Jun 14 01:24:24 2017
@@ -17,8 +17,6 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringSwitch.h"
-#include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h"
-#include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
 #include "llvm/Object/COFF.h"
 #include "llvm/ObjectYAML/ObjectYAML.h"
 #include "llvm/Support/Endian.h"
@@ -144,8 +142,6 @@ struct COFFParser {
 
   COFFYAML::Object &Obj;
 
-  codeview::StringsAndChecksums StringsAndChecksums;
-  BumpPtrAllocator Allocator;
   StringMap<unsigned> StringTableMap;
   std::string StringTable;
   uint32_t SectionTableStart;
@@ -169,32 +165,6 @@ namespace {
 enum { DOSStubSize = 128 };
 }
 
-static yaml::BinaryRef
-toDebugS(ArrayRef<CodeViewYAML::YAMLDebugSubsection> Subsections,
-         const codeview::StringsAndChecksums &SC, BumpPtrAllocator &Allocator) {
-  using namespace codeview;
-  ExitOnError Err("Error occurred writing .debug$S section");
-  auto CVSS =
-      Err(CodeViewYAML::toCodeViewSubsectionList(Allocator, Subsections, SC));
-
-  std::vector<DebugSubsectionRecordBuilder> Builders;
-  uint32_t Size = sizeof(uint32_t);
-  for (auto &SS : CVSS) {
-    DebugSubsectionRecordBuilder B(SS, CodeViewContainer::ObjectFile);
-    Size += B.calculateSerializedLength();
-    Builders.push_back(std::move(B));
-  }
-  uint8_t *Buffer = Allocator.Allocate<uint8_t>(Size);
-  MutableArrayRef<uint8_t> Output(Buffer, Size);
-  BinaryStreamWriter Writer(Output, support::little);
-
-  Err(Writer.writeInteger<uint32_t>(COFF::DEBUG_SECTION_MAGIC));
-  for (const auto &B : Builders) {
-    Err(B.commit(Writer));
-  }
-  return {Output};
-}
-
 // Take a CP and assign addresses and sizes to everything. Returns false if the
 // layout is not valid to do.
 static bool layoutCOFF(COFFParser &CP) {
@@ -209,33 +179,8 @@ static bool layoutCOFF(COFFParser &CP) {
   uint32_t CurrentSectionDataOffset =
       CP.SectionTableStart + CP.SectionTableSize;
 
-  for (COFFYAML::Section &S : CP.Obj.Sections) {
-    // We support specifying exactly one of SectionData or Subsections.  So if
-    // there is already some SectionData, then we don't need to do any of this.
-    if (S.Name == ".debug$S" && S.SectionData.binary_size() == 0) {
-      CodeViewYAML::initializeStringsAndChecksums(S.DebugS,
-                                                  CP.StringsAndChecksums);
-      if (CP.StringsAndChecksums.hasChecksums() &&
-          CP.StringsAndChecksums.hasStrings())
-        break;
-    }
-  }
-
   // Assign each section data address consecutively.
   for (COFFYAML::Section &S : CP.Obj.Sections) {
-    if (S.Name == ".debug$S") {
-      if (S.SectionData.binary_size() == 0) {
-        assert(CP.StringsAndChecksums.hasStrings() &&
-               "Object file does not have debug string table!");
-
-        S.SectionData =
-            toDebugS(S.DebugS, CP.StringsAndChecksums, CP.Allocator);
-      }
-    } else if (S.Name == ".debug$T") {
-      if (S.SectionData.binary_size() == 0)
-        S.SectionData = CodeViewYAML::toDebugT(S.DebugT, CP.Allocator);
-    }
-
     if (S.SectionData.binary_size() > 0) {
       CurrentSectionDataOffset = alignTo(CurrentSectionDataOffset,
                                          CP.isPE() ? CP.getFileAlignment() : 4);
@@ -598,7 +543,6 @@ int yaml2coff(llvm::COFFYAML::Object &Do
     errs() << "yaml2obj: Failed to layout optional header for COFF file!\n";
     return 1;
   }
-
   if (!layoutCOFF(CP)) {
     errs() << "yaml2obj: Failed to layout COFF file!\n";
     return 1;




More information about the llvm-commits mailing list