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:
73 return make_error<JITLinkError>(
74 "Unsupported loongarch relocation:" +
formatv(
"{0:d}: ",
Type) +
82 using Self = ELFLinkGraphBuilder_loongarch<ELFT>;
83 for (
const auto &RelSect : Base::Sections)
84 if (
Error Err = Base::forEachRelaRelocation(RelSect,
this,
85 &Self::addSingleRelocation))
91 Error addSingleRelocation(
const typename ELFT::Rela &Rel,
92 const typename ELFT::Shdr &FixupSect,
96 uint32_t SymbolIndex = Rel.getSymbol(
false);
97 auto ObjSymbol = Base::Obj.getRelocationSymbol(Rel, Base::SymTabSec);
99 return ObjSymbol.takeError();
101 Symbol *GraphSymbol = Base::getGraphSymbol(SymbolIndex);
103 return make_error<StringError>(
104 formatv(
"Could not find symbol at given index, did you add it to "
105 "JITSymbolTable? index: {0}, shndx: {1} Size of table: {2}",
106 SymbolIndex, (*ObjSymbol)->st_shndx,
107 Base::GraphSymbols.size()),
113 return Kind.takeError();
115 int64_t Addend = Rel.r_addend;
125 BlockToFix.
addEdge(std::move(GE));
131 ELFLinkGraphBuilder_loongarch(
StringRef FileName,
155 dbgs() <<
"Building jitlink graph for new input "
161 return ELFObj.takeError();
163 auto Features = (*ELFObj)->getFeatures();
165 return Features.takeError();
168 auto &ELFObjFile = cast<object::ELFObjectFile<object::ELF64LE>>(**ELFObj);
169 return ELFLinkGraphBuilder_loongarch<object::ELF64LE>(
170 (*ELFObj)->getFileName(), ELFObjFile.getELFFile(),
171 (*ELFObj)->makeTriple(), std::move(*Features))
176 "Invalid triple for LoongArch ELF object file");
177 auto &ELFObjFile = cast<object::ELFObjectFile<object::ELF32LE>>(**ELFObj);
178 return ELFLinkGraphBuilder_loongarch<object::ELF32LE>(
179 (*ELFObj)->getFileName(), ELFObjFile.getELFFile(),
180 (*ELFObj)->makeTriple(), std::move(*Features))
185 std::unique_ptr<JITLinkContext> Ctx) {
187 const Triple &TT =
G->getTargetTriple();
188 if (Ctx->shouldAddDefaultTargetPasses(TT)) {
191 Config.PrePrunePasses.push_back(
197 if (
auto MarkLive = Ctx->getMarkLivePass(TT))
198 Config.PrePrunePasses.push_back(std::move(MarkLive));
203 Config.PostPrunePasses.push_back(buildTables_ELF_loongarch);
206 if (
auto Err = Ctx->modifyPassConfig(*
G,
Config))
207 return Ctx->notifyFailed(std::move(Err));
209 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...
@ 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.
Expected< std::unique_ptr< LinkGraph > > createLinkGraphFromELFObject_loongarch(MemoryBufferRef ObjectBuffer)
Create a LinkGraph from an ELF/loongarch 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 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(const char *Fmt, Ts &&...Vals) -> formatv_object< decltype(std::make_tuple(support::detail::build_format_adapter(std::forward< 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...