// Create .idata section for the DLL-imported symbol table. // The format of this section is inherently Windows-specific. // IdataContents class abstracted away the details for us, // so we just let it create chunks and add them to the section. void Writer::createImportTables() { if (Symtab->ImportFiles.empty()) return; // Initialize DLLOrder so that import entries are ordered in // the same order as in the command line. (That affects DLL // initialization order, and this ordering is MSVC-compatible.) for (ImportFile *File : Symtab->ImportFiles) { if (!File->Live) continue; std::string DLL = StringRef(File->DLLName).lower(); if (Config->DLLOrder.count(DLL) == 0) Config->DLLOrder[DLL] = Config->DLLOrder.size(); } OutputSection *Text = createSection(".text"); for (ImportFile *File : Symtab->ImportFiles) { if (!File->Live) continue; if (DefinedImportThunk *Thunk = File->ThunkSym) Text->addChunk(Thunk->getChunk()); if (Config->DelayLoads.count(StringRef(File->DLLName).lower())) { if (!File->ThunkSym) fatal("cannot delay-load " + toString(File) + " due to import of data: " + toString(*File->ImpSym)); DelayIdata.add(File->ImpSym); } else { Idata.add(File->ImpSym); } } if (!Idata.empty()) { OutputSection *Sec = createSection(".idata"); for (Chunk *C : Idata.getChunks()) Sec->addChunk(C); } if (!DelayIdata.empty()) { Defined *Helper = cast<Defined>(Config->DelayLoadHelper); DelayIdata.create(Helper); OutputSection *Sec = createSection(".didat"); for (Chunk *C : DelayIdata.getChunks()) Sec->addChunk(C); Sec = createSection(".data"); for (Chunk *C : DelayIdata.getDataChunks()) Sec->addChunk(C); Sec = createSection(".text"); for (Chunk *C : DelayIdata.getCodeChunks()) Sec->addChunk(C); } }
void Writer::createMiscChunks() { OutputSection *RData = createSection(".rdata"); // Create thunks for locally-dllimported symbols. if (!Symtab->LocalImportChunks.empty()) { for (Chunk *C : Symtab->LocalImportChunks) RData->addChunk(C); } // Create Debug Information Chunks if (Config->Debug) { DebugDirectory = make<DebugDirectoryChunk>(DebugRecords); // TODO(compnerd) create a coffgrp entry if DebugType::CV is not enabled if (Config->DebugTypes & static_cast<unsigned>(coff::DebugType::CV)) { auto *Chunk = make<CVDebugRecordChunk>(); BuildId = Chunk; DebugRecords.push_back(Chunk); } RData->addChunk(DebugDirectory); for (Chunk *C : DebugRecords) RData->addChunk(C); } // Create SEH table. x86-only. if (Config->Machine != I386) return; std::set<Defined *> Handlers; for (lld::coff::ObjectFile *File : Symtab->ObjectFiles) { if (!File->SEHCompat) return; for (SymbolBody *B : File->SEHandlers) { // Make sure the handler is still live. Assume all handlers are regular // symbols. auto *D = dyn_cast<DefinedRegular>(B); if (D && D->getChunk()->isLive()) Handlers.insert(D); } } if (!Handlers.empty()) { SEHTable = make<SEHTableChunk>(Handlers); RData->addChunk(SEHTable); } }
void Writer::createExportTable() { if (Config->Exports.empty()) return; OutputSection *Sec = createSection(".edata"); for (std::unique_ptr<Chunk> &C : Edata.Chunks) Sec->addChunk(C.get()); }
void Writer::createExportTable() { if (Config->Exports.empty()) return; OutputSection *Sec = createSection(".edata"); for (Chunk *C : Edata.Chunks) Sec->addChunk(C); }
void Writer::createMiscChunks() { // Create thunks for locally-dllimported symbols. if (!Symtab->LocalImportChunks.empty()) { OutputSection *Sec = createSection(".rdata"); for (Chunk *C : Symtab->LocalImportChunks) Sec->addChunk(C); } // Create SEH table. x86-only. if (Config->Machine != I386) return; std::set<Defined *> Handlers; for (lld::coff::ObjectFile *File : Symtab->ObjectFiles) { if (!File->SEHCompat) return; for (SymbolBody *B : File->SEHandlers) Handlers.insert(cast<Defined>(B->repl())); } SEHTable.reset(new SEHTableChunk(Handlers)); createSection(".rdata")->addChunk(SEHTable.get()); }