25#define DEBUG_TYPE "jitlink"
33class ELFJITLinker_loongarch :
public JITLinker<ELFJITLinker_loongarch> {
34 friend class JITLinker<ELFJITLinker_loongarch>;
37 ELFJITLinker_loongarch(std::unique_ptr<JITLinkContext> Ctx,
38 std::unique_ptr<LinkGraph>
G,
40 :
JITLinker(std::move(Ctx), std::move(
G), std::move(PassConfig)) {}
48template <
typename ELFT>
53 using namespace loongarch;
59 case ELF::R_LARCH_32_PCREL:
61 case ELF::R_LARCH_B26:
63 case ELF::R_LARCH_PCALA_HI20:
65 case ELF::R_LARCH_PCALA_LO12:
67 case ELF::R_LARCH_GOT_PC_HI20:
69 case ELF::R_LARCH_GOT_PC_LO12:
71 case ELF::R_LARCH_CALL36:
75 return make_error<JITLinkError>(
76 "Unsupported loongarch relocation:" +
formatv(
"{0:d}: ",
Type) +
84 using Self = ELFLinkGraphBuilder_loongarch<ELFT>;
85 for (
const auto &RelSect : Base::Sections)
86 if (
Error Err = Base::forEachRelaRelocation(RelSect,
this,
87 &Self::addSingleRelocation))
93 Error addSingleRelocation(
const typename ELFT::Rela &Rel,
94 const typename ELFT::Shdr &FixupSect,
98 uint32_t SymbolIndex = Rel.getSymbol(
false);
99 auto ObjSymbol = Base::Obj.getRelocationSymbol(Rel, Base::SymTabSec);
101 return ObjSymbol.takeError();
103 Symbol *GraphSymbol = Base::getGraphSymbol(SymbolIndex);
105 return make_error<StringError>(
106 formatv(
"Could not find symbol at given index, did you add it to "
107 "JITSymbolTable? index: {0}, shndx: {1} Size of table: {2}",
108 SymbolIndex, (*ObjSymbol)->st_shndx,
109 Base::GraphSymbols.size()),
115 return Kind.takeError();
117 int64_t Addend = Rel.r_addend;
127 BlockToFix.
addEdge(std::move(GE));
133 ELFLinkGraphBuilder_loongarch(
StringRef FileName,
135 std::shared_ptr<orc::SymbolStringPool> SSP,
138 std::move(Features), FileName,
157 MemoryBufferRef ObjectBuffer, std::shared_ptr<orc::SymbolStringPool> SSP) {
159 dbgs() <<
"Building jitlink graph for new input "
165 return ELFObj.takeError();
167 auto Features = (*ELFObj)->getFeatures();
169 return Features.takeError();
172 auto &ELFObjFile = cast<object::ELFObjectFile<object::ELF64LE>>(**ELFObj);
173 return ELFLinkGraphBuilder_loongarch<object::ELF64LE>(
174 (*ELFObj)->getFileName(), ELFObjFile.getELFFile(),
175 std::move(SSP), (*ELFObj)->makeTriple(), std::move(*Features))
180 "Invalid triple for LoongArch ELF object file");
181 auto &ELFObjFile = cast<object::ELFObjectFile<object::ELF32LE>>(**ELFObj);
182 return ELFLinkGraphBuilder_loongarch<object::ELF32LE>(
183 (*ELFObj)->getFileName(), ELFObjFile.getELFFile(), std::move(SSP),
184 (*ELFObj)->makeTriple(), std::move(*Features))
189 std::unique_ptr<JITLinkContext> Ctx) {
191 const Triple &TT =
G->getTargetTriple();
192 if (Ctx->shouldAddDefaultTargetPasses(TT)) {
195 Config.PrePrunePasses.push_back(
201 if (
auto MarkLive = Ctx->getMarkLivePass(TT))
202 Config.PrePrunePasses.push_back(std::move(MarkLive));
207 Config.PostPrunePasses.push_back(buildTables_ELF_loongarch);
210 if (
auto Err = Ctx->modifyPassConfig(*
G,
Config))
211 return Ctx->notifyFailed(std::move(Err));
213 ELFJITLinker_loongarch::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.
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.
LinkGraph building code that's specific to the given ELFT, but common across all architectures.
virtual Error addRelocations()=0
Call to derived class to handle relocations.
Represents fixups and constraints in the LinkGraph.
Global Offset Table Builder.
Procedure Linkage Table Builder.
static Expected< std::unique_ptr< ObjectFile > > createELFObjectFile(MemoryBufferRef Object, bool InitContent=true)
Represents an address in the executor process.
const char * getEdgeKindName(Edge::Kind K)
Returns a string name for the given loongarch edge.
@ RequestGOTAndTransformToPage20
A GOT entry getter/constructor, transformed to Page20 pointing at the GOT entry for the original targ...
@ NegDelta32
A 32-bit negative delta.
@ PageOffset12
The 12-bit offset of the target within its page.
@ Page20
The signed 20-bit delta from the fixup page to the page containing the target.
@ Pointer64
A plain 64-bit pointer value relocation.
@ RequestGOTAndTransformToPageOffset12
A GOT entry getter/constructor, transformed to Pageoffset12 pointing at the GOT entry for the origina...
@ Call36PCRel
A 36-bit PC-relative call.
@ Branch26PCRel
A 26-bit PC-relative branch.
@ Pointer32
A plain 32-bit pointer value relocation.
Error applyFixup(LinkGraph &G, Block &B, const Edge &E)
Apply fixup expression for edge to block content.
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.
Expected< std::unique_ptr< LinkGraph > > createLinkGraphFromELFObject_loongarch(MemoryBufferRef ObjectBuffer, std::shared_ptr< orc::SymbolStringPool > SSP)
Create a LinkGraph from an ELF/loongarch relocatable object.
void printEdge(raw_ostream &OS, const Block &B, const Edge &E, StringRef EdgeKindName)
void link_ELF_loongarch(std::unique_ptr< LinkGraph > G, std::unique_ptr< JITLinkContext > Ctx)
jit-link the given object buffer, which must be an ELF loongarch object file.
StringRef getELFRelocationTypeName(uint32_t Machine, uint32_t Type)
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...