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 native ARM64 symbol table on ARM64X target. |
36 | std::optional<SymbolTable> hybridSymtab; |
37 | |
38 | // Returns the appropriate symbol table for the specified machine type. |
39 | SymbolTable &getSymtab(llvm::COFF::MachineTypes machine) { |
40 | if (hybridSymtab && machine == ARM64) |
41 | return *hybridSymtab; |
42 | return symtab; |
43 | } |
44 | |
45 | // Invoke the specified callback for each symbol table. |
46 | void forEachSymtab(std::function<void(SymbolTable &symtab)> f) { |
47 | // If present, process the native symbol table first. |
48 | if (hybridSymtab) |
49 | f(*hybridSymtab); |
50 | f(symtab); |
51 | } |
52 | |
53 | // Invoke the specified callback for each active symbol table, |
54 | // skipping the native symbol table on pure ARM64EC targets. |
55 | void forEachActiveSymtab(std::function<void(SymbolTable &symtab)> f) { |
56 | if (symtab.ctx.config.machine == ARM64X) |
57 | f(*hybridSymtab); |
58 | f(symtab); |
59 | } |
60 | |
61 | std::vector<ObjFile *> objFileInstances; |
62 | std::map<std::string, PDBInputFile *> pdbInputFileInstances; |
63 | std::vector<ImportFile *> importFileInstances; |
64 | |
65 | MergeChunk *mergeChunkInstances[Log2MaxSectionAlignment + 1] = {}; |
66 | |
67 | /// All sources of type information in the program. |
68 | std::vector<TpiSource *> tpiSourceList; |
69 | |
70 | void addTpiSource(TpiSource *tpi) { tpiSourceList.push_back(x: tpi); } |
71 | |
72 | std::map<llvm::codeview::GUID, TpiSource *> typeServerSourceMappings; |
73 | std::map<uint32_t, TpiSource *> precompSourceMappings; |
74 | |
75 | /// List of all output sections. After output sections are finalized, this |
76 | /// can be indexed by getOutputSection. |
77 | std::vector<OutputSection *> outputSections; |
78 | |
79 | OutputSection *getOutputSection(const Chunk *c) const { |
80 | return c->osidx == 0 ? nullptr : outputSections[c->osidx - 1]; |
81 | } |
82 | |
83 | // Fake sections for parsing bitcode files. |
84 | FakeSection ltoTextSection; |
85 | FakeSection ltoDataSection; |
86 | FakeSectionChunk ltoTextSectionChunk; |
87 | FakeSectionChunk ltoDataSectionChunk; |
88 | |
89 | // All timers used in the COFF linker. |
90 | Timer rootTimer; |
91 | Timer inputFileTimer; |
92 | Timer ltoTimer; |
93 | Timer gcTimer; |
94 | Timer icfTimer; |
95 | |
96 | // Writer timers. |
97 | Timer codeLayoutTimer; |
98 | Timer outputCommitTimer; |
99 | Timer totalMapTimer; |
100 | Timer symbolGatherTimer; |
101 | Timer symbolStringsTimer; |
102 | Timer writeTimer; |
103 | |
104 | // PDB timers. |
105 | Timer totalPdbLinkTimer; |
106 | Timer addObjectsTimer; |
107 | Timer typeMergingTimer; |
108 | Timer loadGHashTimer; |
109 | Timer mergeGHashTimer; |
110 | Timer symbolMergingTimer; |
111 | Timer publicsLayoutTimer; |
112 | Timer tpiStreamLayoutTimer; |
113 | Timer diskCommitTimer; |
114 | |
115 | Configuration config; |
116 | |
117 | DynamicRelocsChunk *dynamicRelocs = nullptr; |
118 | }; |
119 | |
120 | } // namespace lld::coff |
121 | |
122 | #endif |
123 | |