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];
91 template <
typename RelocHandlerFunction>
93 RelocHandlerFunction &&Func,
94 bool ProcessDebugSections =
false);
99 template <
typename ClassT,
typename RelocHandlerMethod>
101 RelocHandlerMethod &&Method,
102 bool ProcessDebugSections =
false) {
105 [Instance, Method](
const auto &Rel,
const auto &
Target,
auto &GS) {
106 return (Instance->*Method)(Rel,
Target, GS);
108 ProcessDebugSections);
114 struct ComdatExportRequest {
119 std::vector<std::optional<ComdatExportRequest>> PendingComdatExports;
123 struct WeakExternalRequest {
129 std::vector<WeakExternalRequest> WeakExternalRequests;
133 using SymbolSet = std::set<std::pair<orc::ExecutorAddrDiff, Symbol *>>;
134 std::vector<SymbolSet> SymbolSets;
136 Section &getCommonSection();
139 orc::SymbolStringPtr SymbolName,
140 object::COFFSymbolRef Symbol,
141 const object::coff_section *Section);
142 Expected<Symbol *> createAliasSymbol(orc::SymbolStringPtr SymbolName,
145 orc::SymbolStringPtr SymbolName,
146 object::COFFSymbolRef Symbol,
147 const object::coff_section *Section);
148 Expected<Symbol *> createCOMDATExportRequest(
150 const object::coff_aux_section_definition *Definition);
152 orc::SymbolStringPtr SymbolName,
153 object::COFFSymbolRef Symbol);
155 Error handleDirectiveSection(StringRef Str);
156 Error flushWeakAliasRequests();
157 Error handleAlternateNames();
158 Error calculateImplicitSizeOfSymbols();
160 static uint64_t getSectionAddress(
const object::COFFObjectFile &Obj,
161 const object::coff_section *Section);
162 static uint64_t getSectionSize(
const object::COFFObjectFile &Obj,
163 const object::coff_section *Section);
164 static bool isComdatSection(
const object::coff_section *Section);
165 static unsigned getPointerSize(
const object::COFFObjectFile &Obj);
167 static StringRef getDLLImportStubPrefix() {
return "__imp_"; }
168 static StringRef getDirectiveSectionName() {
return ".drectve"; }
170 const object::coff_section *Sec,
171 object::COFFSymbolRef
Sym);
173 const object::COFFObjectFile &Obj;
174 std::unique_ptr<LinkGraph> G;
175 COFFDirectiveParser DirectiveParser;
177 Section *CommonSection =
nullptr;
178 std::vector<Block *> GraphBlocks;
179 std::vector<Symbol *> GraphSymbols;
181 DenseMap<orc::SymbolStringPtr, orc::SymbolStringPtr> AlternateNames;
182 DenseMap<orc::SymbolStringPtr, Symbol *> ExternalSymbols;
183 DenseMap<orc::SymbolStringPtr, Symbol *> DefinedSymbols;
186template <
typename RelocHandlerFunction>
188 RelocHandlerFunction &&Func,
189 bool ProcessDebugSections) {
196 return Name.takeError();
199 if (*
Name ==
".voltbl")
206 return make_error<StringError>(
207 "Referencing a section that wasn't added to the graph: " + *
Name,
212 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.