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(MB)); + InputFile *Imp = make(MB); + Imp->ParentName = ParentName; + Symtab->addFile(Imp); return; } 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 ImpFiles; + ImpFiles.reserve(ImportFile::Instances.size()); + + std::unordered_set 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> DataOrErr = @@ -1109,6 +1149,7 @@ PDB.initialize(BuildId); PDB.addObjectsToPDB(); + PDB.addImportFilesToPDB(); PDB.addSections(OutputSections, SectionTable); PDB.addNatvisFiles();