diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-06-16 21:04:14 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-06-16 21:04:14 +0000 |
commit | 15f7a1a3796209b21af2817fdf11ca9932165c70 (patch) | |
tree | b27ac12a6f210080b2233100767c839224666505 /COFF | |
parent | 2079716dfb3fb7e4e24b8b2e85eb6780b981a0af (diff) | |
download | src-15f7a1a3796209b21af2817fdf11ca9932165c70.tar.gz src-15f7a1a3796209b21af2817fdf11ca9932165c70.zip |
Vendor import of lld trunk r305575:vendor/lld/lld-trunk-r305575
Notes
Notes:
svn path=/vendor/lld/dist/; revision=320021
svn path=/vendor/lld/lld-trunk-r305575/; revision=320022; tag=vendor/lld/lld-trunk-r305575
Diffstat (limited to 'COFF')
-rw-r--r-- | COFF/Driver.cpp | 21 | ||||
-rw-r--r-- | COFF/DriverUtils.cpp | 2 | ||||
-rw-r--r-- | COFF/InputFiles.h | 12 | ||||
-rw-r--r-- | COFF/PDB.cpp | 38 |
4 files changed, 52 insertions, 21 deletions
diff --git a/COFF/Driver.cpp b/COFF/Driver.cpp index 27b1c48ce3e5..71a9c679d19f 100644 --- a/COFF/Driver.cpp +++ b/COFF/Driver.cpp @@ -429,7 +429,7 @@ static std::string getImplibPath() { return Out.str(); } -std::vector<COFFShortExport> createCOFFShortExportFromConfig() { +static void createImportLibrary() { std::vector<COFFShortExport> Exports; for (Export &E1 : Config->Exports) { COFFShortExport E2; @@ -443,11 +443,7 @@ std::vector<COFFShortExport> createCOFFShortExportFromConfig() { E2.Constant = E1.Constant; Exports.push_back(E2); } - return Exports; -} -static void createImportLibrary() { - std::vector<COFFShortExport> Exports = createCOFFShortExportFromConfig(); std::string DLLName = sys::path::filename(Config->OutputFile); std::string Path = getImplibPath(); writeImportLibrary(DLLName, Path, Exports, Config->Machine); @@ -707,8 +703,12 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) { } } - if (!Args.hasArgNoClaim(OPT_INPUT)) - fatal("no input files"); + if (!Args.hasArgNoClaim(OPT_INPUT)) { + if (Args.hasArgNoClaim(OPT_deffile)) + Config->NoEntry = true; + else + fatal("no input files"); + } // Construct search path list. SearchPaths.push_back(""); @@ -990,6 +990,13 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) { parseModuleDefs(Arg->getValue()); } + // Handle generation of import library from a def file. + if (!Args.hasArgNoClaim(OPT_INPUT)) { + fixupExports(); + createImportLibrary(); + exit(0); + } + // Handle /delayload for (auto *Arg : Args.filtered(OPT_delayload)) { Config->DelayLoads.insert(StringRef(Arg->getValue()).lower()); diff --git a/COFF/DriverUtils.cpp b/COFF/DriverUtils.cpp index ee4bd0f6b22c..42619b8fa438 100644 --- a/COFF/DriverUtils.cpp +++ b/COFF/DriverUtils.cpp @@ -522,7 +522,7 @@ void fixupExports() { for (Export &E : Config->Exports) { SymbolBody *Sym = E.Sym; - if (!E.ForwardTo.empty()) { + if (!E.ForwardTo.empty() || !Sym) { E.SymbolName = E.Name; } else { if (auto *U = dyn_cast<Undefined>(Sym)) diff --git a/COFF/InputFiles.h b/COFF/InputFiles.h index 9449f24ac241..99868d9992c6 100644 --- a/COFF/InputFiles.h +++ b/COFF/InputFiles.h @@ -22,6 +22,12 @@ #include <set> #include <vector> +namespace llvm { +namespace pdb { +class DbiModuleDescriptorBuilder; +} +} + namespace lld { namespace coff { @@ -122,6 +128,12 @@ public: // COFF-specific and x86-only. std::set<SymbolBody *> SEHandlers; + // Pointer to the PDB module descriptor builder. Various debug info records + // will reference object files by "module index", which is here. Things like + // source files and section contributions are also recorded here. Will be null + // if we are not producing a PDB. + llvm::pdb::DbiModuleDescriptorBuilder *ModuleDBI = nullptr; + private: void initializeChunks(); void initializeSymbols(); diff --git a/COFF/PDB.cpp b/COFF/PDB.cpp index eb8c3820412d..116766740e58 100644 --- a/COFF/PDB.cpp +++ b/COFF/PDB.cpp @@ -29,6 +29,7 @@ #include "llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h" #include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/Native/PDBFileBuilder.h" +#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.h" #include "llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h" #include "llvm/DebugInfo/PDB/Native/PDBTypeServerHandler.h" #include "llvm/DebugInfo/PDB/Native/TpiStream.h" @@ -53,12 +54,10 @@ using llvm::object::coff_section; static ExitOnError ExitOnErr; // Returns a list of all SectionChunks. -static std::vector<coff_section> getInputSections(SymbolTable *Symtab) { - std::vector<coff_section> V; +static void addSectionContribs(SymbolTable *Symtab, pdb::DbiStreamBuilder &DbiBuilder) { for (Chunk *C : Symtab->getChunks()) if (auto *SC = dyn_cast<SectionChunk>(C)) - V.push_back(*SC->Header); - return V; + DbiBuilder.addSectionContrib(SC->File->ModuleDBI, SC->Header); } static SectionChunk *findByName(std::vector<SectionChunk *> &Sections, @@ -95,10 +94,11 @@ static void addTypeInfo(pdb::TpiStreamBuilder &TpiBuilder, }); } -// Merge .debug$T sections into IpiData and TpiData. -static void mergeDebugT(SymbolTable *Symtab, pdb::PDBFileBuilder &Builder, - codeview::TypeTableBuilder &TypeTable, - codeview::TypeTableBuilder &IDTable) { +// Add all object files to the PDB. Merge .debug$T sections into IpiData and +// TpiData. +static void addObjectsToPDB(SymbolTable *Symtab, pdb::PDBFileBuilder &Builder, + codeview::TypeTableBuilder &TypeTable, + codeview::TypeTableBuilder &IDTable) { // Follow type servers. If the same type server is encountered more than // once for this instance of `PDBTypeServerHandler` (for example if many // object files reference the same TypeServer), the types from the @@ -107,6 +107,20 @@ static void mergeDebugT(SymbolTable *Symtab, pdb::PDBFileBuilder &Builder, // Visit all .debug$T sections to add them to Builder. for (ObjectFile *File : Symtab->ObjectFiles) { + // Add a module descriptor for every object file. We need to put an absolute + // path to the object into the PDB. If this is a plain object, we make its + // path absolute. If it's an object in an archive, we make the archive path + // absolute. + bool InArchive = !File->ParentName.empty(); + SmallString<128> Path = InArchive ? File->ParentName : File->getName(); + sys::fs::make_absolute(Path); + StringRef Name = InArchive ? File->getName() : StringRef(Path); + File->ModuleDBI = &ExitOnErr(Builder.getDbiBuilder().addModuleInfo(Name)); + File->ModuleDBI->setObjFileName(Path); + + // FIXME: Walk the .debug$S sections and add them. Do things like recording + // source files. + ArrayRef<uint8_t> Data = getDebugSection(File, ".debug$T"); if (Data.empty()) continue; @@ -202,17 +216,15 @@ void coff::createPDB(StringRef Path, SymbolTable *Symtab, InfoBuilder.setVersion(pdb::PdbRaw_ImplVer::PdbImplVC70); // Add an empty DPI stream. - auto &DbiBuilder = Builder.getDbiBuilder(); + pdb::DbiStreamBuilder &DbiBuilder = Builder.getDbiBuilder(); DbiBuilder.setVersionHeader(pdb::PdbDbiV110); codeview::TypeTableBuilder TypeTable(BAlloc); codeview::TypeTableBuilder IDTable(BAlloc); - mergeDebugT(Symtab, Builder, TypeTable, IDTable); + addObjectsToPDB(Symtab, Builder, TypeTable, IDTable); // Add Section Contributions. - std::vector<pdb::SectionContrib> Contribs = - pdb::DbiStreamBuilder::createSectionContribs(getInputSections(Symtab)); - DbiBuilder.setSectionContribs(Contribs); + addSectionContribs(Symtab, DbiBuilder); // Add Section Map stream. ArrayRef<object::coff_section> Sections = { |