21#define DEBUG_TYPE "jitlink"
27constexpr StringRef ELFGOTSymbolName =
"_GLOBAL_OFFSET_TABLE_";
49 [
this](
LinkGraph &
G) {
return getOrCreateGOTSymbol(
G); });
53 Symbol *GOTSymbol =
nullptr;
56 auto DefineExternalGOTSymbolIfPresent =
61 if (
auto *GOTSection =
G.findSectionByName(
64 return {*GOTSection, true};
71 if (
auto Err = DefineExternalGOTSymbolIfPresent(
G))
81 if (
auto *GOTSection =
85 for (
auto *
Sym : GOTSection->symbols())
100 &
G.addDefinedSymbol(*SR.getFirstBlock(), 0, ELFGOTSymbolName, 0,
113template <
typename ELFT>
117 using namespace i386;
119 case ELF::R_386_NONE:
120 return EdgeKind_i386::None;
122 return EdgeKind_i386::Pointer32;
123 case ELF::R_386_PC32:
124 return EdgeKind_i386::PCRel32;
126 return EdgeKind_i386::Pointer16;
127 case ELF::R_386_PC16:
128 return EdgeKind_i386::PCRel16;
129 case ELF::R_386_GOT32:
130 return EdgeKind_i386::RequestGOTAndTransformToDelta32FromGOT;
131 case ELF::R_386_GOTPC:
132 return EdgeKind_i386::Delta32;
133 case ELF::R_386_GOTOFF:
134 return EdgeKind_i386::Delta32FromGOT;
135 case ELF::R_386_PLT32:
136 return EdgeKind_i386::BranchPCRel32;
139 return make_error<JITLinkError>(
"Unsupported i386 relocation:" +
143 Error addRelocations()
override {
148 for (
const auto &RelSect : Base::Sections) {
151 return make_error<StringError>(
152 "No SHT_RELA in valid i386 ELF object files",
155 if (
Error Err = Base::forEachRelRelocation(RelSect,
this,
156 &Self::addSingleRelocation))
163 Error addSingleRelocation(
const typename ELFT::Rel &Rel,
164 const typename ELFT::Shdr &FixupSection,
168 uint32_t SymbolIndex = Rel.getSymbol(
false);
169 auto ObjSymbol = Base::Obj.getRelocationSymbol(Rel, Base::SymTabSec);
171 return ObjSymbol.takeError();
173 Symbol *GraphSymbol = Base::getGraphSymbol(SymbolIndex);
175 return make_error<StringError>(
176 formatv(
"Could not find symbol at given index, did you add it to "
177 "JITSymbolTable? index: {0}, shndx: {1} Size of table: {2}",
178 SymbolIndex, (*ObjSymbol)->st_shndx,
179 Base::GraphSymbols.size()),
184 return Kind.takeError();
222 BlockToFix.
addEdge(std::move(GE));
228 std::shared_ptr<orc::SymbolStringPool> SSP,
232 i386::getEdgeKindName) {}
237 std::shared_ptr<orc::SymbolStringPool> SSP) {
239 dbgs() <<
"Building jitlink graph for new input "
245 return ELFObj.takeError();
247 auto Features = (*ELFObj)->getFeatures();
249 return Features.takeError();
252 "Only i386 (little endian) is supported for now");
254 auto &ELFObjFile = cast<object::ELFObjectFile<object::ELF32LE>>(**ELFObj);
257 (*ELFObj)->getFileName(), ELFObjFile.getELFFile(), std::move(SSP),
258 (*ELFObj)->makeTriple(), std::move(*Features))
263 std::unique_ptr<JITLinkContext> Ctx) {
265 const Triple &TT =
G->getTargetTriple();
266 if (Ctx->shouldAddDefaultTargetPasses(TT)) {
267 if (
auto MarkLive = Ctx->getMarkLivePass(TT))
268 Config.PrePrunePasses.push_back(std::move(MarkLive));
273 Config.PostPrunePasses.push_back(buildTables_ELF_i386);
278 if (
auto Err = Ctx->modifyPassConfig(*
G,
Config))
279 return Ctx->notifyFailed(std::move(Err));
281 ELFJITLinker_i386::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")
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
StringRef - Represent a constant reference to a string, i.e.
Manages the enabling and disabling of subtarget specific features.
Triple - Helper class for working with autoconf configuration names.
The instances of the Type class are immutable: once they are created, they are never changed.
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.
ELFJITLinker_i386(std::unique_ptr< JITLinkContext > Ctx, std::unique_ptr< LinkGraph > G, PassConfiguration PassConfig)
ELFLinkGraphBuilder_i386(StringRef FileName, const object::ELFFile< ELFT > &Obj, std::shared_ptr< orc::SymbolStringPool > SSP, Triple TT, SubtargetFeatures Features)
LinkGraph building code that's specific to the given ELFT, but common across all architectures.
Expected< std::unique_ptr< LinkGraph > > buildGraph()
Attempt to construct and return the LinkGraph.
Represents fixups and constraints in the LinkGraph.
PassConfiguration & getPassConfig()
Represents a section address range via a pair of Block pointers to the first and last Blocks in the s...
const orc::SymbolStringPtr & getName() const
Returns the name of this symbol (empty if the symbol is anonymous).
Global Offset Table Builder.
static StringRef getSectionName()
Procedure Linkage Table Builder.
static Expected< std::unique_ptr< ObjectFile > > createELFObjectFile(MemoryBufferRef Object, bool InitContent=true)
Represents an address in the executor process.
Error applyFixup(LinkGraph &G, Block &B, const Edge &E, const ArmConfig &ArmCfg)
Apply fixup expression for edge to block content.
Error applyFixup(LinkGraph &G, Block &B, const Edge &E, const Symbol *GOTSymbol)
Apply fixup expression for edge to block content.
Error optimizeGOTAndStubAccesses(LinkGraph &G)
Optimize the GOT and Stub relocations if the edge target address is in range.
@ BranchPCRel32ToPtrJumpStubBypassable
A relaxable version of BranchPCRel32ToPtrJumpStub.
@ Delta32FromGOT
A 32-bit GOT delta.
@ PCRel32
A 32-bit PC-relative relocation.
@ BranchPCRel32ToPtrJumpStub
A 32-bit PC-relative branch to a pointer jump stub.
@ PCRel16
A 16-bit PC-relative relocation.
@ RequestGOTAndTransformToDelta32FromGOT
A GOT entry offset within GOT getter/constructor, transformed to Delta32FromGOT pointing at the GOT e...
@ BranchPCRel32
A 32-bit PC-relative branch.
@ Pointer32
A plain 32-bit pointer value relocation.
@ Pointer16
A plain 16-bit pointer value relocation.
const char * getEdgeKindName(Edge::Kind K)
Returns a string name for the given i386 edge.
Expected< std::unique_ptr< LinkGraph > > createLinkGraphFromELFObject_i386(MemoryBufferRef ObjectBuffer, std::shared_ptr< orc::SymbolStringPool > SSP)
Create a LinkGraph from an ELF/i386 relocatable object.
void visitExistingEdges(LinkGraph &G, VisitorTs &&...Vs)
For each edge in the given graph, apply a list of visitors to the edge, stopping when the first visit...
Error markAllSymbolsLive(LinkGraph &G)
Marks all symbols in a graph live.
void link_ELF_i386(std::unique_ptr< LinkGraph > G, std::unique_ptr< JITLinkContext > Ctx)
jit-link the given object buffer, which must be a ELF i386 relocatable object file.
void printEdge(raw_ostream &OS, const Block &B, const Edge &E, StringRef EdgeKindName)
DefineExternalSectionStartAndEndSymbols< SymbolIdentifierFunction > createDefineExternalSectionStartAndEndSymbolsPass(SymbolIdentifierFunction &&F)
Returns a JITLink pass (as a function class) that uses the given symbol identification function to id...
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.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.
An LinkGraph pass configuration, consisting of a list of pre-prune, post-prune, and post-fixup passes...
LinkGraphPassList PostAllocationPasses
Post-allocation passes.