13#ifndef LIB_EXECUTIONENGINE_JITLINK_COFFLINKGRAPHBUILDER_H
14#define LIB_EXECUTIONENGINE_JITLINK_COFFLINKGRAPHBUILDER_H
24#define DEBUG_TYPE "jitlink"
41 std::shared_ptr<orc::SymbolStringPool> SSP,
Triple TT,
56 assert(!GraphSymbols[SymIndex] &&
"Duplicate symbol at index");
57 GraphSymbols[SymIndex] = &
Sym;
59 SymbolSets[SecIndex].insert({
Sym.getOffset(), &
Sym});
66 return GraphSymbols[SymIndex];
70 assert(!GraphBlocks[SecIndex] &&
"Duplicate section at index");
72 GraphBlocks[SecIndex] =
B;
79 return GraphBlocks[SecIndex];
83 auto &ImageBase = G->addExternalSymbol(G->intern(
Name), 0,
true);
84 ImageBase.setLive(
true);
97 template <
typename RelocHandlerFunction>
99 RelocHandlerFunction &&Func,
100 bool ProcessDebugSections =
false);
105 template <
typename ClassT,
typename RelocHandlerMethod>
107 RelocHandlerMethod &&Method,
108 bool ProcessDebugSections =
false) {
111 [Instance, Method](
const auto &Rel,
const auto &
Target,
auto &GS) {
112 return (Instance->*Method)(Rel,
Target, GS);
114 ProcessDebugSections);
120 struct ComdatExportRequest {
125 std::vector<std::optional<ComdatExportRequest>> PendingComdatExports;
129 struct WeakExternalRequest {
135 std::vector<WeakExternalRequest> WeakExternalRequests;
139 using SymbolSet = std::set<std::pair<orc::ExecutorAddrDiff, Symbol *>>;
140 std::vector<SymbolSet> SymbolSets;
142 Section &getCommonSection();
145 orc::SymbolStringPtr SymbolName,
146 object::COFFSymbolRef Symbol,
147 const object::coff_section *Section);
148 Expected<Symbol *> createAliasSymbol(orc::SymbolStringPtr SymbolName,
151 orc::SymbolStringPtr SymbolName,
152 object::COFFSymbolRef Symbol,
153 const object::coff_section *Section);
154 Expected<Symbol *> createCOMDATExportRequest(
156 const object::coff_aux_section_definition *Definition);
158 orc::SymbolStringPtr SymbolName,
159 object::COFFSymbolRef Symbol);
161 Error handleDirectiveSection(StringRef Str);
162 Error flushWeakAliasRequests();
163 Error handleAlternateNames();
164 Error calculateImplicitSizeOfSymbols();
166 static uint64_t getSectionAddress(
const object::COFFObjectFile &Obj,
167 const object::coff_section *Section);
168 static uint64_t getSectionSize(
const object::COFFObjectFile &Obj,
169 const object::coff_section *Section);
170 static bool isComdatSection(
const object::coff_section *Section);
171 static unsigned getPointerSize(
const object::COFFObjectFile &Obj);
173 static StringRef getDLLImportStubPrefix() {
return "__imp_"; }
174 static StringRef getDirectiveSectionName() {
return ".drectve"; }
176 const object::coff_section *Sec,
177 object::COFFSymbolRef
Sym);
179 const object::COFFObjectFile &Obj;
180 std::unique_ptr<LinkGraph> G;
181 COFFDirectiveParser DirectiveParser;
183 Section *CommonSection =
nullptr;
184 std::vector<Block *> GraphBlocks;
185 std::vector<Symbol *> GraphSymbols;
187 DenseMap<orc::SymbolStringPtr, orc::SymbolStringPtr> AlternateNames;
188 DenseMap<orc::SymbolStringPtr, Symbol *> ExternalSymbols;
189 DenseMap<orc::SymbolStringPtr, Symbol *> DefinedSymbols;
192template <
typename RelocHandlerFunction>
194 RelocHandlerFunction &&Func,
195 bool ProcessDebugSections) {
202 return Name.takeError();
205 if (*
Name ==
".voltbl")
212 return make_error<StringError>(
213 "Referencing a section that wasn't added to the graph: " + *
Name,
218 if (
Error Err = Func(R, RelSec, *BlockToFix))
228 : ImageBaseName(ImageBaseName) {}
230 void reset() { ImageBase = std::nullopt; }
234 std::optional<Symbol *> ImageBase;
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
Symbol & addImageBaseSymbol(StringRef Name="__ImageBase")
const object::COFFObjectFile & getObject() const
GetImageBaseSymbol(StringRef ImageBaseName="__ImageBase")
Symbol * operator()(LinkGraph &G)
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.