13#ifndef LIB_EXECUTIONENGINE_JITLINK_COFFLINKGRAPHBUILDER_H
14#define LIB_EXECUTIONENGINE_JITLINK_COFFLINKGRAPHBUILDER_H
24#define DEBUG_TYPE "jitlink"
55 assert(!GraphSymbols[SymIndex] &&
"Duplicate symbol at index");
56 GraphSymbols[SymIndex] = &
Sym;
58 SymbolSets[SecIndex].insert({
Sym.getOffset(), &
Sym});
65 return GraphSymbols[SymIndex];
69 assert(!GraphBlocks[SecIndex] &&
"Duplicate section at index");
71 GraphBlocks[SecIndex] =
B;
78 return GraphBlocks[SecIndex];
90 template <
typename RelocHandlerFunction>
92 RelocHandlerFunction &&Func,
93 bool ProcessDebugSections =
false);
98 template <
typename ClassT,
typename RelocHandlerMethod>
100 RelocHandlerMethod &&Method,
101 bool ProcessDebugSections =
false) {
104 [Instance, Method](
const auto &Rel,
const auto &
Target,
auto &GS) {
105 return (Instance->*Method)(Rel,
Target, GS);
107 ProcessDebugSections);
113 struct ComdatExportRequest {
118 std::vector<std::optional<ComdatExportRequest>> PendingComdatExports;
122 struct WeakExternalRequest {
128 std::vector<WeakExternalRequest> WeakExternalRequests;
132 using SymbolSet = std::set<std::pair<orc::ExecutorAddrDiff, Symbol *>>;
133 std::vector<SymbolSet> SymbolSets;
135 Section &getCommonSection();
137 Symbol *createExternalSymbol(
COFFSymbolIndex SymIndex, StringRef SymbolName,
138 object::COFFSymbolRef Symbol,
139 const object::coff_section *Section);
140 Expected<Symbol *> createAliasSymbol(StringRef SymbolName,
Linkage L,
Scope S,
143 StringRef SymbolName,
144 object::COFFSymbolRef Symbol,
145 const object::coff_section *Section);
146 Expected<Symbol *> createCOMDATExportRequest(
148 const object::coff_aux_section_definition *Definition);
150 StringRef SymbolName,
151 object::COFFSymbolRef Symbol);
153 Error handleDirectiveSection(StringRef Str);
154 Error flushWeakAliasRequests();
155 Error handleAlternateNames();
156 Error calculateImplicitSizeOfSymbols();
158 static uint64_t getSectionAddress(
const object::COFFObjectFile &Obj,
159 const object::coff_section *Section);
160 static uint64_t getSectionSize(
const object::COFFObjectFile &Obj,
161 const object::coff_section *Section);
162 static bool isComdatSection(
const object::coff_section *Section);
163 static unsigned getPointerSize(
const object::COFFObjectFile &Obj);
165 static StringRef getDLLImportStubPrefix() {
return "__imp_"; }
166 static StringRef getDirectiveSectionName() {
return ".drectve"; }
168 const object::coff_section *Sec,
169 object::COFFSymbolRef
Sym);
171 const object::COFFObjectFile &Obj;
172 std::unique_ptr<LinkGraph> G;
173 COFFDirectiveParser DirectiveParser;
175 Section *CommonSection =
nullptr;
176 std::vector<Block *> GraphBlocks;
177 std::vector<Symbol *> GraphSymbols;
179 DenseMap<StringRef, StringRef> AlternateNames;
180 DenseMap<StringRef, Symbol *> ExternalSymbols;
181 DenseMap<StringRef, Symbol *> DefinedSymbols;
184template <
typename RelocHandlerFunction>
186 RelocHandlerFunction &&Func,
187 bool ProcessDebugSections) {
194 return Name.takeError();
197 if (*
Name ==
".voltbl")
204 return make_error<StringError>(
205 "Referencing a section that wasn't added to the graph: " + *
Name,
210 if (
Error Err = Func(R, RelSec, *BlockToFix))
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file defines the DenseMap class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
StringRef - Represent a constant reference to a string, i.e.
Manages the enabling and disabling of subtarget specific features.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
A range adaptor for a pair of iterators.
An Addressable with content and edges.
Expected< std::unique_ptr< LinkGraph > > buildGraph()
virtual Error addRelocations()=0
Error forEachRelocation(const object::SectionRef &RelSec, RelocHandlerFunction &&Func, bool ProcessDebugSections=false)
Traverse all matching relocation records in the given section.
Symbol * getGraphSymbol(COFFSymbolIndex SymIndex) const
Error forEachRelocation(const object::SectionRef &RelSec, ClassT *Instance, RelocHandlerMethod &&Method, bool ProcessDebugSections=false)
Traverse all matching relocation records in the given section.
object::COFFObjectFile::section_iterator_range sections() const
virtual ~COFFLinkGraphBuilder()
Block * getGraphBlock(COFFSectionIndex SecIndex) const
void setGraphSymbol(COFFSectionIndex SecIndex, COFFSymbolIndex SymIndex, Symbol &Sym)
void setGraphBlock(COFFSectionIndex SecIndex, Block *B)
LinkGraph & getGraph() const
const object::COFFObjectFile & getObject() const
const char *(*)(Edge::Kind) GetEdgeKindNameFunction
Expected< StringRef > getSectionName(DataRefImpl Sec) const override
const coff_section * getCOFFSection(const SectionRef &Section) const
section_iterator_range sections() const
This is a value type class that represents a single section in the list of sections in the object fil...
uint64_t getIndex() const
iterator_range< relocation_iterator > relocations() const
bool isReservedSectionNumber(int32_t SectionNumber)
Linkage
Describes symbol linkage. This can be used to resolve definition clashes.
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface o...
This is an optimization pass for GlobalISel generic memory operations.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.