22#define DEBUG_TYPE "jitlink"
37class COFFJITLinker_x86_64 :
public JITLinker<COFFJITLinker_x86_64> {
38 friend class JITLinker<COFFJITLinker_x86_64>;
41 COFFJITLinker_x86_64(std::unique_ptr<JITLinkContext> Ctx,
42 std::unique_ptr<LinkGraph>
G,
44 :
JITLinker(std::move(Ctx), std::move(
G), std::move(PassConfig)) {}
57 for (
const auto &RelSect :
sections())
59 RelSect,
this, &COFFLinkGraphBuilder_x86_64::addSingleRelocation))
70 if (SymbolIt ==
getObject().symbol_end()) {
71 return make_error<StringError>(
72 formatv(
"Invalid symbol index in relocation entry. "
73 "index: {0}, section: {1}",
83 return make_error<StringError>(
84 formatv(
"Could not find symbol at given index, did you add it to "
85 "JITSymbolTable? index: {0}, section: {1}",
102 Kind = EdgeKind_coff_x86_64::Pointer32NB;
107 Kind = EdgeKind_coff_x86_64::PCRel32;
112 Kind = EdgeKind_coff_x86_64::PCRel32;
118 Kind = EdgeKind_coff_x86_64::PCRel32;
124 Kind = EdgeKind_coff_x86_64::PCRel32;
130 Kind = EdgeKind_coff_x86_64::PCRel32;
136 Kind = EdgeKind_coff_x86_64::PCRel32;
142 Kind = EdgeKind_coff_x86_64::Pointer64;
147 Kind = EdgeKind_coff_x86_64::SectionIdx16;
157 Scope::Local,
false);
158 GraphSymbol = AbsSym;
165 Kind = EdgeKind_coff_x86_64::SecRel32;
170 return make_error<JITLinkError>(
"Unsupported x86_64 relocation:" +
182 BlockToFix.
addEdge(std::move(GE));
189 std::shared_ptr<orc::SymbolStringPool> SSP,
196class COFFLinkGraphLowering_x86_64 {
200 for (
auto *
B :
G.blocks()) {
201 for (
auto &E :
B->edges()) {
202 switch (E.getKind()) {
203 case EdgeKind_coff_x86_64::Pointer32NB: {
204 auto ImageBase = GetImageBase(
G);
205 assert(ImageBase &&
"__ImageBase symbol must be defined");
206 E.setAddend(E.getAddend() - ImageBase->getAddress().getValue());
210 case EdgeKind_coff_x86_64::PCRel32: {
214 case EdgeKind_coff_x86_64::Pointer64: {
218 case EdgeKind_coff_x86_64::SectionIdx16: {
222 case EdgeKind_coff_x86_64::SecRel32: {
223 E.setAddend(E.getAddend() -
224 getSectionStart(E.getTarget().getBlock().getSection())
239 if (!SectionStartCache.count(&Sec)) {
241 SectionStartCache[&Sec] =
Range.getStart();
242 return Range.getStart();
244 return SectionStartCache[&Sec];
261 return "Pointer32NB";
265 return "SectionIdx16";
274 MemoryBufferRef ObjectBuffer, std::shared_ptr<orc::SymbolStringPool> SSP) {
276 dbgs() <<
"Building jitlink graph for new input "
282 return COFFObj.takeError();
284 auto Features = (*COFFObj)->getFeatures();
286 return Features.takeError();
288 return COFFLinkGraphBuilder_x86_64(**COFFObj, std::move(SSP),
289 (*COFFObj)->makeTriple(),
290 std::move(*Features))
295 std::unique_ptr<JITLinkContext> Ctx) {
297 const Triple &TT =
G->getTargetTriple();
298 if (Ctx->shouldAddDefaultTargetPasses(TT)) {
300 if (
auto MarkLive = Ctx->getMarkLivePass(TT)) {
301 Config.PrePrunePasses.push_back(std::move(MarkLive));
307 Config.PreFixupPasses.push_back(COFFLinkGraphLowering_x86_64());
310 if (
auto Err = Ctx->modifyPassConfig(*
G,
Config))
311 return Ctx->notifyFailed(std::move(Err));
313 COFFJITLinker_x86_64::link(std::move(Ctx), std::move(
G), std::move(
Config));
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
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 getBufferIdentifier() const
Manages the enabling and disabling of subtarget specific features.
Triple - Helper class for working with autoconf configuration names.
orc::ExecutorAddr getAddress() const
An Addressable with content and edges.
ArrayRef< char > getContent() const
Get the content for this block. Block must not be a zero-fill block.
void addEdge(Edge::Kind K, Edge::OffsetT Offset, Symbol &Target, Edge::AddendT Addend)
Add an edge to this block.
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
object::COFFObjectFile::section_iterator_range sections() const
LinkGraph & getGraph() const
Symbol & addImageBaseSymbol(StringRef Name="__ImageBase")
const object::COFFObjectFile & getObject() const
Represents fixups and constraints in the LinkGraph.
Symbol & addAbsoluteSymbol(orc::SymbolStringPtr Name, orc::ExecutorAddr Address, orc::ExecutorAddrDiff Size, Linkage L, Scope S, bool IsLive)
Add an absolute symbol.
This pass adds keep-alive edge from SEH frame sections to the parent function content block.
Represents a section address range via a pair of Block pointers to the first and last Blocks in the s...
Represents an object file section.
bool isDefined() const
Returns true if this Symbol has content (potentially) defined within this object file (i....
const coff_relocation * getCOFFRelocation(const RelocationRef &Reloc) const
uint32_t getNumberOfSections() const
uint32_t getSymbolIndex(COFFSymbolRef Symbol) const
COFFSymbolRef getCOFFSymbol(const DataRefImpl &Ref) const
int32_t getSectionNumber() const
static Expected< std::unique_ptr< COFFObjectFile > > createCOFFObjectFile(MemoryBufferRef Object)
This is a value type class that represents a single relocation in the list of relocations in the obje...
uint64_t getOffset() const
symbol_iterator getSymbol() 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
uint64_t getAddress() const
Represents an address in the executor process.
@ IMAGE_REL_AMD64_REL32_5
@ IMAGE_REL_AMD64_REL32_3
@ IMAGE_REL_AMD64_ADDR32NB
@ IMAGE_REL_AMD64_SECTION
@ IMAGE_REL_AMD64_REL32_2
@ IMAGE_REL_AMD64_REL32_1
@ IMAGE_REL_AMD64_REL32_4
const char * getEdgeKindName(Edge::Kind K)
Returns a string name for the given x86-64 edge.
Error applyFixup(LinkGraph &G, Block &B, const Edge &E, const Symbol *GOTSymbol)
Apply fixup expression for edge to block content.
@ Pointer32
A plain 32-bit pointer value relocation.
@ PCRel32
A 32-bit PC-relative relocation.
@ Pointer16
A plain 16-bit pointer value relocation.
@ Pointer64
A plain 64-bit pointer value relocation.
@ FirstPlatformRelocation
Expected< std::unique_ptr< LinkGraph > > createLinkGraphFromCOFFObject_x86_64(MemoryBufferRef ObjectBuffer, std::shared_ptr< orc::SymbolStringPool > SSP)
Create a LinkGraph from an COFF/x86-64 relocatable object.
Error markAllSymbolsLive(LinkGraph &G)
Marks all symbols in a graph live.
void link_COFF_x86_64(std::unique_ptr< LinkGraph > G, std::unique_ptr< JITLinkContext > Ctx)
jit-link the given object buffer, which must be a COFF x86-64 object file.
void printEdge(raw_ostream &OS, const Block &B, const Edge &E, StringRef EdgeKindName)
const char * getCOFFX86RelocationKindName(Edge::Kind R)
Return the string name of the given COFF x86-64 edge kind.
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...
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
An LinkGraph pass configuration, consisting of a list of pre-prune, post-prune, and post-fixup passes...
support::ulittle32_t SymbolTableIndex