[PATCH] D49231: Add import libraries to list of modules in PDB
Stefan Reinalter via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 18 03:19:20 PDT 2018
stefan_reinalter updated this revision to Diff 156033.
stefan_reinalter added a comment.
Updated diff to only contain formatted changes for new code.
https://reviews.llvm.org/D49231
Files:
COFF/Driver.cpp
COFF/PDB.cpp
Index: COFF/PDB.cpp
===================================================================
--- COFF/PDB.cpp
+++ COFF/PDB.cpp
@@ -101,6 +101,9 @@
/// Link CodeView from each object file in the symbol table into the PDB.
void addObjectsToPDB();
+ /// Link info for each import file in the symbol table into the PDB.
+ void addImportFilesToPDB();
+
/// Link CodeView from a single object file into the PDB.
void addObjFile(ObjFile *File);
@@ -1000,6 +1003,43 @@
}
}
+// Add all import files as modules to the PDB.
+void PDBLinker::addImportFilesToPDB() {
+ // Gather unique import files first.
+ std::vector<ImportFile *> ImpFiles;
+ ImpFiles.reserve(ImportFile::Instances.size());
+
+ std::unordered_set<std::string> UniqueImpFiles;
+ for (ImportFile *File : ImportFile::Instances) {
+ const auto &InsertIt = UniqueImpFiles.insert(File->DLLName);
+ if (InsertIt.second) {
+ // Found a new unique import file.
+ ImpFiles.push_back(File);
+ }
+ }
+
+ // Now walk all import files and add them as modules to the PDB.
+ for (ImportFile *File : ImpFiles) {
+ SmallString<128> LibPath = File->ParentName;
+ sys::fs::make_absolute(LibPath);
+ sys::path::native(LibPath, sys::path::Style::windows);
+
+ // Name modules similar to MSVC's link.exe.
+ SmallString<128> Name = "Import:" + File->DLLName;
+ llvm::pdb::DbiModuleDescriptorBuilder *ModuleDBI =
+ &ExitOnErr(Builder.getDbiBuilder().addModuleInfo(Name));
+ ModuleDBI->setObjFileName(LibPath);
+ ExitOnErr(Builder.getDbiBuilder().addModuleSourceFile(*ModuleDBI, Name));
+
+ ObjNameSym ONS(SymbolRecordKind::ObjNameSym);
+ ONS.Name = File->DLLName;
+ ONS.Signature = 0;
+
+ ModuleDBI->addSymbol(codeview::SymbolSerializer::writeOneSymbol(
+ ONS, Alloc, CodeViewContainer::Pdb));
+ }
+}
+
void PDBLinker::addNatvisFiles() {
for (StringRef File : Config->NatvisFiles) {
ErrorOr<std::unique_ptr<MemoryBuffer>> DataOrErr =
@@ -1109,6 +1149,7 @@
PDB.initialize(BuildId);
PDB.addObjectsToPDB();
+ PDB.addImportFilesToPDB();
PDB.addSections(OutputSections, SectionTable);
PDB.addNatvisFiles();
Index: COFF/Driver.cpp
===================================================================
--- COFF/Driver.cpp
+++ COFF/Driver.cpp
@@ -187,7 +187,9 @@
StringRef ParentName) {
file_magic Magic = identify_magic(MB.getBuffer());
if (Magic == file_magic::coff_import_library) {
- Symtab->addFile(make<ImportFile>(MB));
+ InputFile *Imp = make<ImportFile>(MB);
+ Imp->ParentName = ParentName;
+ Symtab->addFile(Imp);
return;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49231.156033.patch
Type: text/x-patch
Size: 2644 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180718/0634cd78/attachment.bin>
More information about the llvm-commits
mailing list