OSDN Git Service

Define DbiStreamBuilder::addSectionContribs.
authorRui Ueyama <ruiu@google.com>
Fri, 11 Nov 2016 23:41:13 +0000 (23:41 +0000)
committerRui Ueyama <ruiu@google.com>
Fri, 11 Nov 2016 23:41:13 +0000 (23:41 +0000)
This patch defines a new function to add a SectionContribs stream
to a PDB file. Unlike SectionMap, SectionContribs contains a list
of input sections as opposed to output sections.

Note that this patch needs improving because currently we do not
set Module field in SectionContribs entries. In a follow-up patch,
I'll add Modules and then fix it after that.

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

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

include/llvm/DebugInfo/PDB/Raw/DbiStreamBuilder.h
lib/DebugInfo/PDB/Raw/DbiStreamBuilder.cpp

index 0784b5e..da1eab8 100644 (file)
@@ -47,6 +47,7 @@ public:
   void setPdbDllRbld(uint16_t R);
   void setFlags(uint16_t F);
   void setMachineType(PDB_Machine M);
   void setPdbDllRbld(uint16_t R);
   void setFlags(uint16_t F);
   void setMachineType(PDB_Machine M);
+  void setSectionContribs(ArrayRef<SectionContrib> SecMap);
   void setSectionMap(ArrayRef<SecMapEntry> SecMap);
 
   // Add given bytes as a new stream.
   void setSectionMap(ArrayRef<SecMapEntry> SecMap);
 
   // Add given bytes as a new stream.
@@ -63,6 +64,11 @@ public:
   Error commit(const msf::MSFLayout &Layout,
                const msf::WritableStream &Buffer);
 
   Error commit(const msf::MSFLayout &Layout,
                const msf::WritableStream &Buffer);
 
+  // A helper function to create Section Contributions from COFF input
+  // section headers.
+  static std::vector<SectionContrib>
+  createSectionContribs(ArrayRef<llvm::object::coff_section> SecHdrs);
+
   // A helper function to create a Section Map from a COFF section header.
   static std::vector<SecMapEntry>
   createSectionMap(ArrayRef<llvm::object::coff_section> SecHdrs);
   // A helper function to create a Section Map from a COFF section header.
   static std::vector<SecMapEntry>
   createSectionMap(ArrayRef<llvm::object::coff_section> SecHdrs);
@@ -75,6 +81,7 @@ private:
 
   Error finalize();
   uint32_t calculateModiSubstreamSize() const;
 
   Error finalize();
   uint32_t calculateModiSubstreamSize() const;
+  uint32_t calculateSectionContribsStreamSize() const;
   uint32_t calculateSectionMapStreamSize() const;
   uint32_t calculateFileInfoSubstreamSize() const;
   uint32_t calculateNamesBufferSize() const;
   uint32_t calculateSectionMapStreamSize() const;
   uint32_t calculateFileInfoSubstreamSize() const;
   uint32_t calculateNamesBufferSize() const;
@@ -110,6 +117,7 @@ private:
   msf::WritableStreamRef NamesBuffer;
   msf::MutableByteStream ModInfoBuffer;
   msf::MutableByteStream FileInfoBuffer;
   msf::WritableStreamRef NamesBuffer;
   msf::MutableByteStream ModInfoBuffer;
   msf::MutableByteStream FileInfoBuffer;
+  ArrayRef<SectionContrib> SectionContribs;
   ArrayRef<SecMapEntry> SectionMap;
   llvm::SmallVector<DebugStream, (int)DbgHeaderType::Max> DbgStreams;
 };
   ArrayRef<SecMapEntry> SectionMap;
   llvm::SmallVector<DebugStream, (int)DbgHeaderType::Max> DbgStreams;
 };
index 6067e5c..279f9d5 100644 (file)
@@ -46,6 +46,10 @@ void DbiStreamBuilder::setFlags(uint16_t F) { Flags = F; }
 
 void DbiStreamBuilder::setMachineType(PDB_Machine M) { MachineType = M; }
 
 
 void DbiStreamBuilder::setMachineType(PDB_Machine M) { MachineType = M; }
 
+void DbiStreamBuilder::setSectionContribs(ArrayRef<SectionContrib> Arr) {
+  SectionContribs = Arr;
+}
+
 void DbiStreamBuilder::setSectionMap(ArrayRef<SecMapEntry> SecMap) {
   SectionMap = SecMap;
 }
 void DbiStreamBuilder::setSectionMap(ArrayRef<SecMapEntry> SecMap) {
   SectionMap = SecMap;
 }
