[lld] r298717 - [PDB] Split item and type records when merging type streams
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 24 10:26:38 PDT 2017
Author: rnk
Date: Fri Mar 24 12:26:38 2017
New Revision: 298717
URL: http://llvm.org/viewvc/llvm-project?rev=298717&view=rev
Log:
[PDB] Split item and type records when merging type streams
Summary: MSVC does this when producing a PDB.
Reviewers: ruiu
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D31316
Modified:
lld/trunk/COFF/PDB.cpp
lld/trunk/test/COFF/pdb.test
Modified: lld/trunk/COFF/PDB.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/PDB.cpp?rev=298717&r1=298716&r2=298717&view=diff
==============================================================================
--- lld/trunk/COFF/PDB.cpp (original)
+++ lld/trunk/COFF/PDB.cpp Fri Mar 24 12:26:38 2017
@@ -82,18 +82,40 @@ static ArrayRef<uint8_t> getDebugSection
return Data.slice(4);
}
-// Merge .debug$T sections and returns it.
-static std::vector<uint8_t> mergeDebugT(SymbolTable *Symtab) {
- ScopedPrinter W(outs());
+static void addTypeInfo(pdb::TpiStreamBuilder &TpiBuilder,
+ codeview::TypeTableBuilder &TypeTable,
+ std::vector<uint8_t> &Data) {
+ // Start the TPI or IPI stream header.
+ TpiBuilder.setVersionHeader(pdb::PdbTpiV80);
+
+ // Flatten the in memory type table.
+ // FIXME: Avoid this copy.
+ TypeTable.ForEachRecord([&](TypeIndex TI, ArrayRef<uint8_t> Rec) {
+ Data.insert(Data.end(), Rec.begin(), Rec.end());
+ });
+
+ BinaryByteStream Stream(Data, support::little);
+ codeview::CVTypeArray Records;
+ BinaryStreamReader Reader(Stream);
+ if (auto EC = Reader.readArray(Records, Reader.getLength()))
+ fatal(EC, "Reader.readArray failed");
+ for (const codeview::CVType &Rec : Records)
+ TpiBuilder.addTypeRecord(Rec);
+}
+// Merge .debug$T sections into IpiData and TpiData.
+static void mergeDebugT(SymbolTable *Symtab, pdb::PDBFileBuilder &Builder,
+ std::vector<uint8_t> &TpiData,
+ std::vector<uint8_t> &IpiData) {
// Visit all .debug$T sections to add them to Builder.
- codeview::TypeTableBuilder Builder(BAlloc);
+ codeview::TypeTableBuilder IDTable(BAlloc);
+ codeview::TypeTableBuilder TypeTable(BAlloc);
for (ObjectFile *File : Symtab->ObjectFiles) {
ArrayRef<uint8_t> Data = getDebugSection(File, ".debug$T");
if (Data.empty())
continue;
- BinaryByteStream Stream(Data, llvm::support::little);
+ BinaryByteStream Stream(Data, support::little);
codeview::CVTypeArray Types;
BinaryStreamReader Reader(Stream);
// Follow type servers. If the same type server is encountered more than
@@ -104,16 +126,16 @@ static std::vector<uint8_t> mergeDebugT(
Handler.addSearchPath(llvm::sys::path::parent_path(File->getName()));
if (auto EC = Reader.readArray(Types, Reader.getLength()))
fatal(EC, "Reader::readArray failed");
- if (auto Err = codeview::mergeTypeStreams(Builder, &Handler, Types))
+ if (auto Err =
+ codeview::mergeTypeStreams(IDTable, TypeTable, &Handler, Types))
fatal(Err, "codeview::mergeTypeStreams failed");
}
- // Construct section contents.
- std::vector<uint8_t> V;
- Builder.ForEachRecord([&](TypeIndex TI, ArrayRef<uint8_t> Rec) {
- V.insert(V.end(), Rec.begin(), Rec.end());
- });
- return V;
+ // Construct TPI stream contents.
+ addTypeInfo(Builder.getTpiBuilder(), TypeTable, TpiData);
+
+ // Construct IPI stream contents.
+ addTypeInfo(Builder.getIpiBuilder(), IDTable, IpiData);
}
static void dumpDebugT(ScopedPrinter &W, ObjectFile *File) {
@@ -159,17 +181,6 @@ static void dumpCodeView(SymbolTable *Sy
}
}
-static void addTypeInfo(pdb::TpiStreamBuilder &TpiBuilder,
- ArrayRef<uint8_t> Data) {
- BinaryByteStream Stream(Data, llvm::support::little);
- codeview::CVTypeArray Records;
- BinaryStreamReader Reader(Stream);
- if (auto EC = Reader.readArray(Records, Reader.getLength()))
- fatal(EC, "Reader.readArray failed");
- for (const codeview::CVType &Rec : Records)
- TpiBuilder.addTypeRecord(Rec);
-}
-
// Creates a PDB file.
void coff::createPDB(StringRef Path, SymbolTable *Symtab,
ArrayRef<uint8_t> SectionTable,
@@ -202,18 +213,9 @@ void coff::createPDB(StringRef Path, Sym
auto &DbiBuilder = Builder.getDbiBuilder();
DbiBuilder.setVersionHeader(pdb::PdbDbiV110);
- // Add an empty TPI stream.
- auto &TpiBuilder = Builder.getTpiBuilder();
- TpiBuilder.setVersionHeader(pdb::PdbTpiV80);
std::vector<uint8_t> TpiData;
- if (Config->DebugPdb) {
- TpiData = mergeDebugT(Symtab);
- addTypeInfo(TpiBuilder, TpiData);
- }
-
- // Add an empty IPI stream.
- auto &IpiBuilder = Builder.getIpiBuilder();
- IpiBuilder.setVersionHeader(pdb::PdbTpiV80);
+ std::vector<uint8_t> IpiData;
+ mergeDebugT(Symtab, Builder, TpiData, IpiData);
// Add Section Contributions.
std::vector<pdb::SectionContrib> Contribs =
Modified: lld/trunk/test/COFF/pdb.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/pdb.test?rev=298717&r1=298716&r2=298717&view=diff
==============================================================================
--- lld/trunk/test/COFF/pdb.test (original)
+++ lld/trunk/test/COFF/pdb.test Fri Mar 24 12:26:38 2017
@@ -60,6 +60,9 @@
# CHECK-NEXT: Options: [ None ]
# CHECK-NEXT: ParameterCount: 0
# CHECK-NEXT: ArgumentList: 4099
+# CHECK-NEXT: IpiStream:
+# CHECK-NEXT: Version: VC80
+# CHECK-NEXT: Records:
# CHECK-NEXT: - Kind: LF_FUNC_ID
# CHECK-NEXT: FuncId:
# CHECK-NEXT: ParentScope: 0
@@ -84,10 +87,10 @@
# CHECK-NEXT: String: '-Z7 -c -MT -IC:\vs14\VC\INCLUDE -IC:\vs14\VC\ATLMFC\INCLUDE -I"C:\Program Files (x86)\Windows Kits\10\include\10.0.10150.0\ucrt" -I"C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6\include\um" -I"C:\Program Files (x86)\Windows Kits\8.1\include\shared"'
# CHECK-NEXT: - Kind: LF_SUBSTR_LIST
# CHECK-NEXT: StringList:
-# CHECK-NEXT: StringIndices: [ 4105 ]
+# CHECK-NEXT: StringIndices: [ 4100 ]
# CHECK-NEXT: - Kind: LF_STRING_ID
# CHECK-NEXT: StringId:
-# CHECK-NEXT: Id: 4106
+# CHECK-NEXT: Id: 4101
# CHECK-NEXT: String: ' -I"C:\Program Files (x86)\Windows Kits\8.1\include\um" -I"C:\Program Files (x86)\Windows Kits\8.1\include\winrt" -TC -X'
# CHECK-NEXT: - Kind: LF_STRING_ID
# CHECK-NEXT: StringId:
@@ -99,17 +102,14 @@
# CHECK-NEXT: String: 'D:\b\vc140.pdb'
# CHECK-NEXT: - Kind: LF_BUILDINFO
# CHECK-NEXT: BuildInfo:
-# CHECK-NEXT: ArgIndices: [ 4103, 4104, 4108, 4109, 4107 ]
+# CHECK-NEXT: ArgIndices: [ 4098, 4099, 4103, 4104, 4102 ]
# CHECK-NEXT: - Kind: LF_STRING_ID
# CHECK-NEXT: StringId:
# CHECK-NEXT: Id: 0
# CHECK-NEXT: String: ret42-sub.c
# CHECK-NEXT: - Kind: LF_BUILDINFO
# CHECK-NEXT: BuildInfo:
-# CHECK-NEXT: ArgIndices: [ 4103, 4104, 4111, 4109, 4107 ]
-# CHECK-NEXT: IpiStream:
-# CHECK-NEXT: Version: VC80
-# CHECK-NEXT: Records:
+# CHECK-NEXT: ArgIndices: [ 4098, 4099, 4106, 4104, 4102 ]
# RAW: FileHeaders {
# RAW-NEXT: BlockSize: 4096
More information about the llvm-commits
mailing list