1 //===- COFFLinkerContext.h --------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLD_COFF_COFFLINKERCONTEXT_H 10 #define LLD_COFF_COFFLINKERCONTEXT_H 11 12 #include "Chunks.h" 13 #include "Config.h" 14 #include "DebugTypes.h" 15 #include "Driver.h" 16 #include "InputFiles.h" 17 #include "SymbolTable.h" 18 #include "Writer.h" 19 #include "lld/Common/CommonLinkerContext.h" 20 #include "lld/Common/Timer.h" 21 22 namespace lld::coff { 23 24 class COFFLinkerContext : public CommonLinkerContext { 25 public: 26 COFFLinkerContext(); 27 COFFLinkerContext(const COFFLinkerContext &) = delete; 28 COFFLinkerContext &operator=(const COFFLinkerContext &) = delete; 29 ~COFFLinkerContext() = default; 30 31 LinkerDriver driver; 32 SymbolTable symtab; 33 COFFOptTable optTable; 34 35 // A hybrid ARM64EC symbol table on ARM64X target. 36 std::optional<SymbolTable> hybridSymtab; 37 38 // Pointer to the ARM64EC symbol table: either symtab for an ARM64EC target or 39 // hybridSymtab for an ARM64X target. 40 SymbolTable *symtabEC = nullptr; 41 42 // Returns the appropriate symbol table for the specified machine type. 43 SymbolTable &getSymtab(llvm::COFF::MachineTypes machine) { 44 if (hybridSymtab && (machine == ARM64EC || machine == AMD64)) 45 return *hybridSymtab; 46 return symtab; 47 } 48 49 // Invoke the specified callback for each symbol table. 50 void forEachSymtab(std::function<void(SymbolTable &symtab)> f) { 51 f(symtab); 52 if (hybridSymtab) 53 f(*hybridSymtab); 54 } 55 56 std::vector<ObjFile *> objFileInstances; 57 std::map<std::string, PDBInputFile *> pdbInputFileInstances; 58 std::vector<ImportFile *> importFileInstances; 59 60 MergeChunk *mergeChunkInstances[Log2MaxSectionAlignment + 1] = {}; 61 62 /// All sources of type information in the program. 63 std::vector<TpiSource *> tpiSourceList; 64 65 void addTpiSource(TpiSource *tpi) { tpiSourceList.push_back(tpi); } 66 67 std::map<llvm::codeview::GUID, TpiSource *> typeServerSourceMappings; 68 std::map<uint32_t, TpiSource *> precompSourceMappings; 69 70 /// List of all output sections. After output sections are finalized, this 71 /// can be indexed by getOutputSection. 72 std::vector<OutputSection *> outputSections; 73 74 OutputSection *getOutputSection(const Chunk *c) const { 75 return c->osidx == 0 ? nullptr : outputSections[c->osidx - 1]; 76 } 77 78 // Fake sections for parsing bitcode files. 79 FakeSection ltoTextSection; 80 FakeSection ltoDataSection; 81 FakeSectionChunk ltoTextSectionChunk; 82 FakeSectionChunk ltoDataSectionChunk; 83 84 // All timers used in the COFF linker. 85 Timer rootTimer; 86 Timer inputFileTimer; 87 Timer ltoTimer; 88 Timer gcTimer; 89 Timer icfTimer; 90 91 // Writer timers. 92 Timer codeLayoutTimer; 93 Timer outputCommitTimer; 94 Timer totalMapTimer; 95 Timer symbolGatherTimer; 96 Timer symbolStringsTimer; 97 Timer writeTimer; 98 99 // PDB timers. 100 Timer totalPdbLinkTimer; 101 Timer addObjectsTimer; 102 Timer typeMergingTimer; 103 Timer loadGHashTimer; 104 Timer mergeGHashTimer; 105 Timer symbolMergingTimer; 106 Timer publicsLayoutTimer; 107 Timer tpiStreamLayoutTimer; 108 Timer diskCommitTimer; 109 110 Configuration config; 111 112 DynamicRelocsChunk *dynamicRelocs = nullptr; 113 }; 114 115 } // namespace lld::coff 116 117 #endif 118