23#define DEBUG_TYPE "jitlink"
30constexpr StringRef ELFTOCSymbolName =
".TOC.";
31constexpr StringRef TOCSymbolAliasIdent =
"__TOC__";
32constexpr uint64_t ELFTOCBaseOffset = 0x8000;
33constexpr StringRef ELFTLSInfoSectionName =
"$__TLSINFO";
35template <llvm::endianness Endianness>
36class TLSInfoTableManager_ELF_ppc64
37 :
public TableManager<TLSInfoTableManager_ELF_ppc64<Endianness>> {
39 static const uint8_t TLSInfoEntryContent[16];
44 Edge::Kind K =
E.getKind();
48 E.setTarget(this->getEntryForTarget(
G,
E.getTarget()));
52 E.setTarget(this->getEntryForTarget(
G,
E.getTarget()));
56 E.setTarget(this->getEntryForTarget(
G,
E.getTarget()));
66 auto &TLSInfoEntry =
G.createMutableContentBlock(
67 getTLSInfoSection(
G),
G.allocateContent(getTLSInfoEntryContent()),
70 return G.addAnonymousSymbol(TLSInfoEntry, 0, 16,
false,
false);
82 return {
reinterpret_cast<const char *
>(TLSInfoEntryContent),
83 sizeof(TLSInfoEntryContent)};
86 Section *TLSInfoTable =
nullptr;
90const uint8_t TLSInfoTableManager_ELF_ppc64<
92 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
93 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
97const uint8_t TLSInfoTableManager_ELF_ppc64<
99 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
100 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
103template <llvm::endianness Endianness>
106 Symbol *TOCSymbol =
nullptr;
108 for (
Symbol *Sym :
G.defined_symbols())
109 if (
LLVM_UNLIKELY(Sym->hasName() && *Sym->getName() == ELFTOCSymbolName)) {
115 for (
Symbol *Sym :
G.external_symbols())
116 if (Sym->hasName() && *Sym->getName() == ELFTOCSymbolName) {
123 TOCSymbol = &
G.addExternalSymbol(ELFTOCSymbolName, 0,
false);
125 return TOC.getEntryForTarget(
G, *TOCSymbol);
129template <llvm::endianness Endianness>
133 auto isGOTEntry = [](
const Edge &
E) {
136 if (
Section *dotTOCSection =
G.findSectionByName(
".toc")) {
137 for (
Block *
B : dotTOCSection->blocks())
138 for (
Edge &
E :
B->edges())
140 TOC.registerPreExistingEntry(
E.getTarget(),
141 G.addAnonymousSymbol(*
B,
E.getOffset(),
147template <llvm::endianness Endianness>
156 createELFGOTHeader(
G, TOC);
159 registerExistingGOTEntries(
G, TOC);
162 TLSInfoTableManager_ELF_ppc64<Endianness> TLSInfo;
170 if (
Section *TOCSection =
G.findSectionByName(TOC.getSectionName())) {
173 if (
Section *gotSection =
G.findSectionByName(
".got"))
174 G.mergeSections(*TOCSection, *gotSection);
175 if (
Section *tocSection =
G.findSectionByName(
".toc"))
176 G.mergeSections(*TOCSection, *tocSection);
177 if (
Section *sdataSection =
G.findSectionByName(
".sdata"))
178 G.mergeSections(*TOCSection, *sdataSection);
179 if (
Section *sbssSection =
G.findSectionByName(
".sbss"))
180 G.mergeSections(*TOCSection, *sbssSection);
183 if (
Section *tocbssSection =
G.findSectionByName(
".tocbss"))
184 G.mergeSections(*TOCSection, *tocbssSection);
185 if (
Section *pltSection =
G.findSectionByName(
".plt"))
186 G.mergeSections(*TOCSection, *pltSection);
196template <llvm::endianness Endianness>
213 G->getTargetTriple().getArchName() +
218 &Self::addSingleRelocation))
229 auto ELFReloc = Rel.getType(
false);
236 if (ELFReloc == ELF::R_PPC64_TLSGD)
238 if (ELFReloc == ELF::R_PPC64_TLSLD)
242 if (ELFReloc == ELF::R_PPC64_PCREL_OPT)
246 if (ELFReloc == ELF::R_PPC64_TPREL34)
252 return ObjSymbol.takeError();
254 uint32_t SymbolIndex = Rel.getSymbol(
false);
258 formatv(
"Could not find symbol at given index, did you add it to "
259 "JITSymbolTable? index: {0}, shndx: {1} Size of table: {2}",
260 SymbolIndex, (*ObjSymbol)->st_shndx,
264 int64_t Addend = Rel.r_addend;
268 Edge::Kind Kind = Edge::Invalid;
273 "In " +
G->getName() +
": Unsupported ppc64 relocation type " +
275 case ELF::R_PPC64_ADDR64:
278 case ELF::R_PPC64_ADDR32:
281 case ELF::R_PPC64_ADDR16:
284 case ELF::R_PPC64_ADDR16_DS:
287 case ELF::R_PPC64_ADDR16_HA:
290 case ELF::R_PPC64_ADDR16_HI:
293 case ELF::R_PPC64_ADDR16_HIGH:
296 case ELF::R_PPC64_ADDR16_HIGHA:
299 case ELF::R_PPC64_ADDR16_HIGHER:
302 case ELF::R_PPC64_ADDR16_HIGHERA:
305 case ELF::R_PPC64_ADDR16_HIGHEST:
308 case ELF::R_PPC64_ADDR16_HIGHESTA:
311 case ELF::R_PPC64_ADDR16_LO:
314 case ELF::R_PPC64_ADDR16_LO_DS:
317 case ELF::R_PPC64_ADDR14:
320 case ELF::R_PPC64_TOC:
323 case ELF::R_PPC64_TOC16:
326 case ELF::R_PPC64_TOC16_HA:
329 case ELF::R_PPC64_TOC16_HI:
332 case ELF::R_PPC64_TOC16_DS:
335 case ELF::R_PPC64_TOC16_LO:
338 case ELF::R_PPC64_TOC16_LO_DS:
341 case ELF::R_PPC64_REL16:
344 case ELF::R_PPC64_REL16_HA:
347 case ELF::R_PPC64_REL16_HI:
350 case ELF::R_PPC64_REL16_LO:
353 case ELF::R_PPC64_REL32:
356 case ELF::R_PPC64_REL24_NOTOC:
359 case ELF::R_PPC64_REL24:
369 case ELF::R_PPC64_REL64:
372 case ELF::R_PPC64_PCREL34:
375 case ELF::R_PPC64_GOT_PCREL34:
378 case ELF::R_PPC64_GOT_TLSGD16_HA:
381 case ELF::R_PPC64_GOT_TLSGD16_LO:
384 case ELF::R_PPC64_GOT_TLSGD_PCREL34:
390 BlockToFix.
addEdge(std::move(GE));
397 std::shared_ptr<orc::SymbolStringPool> SSP,
401 ppc64::getEdgeKindName) {}
404template <llvm::endianness Endianness>
407 friend JITLinkerBase;
414 [
this](
LinkGraph &G) {
return defineTOCBase(G); });
418 Symbol *TOCSymbol =
nullptr;
421 for (
Symbol *Sym :
G.defined_symbols()) {
423 *Sym->getName() == ELFTOCSymbolName)) {
429 assert(TOCSymbol ==
nullptr &&
430 "TOCSymbol should not be defined at this point");
432 for (
Symbol *Sym :
G.external_symbols()) {
433 if (Sym->hasName() && *Sym->getName() == ELFTOCSymbolName) {
439 if (Section *TOCSection = G.findSectionByName(
441 assert(!TOCSection->empty() &&
"TOC section should have reserved an "
442 "entry for containing the TOC base");
444 SectionRange SR(*TOCSection);
445 orc::ExecutorAddr TOCBaseAddr(SR.getFirstBlock()->getAddress() +
447 assert(TOCSymbol && TOCSymbol->isExternal() &&
448 ".TOC. should be a external symbol at this point");
449 G.makeAbsolute(*TOCSymbol, TOCBaseAddr);
451 G.addAbsoluteSymbol(TOCSymbolAliasIdent, TOCSymbol->getAddress(),
452 TOCSymbol->getSize(), TOCSymbol->getLinkage(),
453 TOCSymbol->getScope(), TOCSymbol->isLive());
467template <llvm::endianness Endianness>
468Expected<std::unique_ptr<LinkGraph>>
470 std::shared_ptr<orc::SymbolStringPool> SSP) {
472 dbgs() <<
"Building jitlink graph for new input "
478 return ELFObj.takeError();
480 auto Features = (*ELFObj)->getFeatures();
482 return Features.takeError();
487 (*ELFObj)->getFileName(), ELFObjFile.getELFFile(), std::move(SSP),
488 (*ELFObj)->makeTriple(), std::move(*Features))
492template <llvm::endianness Endianness>
494 std::unique_ptr<JITLinkContext> Ctx) {
497 if (Ctx->shouldAddDefaultTargetPasses(
G->getTargetTriple())) {
508 if (
auto MarkLive = Ctx->getMarkLivePass(
G->getTargetTriple()))
516 if (
auto Err = Ctx->modifyPassConfig(*
G, Config))
517 return Ctx->notifyFailed(std::move(Err));
525 std::shared_ptr<orc::SymbolStringPool> SSP) {
527 std::move(ObjectBuffer), std::move(SSP));
531 MemoryBufferRef ObjectBuffer, std::shared_ptr<orc::SymbolStringPool> SSP) {
533 std::move(ObjectBuffer), std::move(SSP));
538 std::unique_ptr<JITLinkContext> Ctx) {
544 std::unique_ptr<JITLinkContext> Ctx) {
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)
#define LLVM_LIKELY(EXPR)
std::pair< BasicBlock *, BasicBlock * > Edge
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_ppc64(std::unique_ptr< JITLinkContext > Ctx, std::unique_ptr< LinkGraph > G, PassConfiguration PassConfig)
std::unique_ptr< LinkGraph > G
ELFLinkGraphBuilder_ppc64(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::ELFType< Endianness, true > > &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()
static void link(ArgTs &&... Args)
Represents an object file section.
A CRTP base for tables that are built on demand, e.g.
static StringRef getSectionName()
static Expected< std::unique_ptr< ObjectFile > > createELFObjectFile(MemoryBufferRef Object, bool InitContent=true)
Represents an address in the executor process.
static int64_t decodePPC64LocalEntryOffset(unsigned Other)
static constexpr const StringLiteral & getSectionName(DebugSectionKind SectionKind)
Return the name of the section.
Error applyFixup(LinkGraph &G, Block &B, const Edge &E, const Symbol *TOCSymbol)
Apply fixup expression for edge to block content.
@ RequestTLSDescInGOTAndTransformToTOCDelta16HA
@ RequestGOTAndTransformToDelta34
@ RequestTLSDescInGOTAndTransformToTOCDelta16LO
@ RequestTLSDescInGOTAndTransformToDelta34
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_ppc64le(std::unique_ptr< LinkGraph > G, std::unique_ptr< JITLinkContext > Ctx)
jit-link the given object buffer, which must be a ELF ppc64le object file.
LLVM_ABI Error markAllSymbolsLive(LinkGraph &G)
Marks all symbols in a graph live.
void link_ELF_ppc64(std::unique_ptr< LinkGraph > G, std::unique_ptr< JITLinkContext > Ctx)
jit-link the given object buffer, which must be a ELF ppc64le object file.
Expected< std::unique_ptr< LinkGraph > > createLinkGraphFromELFObject_ppc64le(MemoryBufferRef ObjectBuffer, std::shared_ptr< orc::SymbolStringPool > SSP)
Create a LinkGraph from an ELF/ppc64le relocatable object.
void visitEdge(LinkGraph &G, Block *B, Edge &E)
Base case for edge-visitors where the visitor-list is empty.
Expected< std::unique_ptr< LinkGraph > > createLinkGraphFromELFObject_ppc64(MemoryBufferRef ObjectBuffer, std::shared_ptr< orc::SymbolStringPool > SSP)
Create a LinkGraph from an ELF/ppc64 relocatable object.
LLVM_ABI StringRef getELFRelocationTypeName(uint32_t Machine, uint32_t Type)
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