22#define DEBUG_TYPE "jitlink"
29constexpr StringRef ELFGOTSymbolName =
"_GLOBAL_OFFSET_TABLE_";
30constexpr StringRef ELFTLSInfoSectionName =
"$__TLSINFO";
33class TLSInfoTableManager_ELF_systemz
38 static const uint8_t TLSInfoEntryContent[16];
44 dbgs() <<
" Fixing " <<
G.getEdgeKindName(
E.getKind()) <<
" edge at "
45 <<
formatv(
"{0:x}",
B->getFixupAddress(
E)) <<
" ("
46 <<
formatv(
"{0:x}",
B->getAddress()) <<
" + "
47 <<
formatv(
"{0:x}",
E.getOffset()) <<
")\n";
50 E.setTarget(getEntryForTarget(
G,
E.getTarget()));
59 auto &TLSInfoEntry =
G.createMutableContentBlock(
60 getTLSInfoSection(
G),
G.allocateContent(getTLSInfoEntryContent()),
63 return G.addAnonymousSymbol(TLSInfoEntry, 0, 16,
false,
false);
74 return {
reinterpret_cast<const char *
>(TLSInfoEntryContent),
75 sizeof(TLSInfoEntryContent)};
78 Section *TLSInfoTable =
nullptr;
81const uint8_t TLSInfoTableManager_ELF_systemz::TLSInfoEntryContent[16] = {
82 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
83 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
89 TLSInfoTableManager_ELF_systemz TLSInfo;
103 std::unique_ptr<LinkGraph> G,
108 [
this](
LinkGraph &G) { return getOrCreateGOTSymbol(G); });
112 Symbol *GOTSymbol =
nullptr;
119 auto DefineExternalGOTSymbolIfPresent =
122 if (Sym.
getName() !=
nullptr &&
123 *Sym.
getName() == ELFGOTSymbolName)
124 if (
auto *GOTSection =
G.findSectionByName(
127 return {*GOTSection,
true};
134 if (
auto Err = DefineExternalGOTSymbolIfPresent(G))
144 if (
auto *GOTSection =
148 for (
auto *Sym : GOTSection->symbols())
149 if (Sym->
getName() !=
nullptr && *Sym->
getName() == ELFGOTSymbolName) {
155 SectionRange SR(*GOTSection);
158 &G.addAbsoluteSymbol(ELFGOTSymbolName, orc::ExecutorAddr(), 0,
162 &G.addDefinedSymbol(*SR.getFirstBlock(), 0, ELFGOTSymbolName, 0,
170 for (
auto *Sym : G.external_symbols()) {
171 if (Sym->
getName() !=
nullptr && *Sym->
getName() == ELFGOTSymbolName) {
172 auto Blocks = G.blocks();
173 if (!Blocks.empty()) {
174 G.makeAbsolute(*Sym, (*Blocks.begin())->getAddress());
202 G->getTargetTriple().getArchName() +
207 &Self::addSingleRelocation))
219 auto ELFReloc = Rel.getType(
false);
225 uint32_t SymbolIndex = Rel.getSymbol(
false);
228 return ObjSymbol.takeError();
233 formatv(
"Could not find symbol at given index, did you add it to "
234 "JITSymbolTable? index: {0}, shndx: {1} Size of table: {2}",
235 SymbolIndex, (*ObjSymbol)->st_shndx,
240 int64_t Addend = Rel.r_addend;
241 Edge::Kind Kind = Edge::Invalid;
244 case ELF::R_390_PC64: {
248 case ELF::R_390_PC32: {
252 case ELF::R_390_PC16: {
256 case ELF::R_390_PC32DBL: {
260 case ELF::R_390_PC24DBL: {
264 case ELF::R_390_PC16DBL: {
268 case ELF::R_390_PC12DBL: {
272 case ELF::R_390_64: {
276 case ELF::R_390_32: {
280 case ELF::R_390_20: {
284 case ELF::R_390_16: {
288 case ELF::R_390_12: {
297 case ELF::R_390_PLT64: {
301 case ELF::R_390_PLT32: {
305 case ELF::R_390_PLT32DBL: {
309 case ELF::R_390_PLT24DBL: {
313 case ELF::R_390_PLT16DBL: {
317 case ELF::R_390_PLT12DBL: {
321 case ELF::R_390_PLTOFF64: {
325 case ELF::R_390_PLTOFF32: {
329 case ELF::R_390_PLTOFF16: {
334 case ELF::R_390_GOTOFF64: {
338 case ELF::R_390_GOTOFF: {
342 case ELF::R_390_GOTOFF16: {
347 case ELF::R_390_GOT64:
348 case ELF::R_390_GOTPLT64: {
352 case ELF::R_390_GOT32:
353 case ELF::R_390_GOTPLT32: {
357 case ELF::R_390_GOT20:
358 case ELF::R_390_GOTPLT20: {
362 case ELF::R_390_GOT16:
363 case ELF::R_390_GOTPLT16: {
367 case ELF::R_390_GOT12:
368 case ELF::R_390_GOTPLT12: {
372 case ELF::R_390_GOTENT:
373 case ELF::R_390_GOTPLTENT: {
379 case ELF::R_390_GOTPC: {
383 case ELF::R_390_GOTPCDBL: {
388 case ELF::R_390_TLS_GDCALL: {
392 case ELF::R_390_TLS_GD64: {
398 "In " +
G->getName() +
": Unsupported systemz relocation type " +
410 BlockToFix.
addEdge(std::move(GE));
418 std::shared_ptr<orc::SymbolStringPool> SSP,
426 MemoryBufferRef ObjectBuffer, std::shared_ptr<orc::SymbolStringPool> SSP) {
428 dbgs() <<
"Building jitlink graph for new input "
434 return ELFObj.takeError();
436 auto Features = (*ELFObj)->getFeatures();
438 return Features.takeError();
441 "Only SystemZ is supported");
445 (*ELFObj)->getFileName(), ELFObjFile.getELFFile(), std::move(SSP),
446 (*ELFObj)->makeTriple(), std::move(*Features))
451 std::unique_ptr<JITLinkContext> Ctx) {
453 const Triple &TT = G->getTargetTriple();
454 if (Ctx->shouldAddDefaultTargetPasses(TT)) {
464 if (
auto MarkLive = Ctx->getMarkLivePass(TT))
481 if (
auto Err = Ctx->modifyPassConfig(*G, Config))
482 return Ctx->notifyFailed(std::move(Err));
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_UNLIKELY(EXPR)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
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.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
orc::ExecutorAddr getAddress() const
An Addressable with content and edges.
void addEdge(Edge::Kind K, Edge::OffsetT Offset, Symbol &Target, Edge::AddendT Addend)
Add an edge to this block.
A LinkGraph pass that splits blocks in a section that follows the DWARF Record format into sub-blocks...
A LinkGraph pass that adds missing FDE-to-CIE, FDE-to-PC and FDE-to-LSDA edges.
ELFJITLinker_systemz(std::unique_ptr< JITLinkContext > Ctx, std::unique_ptr< LinkGraph > G, PassConfiguration PassConfig)
std::unique_ptr< LinkGraph > G
ELFLinkGraphBuilder_systemz(StringRef FileName, const object::ELFFile< ELFT > &Obj, std::shared_ptr< orc::SymbolStringPool > SSP, Triple TT, SubtargetFeatures Features)
const ELFFile::Elf_Shdr * SymTabSec
virtual Error addRelocations()=0
ELFLinkGraphBuilder(const object::ELFFile< object::ELF64BE > &Obj, std::shared_ptr< orc::SymbolStringPool > SSP, Triple TT, SubtargetFeatures Features, StringRef FileName, LinkGraph::GetEdgeKindNameFunction GetEdgeKindName)
Expected< std::unique_ptr< LinkGraph > > buildGraph()
Attempt to construct and return the LinkGraph.
DenseMap< ELFSymbolIndex, Symbol * > GraphSymbols
ELFFile::Elf_Shdr_Range Sections
Error forEachRelaRelocation(const typename ELFT::Shdr &RelSect, RelocHandlerMethod &&Func)
Traverse all matching ELFT::Rela relocation records in the given section.
Symbol * getGraphSymbol(ELFSymbolIndex SymIndex)
Represents fixups and constraints in the LinkGraph.
PassConfiguration & getPassConfig()
bool shouldAddDefaultTargetPasses(const Triple &TT)
static void link(ArgTs &&... Args)
Represents an object file section.
const orc::SymbolStringPtr & getName() const
Returns the name of this symbol (empty if the symbol is anonymous).
A CRTP base for tables that are built on demand, e.g.
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.
static constexpr const StringLiteral & getSectionName(DebugSectionKind SectionKind)
Return the name of the section.
Error applyFixup(LinkGraph &G, Block &B, const Edge &E, const Symbol *GOTSymbol)
Apply fixup expression for edge to block content.
@ DeltaPLT32
A 32-bit Delta.
@ Delta64PLTFromGOT
A 64-bit offset from GOT to PLT.
@ Pointer16
A plain 16-bit pointer value relocation.
@ RequestGOTAndTransformToDelta32FromGOT
A GOT entry getter/constructor, transformed to Delta32FromGOT pointing at the GOT entry for the origi...
@ RequestGOTAndTransformToDelta32dbl
A GOT entry getter/constructor, transformed to Delta32dbl pointing at the GOT entry for the original ...
@ Pointer64
A plain 64-bit pointer value relocation.
@ Pointer20
A plain 20-bit pointer value relocation.
@ RequestGOTAndTransformToDelta16FromGOT
A GOT entry getter/constructor, transformed to Delta16FromGOT pointing at the GOT entry for the origi...
@ RequestGOTAndTransformToDelta12FromGOT
A GOT entry getter/constructor, transformed to Delta12FromGOT pointing at the GOT entry for the origi...
@ RequestGOTAndTransformToDelta64FromGOT
A GOT entry getter/constructor, transformed to Delta64FromGOT pointing at the GOT entry for the origi...
@ DeltaPLT16dbl
A 16-bit Delta shifted by 1.
@ Delta16FromGOT
A 16-bit offset from GOT.
@ Pointer8
A plain 8-bit pointer value relocation.
@ Delta16PLTFromGOT
A 16-bit offset from GOT to PLT.
@ Delta32PLTFromGOT
A 32-bit offset from GOT to PLT.
@ Delta32dblGOTBase
A 32-bit Delta to GOT base shifted by 1.
@ Delta32FromGOT
A 32-bit offset from GOT.
@ Delta32GOTBase
A 32-bit Delta to GOT base.
@ DeltaPLT12dbl
A 12-bit Delta shifted by 1.
@ RequestGOTAndTransformToDelta20FromGOT
A GOT entry getter/constructor, transformed to Delta20FromGOT pointing at the GOT entry for the origi...
@ Delta16dbl
A 16-bit delta shifted by 1.
@ DeltaPLT32dbl
A 32-bit Delta shifted by 1.
@ NegDelta32
A 32-bit negative delta.
@ Delta24dbl
A 24-bit delta shifted by 1.
@ RequestTLSDescInGOTAndTransformToDelta64FromGOT
A TLSInfo entry getter/constructor, transformed to Delta64FromGOT.
@ DeltaPLT64
A 64-bit Delta.
@ DeltaPLT24dbl
A 24-bit Delta shifted by 1.
@ Pointer12
A plain 12-bit pointer value relocation.
@ Delta12dbl
A 12-bit delta shifted by 1.
@ Pointer32
A plain 32-bit pointer value relocation.
@ Delta32dbl
A 32-bit delta shifted by 1.
@ Delta64FromGOT
A 64-bit offset from GOT.
const char * getEdgeKindName(Edge::Kind K)
Returns a string name for the given systemz edge.
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...
void link_ELF_systemz(std::unique_ptr< LinkGraph > G, std::unique_ptr< JITLinkContext > Ctx)
jit-link the given object buffer, which must be a ELF systemz relocatable object file.
LLVM_ABI Error markAllSymbolsLive(LinkGraph &G)
Marks all symbols in a graph live.
LLVM_ABI void printEdge(raw_ostream &OS, const Block &B, const Edge &E, StringRef EdgeKindName)
SectionRangeSymbolDesc identifyELFSectionStartAndEndSymbols(LinkGraph &G, Symbol &Sym)
ELF section start/end symbol detection.
void visitEdge(LinkGraph &G, Block *B, Edge &E)
Base case for edge-visitors where the visitor-list is empty.
DefineExternalSectionStartAndEndSymbols< SymbolIdentifierFunction > createDefineExternalSectionStartAndEndSymbolsPass(SymbolIdentifierFunction &&F)
Returns a JITLink pass (as a function class) that uses the given symbol identification function to id...
Expected< std::unique_ptr< LinkGraph > > createLinkGraphFromELFObject_systemz(MemoryBufferRef ObjectBuffer, std::shared_ptr< orc::SymbolStringPool > SSP)
Create a LinkGraph from an ELF/systemz relocatable object.
LLVM_ABI StringRef getELFRelocationTypeName(uint32_t Machine, uint32_t Type)
ELFType< llvm::endianness::big, true > ELF64BE
detail::packed_endian_specific_integral< int32_t, llvm::endianness::big, unaligned > big32_t
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.
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
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.
LinkGraphPassList PostPrunePasses
Post-prune passes.
LinkGraphPassList PrePrunePasses
Pre-prune passes.
Elf_Rel_Impl< ELFType< E, Is64 >, true > Rela
Elf_Shdr_Impl< ELFType< E, Is64 > > Shdr