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,
121 case ELF::R_386_PC32:
125 case ELF::R_386_PC16:
127 case ELF::R_386_GOT32:
129 case ELF::R_386_GOT32X:
132 case ELF::R_386_GOTPC:
134 case ELF::R_386_GOTOFF:
136 case ELF::R_386_PLT32:
140 return make_error<JITLinkError>(
141 "In " +
G->getName() +
": Unsupported x86 relocation type " +
145 Error addRelocations()
override {
150 for (
const auto &RelSect : Base::Sections) {
153 return make_error<StringError>(
154 "No SHT_RELA in valid x86 ELF object files",
157 if (
Error Err = Base::forEachRelRelocation(RelSect,
this,
158 &Self::addSingleRelocation))
170 auto ELFReloc = Rel.getType(
false);
176 uint32_t SymbolIndex = Rel.getSymbol(
false);
177 auto ObjSymbol = Base::Obj.getRelocationSymbol(Rel, Base::SymTabSec);
179 return ObjSymbol.takeError();
181 Symbol *GraphSymbol = Base::getGraphSymbol(SymbolIndex);
183 return make_error<StringError>(
184 formatv(
"Could not find symbol at given index, did you add it to "
185 "JITSymbolTable? index: {0}, shndx: {1} Size of table: {2}",
186 SymbolIndex, (*ObjSymbol)->st_shndx,
187 Base::GraphSymbols.size()),
192 return Kind.takeError();
228 BlockToFix.
addEdge(std::move(GE));
234 std::shared_ptr<orc::SymbolStringPool> SSP,
Triple TT,
238 x86::getEdgeKindName) {}
243 std::shared_ptr<orc::SymbolStringPool> SSP) {
245 dbgs() <<
"Building jitlink graph for new input "
251 return ELFObj.takeError();
253 auto Features = (*ELFObj)->getFeatures();
255 return Features.takeError();
258 "Only x86 (little endian) is supported for now");
260 auto &ELFObjFile = cast<object::ELFObjectFile<object::ELF32LE>>(**ELFObj);
263 ELFObjFile.getELFFile(), std::move(SSP),
264 (*ELFObj)->makeTriple(), std::move(*Features))
269 std::unique_ptr<JITLinkContext> Ctx) {
271 const Triple &TT =
G->getTargetTriple();
272 if (Ctx->shouldAddDefaultTargetPasses(TT)) {
273 if (
auto MarkLive = Ctx->getMarkLivePass(TT))
274 Config.PrePrunePasses.push_back(std::move(MarkLive));
279 Config.PostPrunePasses.push_back(buildTables_ELF_x86);
284 if (
auto Err = Ctx->modifyPassConfig(*
G,
Config))
285 return Ctx->notifyFailed(std::move(Err));
287 ELFJITLinker_x86::link(std::move(Ctx), std::move(
G), std::move(
Config));
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_UNLIKELY(EXPR)
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_x86(std::unique_ptr< JITLinkContext > Ctx, std::unique_ptr< LinkGraph > G, PassConfiguration PassConfig)
std::unique_ptr< LinkGraph > G
ELFLinkGraphBuilder_x86(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.
@ BranchPCRel32ToPtrJumpStubBypassable
A relaxable version of BranchPCRel32ToPtrJumpStub.
@ RequestGOTAndTransformToDelta32FromGOT
A GOT entry offset within GOT getter/constructor, transformed to Delta32FromGOT pointing at the GOT e...
@ Pointer16
A plain 16-bit pointer value relocation.
@ BranchPCRel32
A 32-bit PC-relative branch.
@ PCRel32
A 32-bit PC-relative relocation.
@ PCRel16
A 16-bit PC-relative relocation.
@ BranchPCRel32ToPtrJumpStub
A 32-bit PC-relative branch to a pointer jump stub.
@ Pointer32
A plain 32-bit pointer value relocation.
@ Delta32FromGOT
A 32-bit GOT delta.
LLVM_ABI const char * getEdgeKindName(Edge::Kind K)
Returns a string name for the given x86 edge.
LLVM_ABI Error optimizeGOTAndStubAccesses(LinkGraph &G)
Optimize the GOT and Stub relocations if the edge target address is in range.
Error applyFixup(LinkGraph &G, Block &B, const Edge &E, const Symbol *GOTSymbol)
Apply fixup expression for edge to block content.
Expected< std::unique_ptr< LinkGraph > > createLinkGraphFromELFObject_x86(MemoryBufferRef ObjectBuffer, std::shared_ptr< orc::SymbolStringPool > SSP)
Create a LinkGraph from an ELF/x86 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...
LLVM_ABI Error markAllSymbolsLive(LinkGraph &G)
Marks all symbols in a graph live.
void link_ELF_x86(std::unique_ptr< LinkGraph > G, std::unique_ptr< JITLinkContext > Ctx)
jit-link the given object buffer, which must be a ELF x86 relocatable object file.
LLVM_ABI 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...
LLVM_ABI StringRef getELFRelocationTypeName(uint32_t Machine, uint32_t Type)
ELFType< llvm::endianness::little, false > ELF32LE
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI 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)
LLVM_ABI 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.