@@ -67,8 +71,8 @@ Error DbiStreamBuilder::addDbgStream(pdb::DbgHeaderType Type,
 uint32_t DbiStreamBuilder::calculateSerializedLength() const {
   // For now we only support serializing the header.
   return sizeof(DbiStreamHeader) + calculateFileInfoSubstreamSize() +
 uint32_t DbiStreamBuilder::calculateSerializedLength() const {
   // For now we only support serializing the header.
   return sizeof(DbiStreamHeader) + calculateFileInfoSubstreamSize() +
-         calculateModiSubstreamSize() + calculateSectionMapStreamSize() +
-         calculateDbgStreamsSize();
+         calculateModiSubstreamSize() + calculateSectionContribsStreamSize() +
+         calculateSectionMapStreamSize() + calculateDbgStreamsSize();
 }
 
 Error DbiStreamBuilder::addModuleInfo(StringRef ObjFile, StringRef Module) {
 }
 
 Error DbiStreamBuilder::addModuleInfo(StringRef ObjFile, StringRef Module) {
@@ -106,6 +110,13 @@ uint32_t DbiStreamBuilder::calculateModiSubstreamSize() const {
   return Size;
 }
 
   return Size;
 }
 
+uint32_t DbiStreamBuilder::calculateSectionContribsStreamSize() const {
+  if (SectionContribs.empty())
+    return 0;
+  return sizeof(enum PdbRaw_DbiSecContribVer) +
+         sizeof(SectionContribs[0]) * SectionContribs.size();
+};
+
 uint32_t DbiStreamBuilder::calculateSectionMapStreamSize() const {
   if (SectionMap.empty())
     return 0;
 uint32_t DbiStreamBuilder::calculateSectionMapStreamSize() const {
   if (SectionMap.empty())
     return 0;
@@ -249,7 +260,7 @@ Error DbiStreamBuilder::finalize() {
   H->FileInfoSize = FileInfoBuffer.getLength();
   H->ModiSubstreamSize = ModInfoBuffer.getLength();
   H->OptionalDbgHdrSize = DbgStreams.size() * sizeof(uint16_t);
   H->FileInfoSize = FileInfoBuffer.getLength();
   H->ModiSubstreamSize = ModInfoBuffer.getLength();
   H->OptionalDbgHdrSize = DbgStreams.size() * sizeof(uint16_t);
-  H->SecContrSubstreamSize = 0;
+  H->SecContrSubstreamSize = calculateSectionContribsStreamSize();
   H->SectionMapSize = calculateSectionMapStreamSize();
   H->TypeServerSize = 0;
   H->SymRecordStreamIndex = kInvalidStreamIndex;
   H->SectionMapSize = calculateSectionMapStreamSize();
   H->TypeServerSize = 0;
   H->SymRecordStreamIndex = kInvalidStreamIndex;
@@ -287,6 +298,25 @@ static uint16_t toSecMapFlags(uint32_t Flags) {
   return Ret;
 }
 
   return Ret;
 }
 
+// A utility function to create Section Contributions
+// for a given input sections.
+std::vector<SectionContrib> DbiStreamBuilder::createSectionContribs(
+    ArrayRef<object::coff_section> SecHdrs) {
+  std::vector<SectionContrib> Ret;
+
+  // Create a SectionContrib for each input section.
+  for (auto &Sec : SecHdrs) {
+    Ret.emplace_back();
+    auto &Entry = Ret.back();
+    memset(&Entry, 0, sizeof(Entry));
+
+    Entry.Off = Sec.PointerToRawData;
+    Entry.Size = Sec.SizeOfRawData;
+    Entry.Characteristics = Sec.Characteristics;
+  }
+  return Ret;
+}
+
 // A utility function to create a Section Map for a given list of COFF sections.
 //
 // A Section Map seem to be a copy of a COFF section list in other format.
 // A utility function to create a Section Map for a given list of COFF sections.
 //
 // A Section Map seem to be a copy of a COFF section list in other format.
@@ -363,6 +393,13 @@ Error DbiStreamBuilder::commit(const msf::MSFLayout &Layout,
   if (auto EC = Writer.writeStreamRef(ModInfoBuffer))
     return EC;
 
   if (auto EC = Writer.writeStreamRef(ModInfoBuffer))
     return EC;
 
+  if (!SectionContribs.empty()) {
+    if (auto EC = Writer.writeEnum(DbiSecContribVer60))
+      return EC;
+    if (auto EC = Writer.writeArray(SectionContribs))
+      return EC;
+  }
+
   if (!SectionMap.empty()) {
     ulittle16_t Size = static_cast<ulittle16_t>(SectionMap.size());
     SecMapHeader SMHeader = {Size, Size};
   if (!SectionMap.empty()) {
     ulittle16_t Size = static_cast<ulittle16_t>(SectionMap.size());
     SecMapHeader SMHeader = {Size, Size};