20#define DEBUG_TYPE "jitlink"
27class ELFJITLinker_hexagon :
public JITLinker<ELFJITLinker_hexagon> {
28 friend class JITLinker<ELFJITLinker_hexagon>;
31 ELFJITLinker_hexagon(std::unique_ptr<JITLinkContext> Ctx,
32 std::unique_ptr<LinkGraph>
G,
34 :
JITLinker(std::move(Ctx), std::move(
G), std::move(PassConfig)) {}
42class ELFLinkGraphBuilder_hexagon
51 case ELF::R_HEX_32_PCREL:
53 case ELF::R_HEX_B22_PCREL:
54 case ELF::R_HEX_PLT_B22_PCREL:
60 case ELF::R_HEX_GD_PLT_B22_PCREL:
62 case ELF::R_HEX_B15_PCREL:
64 case ELF::R_HEX_B13_PCREL:
66 case ELF::R_HEX_B9_PCREL:
68 case ELF::R_HEX_B7_PCREL:
74 case ELF::R_HEX_32_6_X:
76 case ELF::R_HEX_B32_PCREL_X:
77 case ELF::R_HEX_GD_PLT_B32_PCREL_X:
79 case ELF::R_HEX_B22_PCREL_X:
80 case ELF::R_HEX_GD_PLT_B22_PCREL_X:
82 case ELF::R_HEX_B15_PCREL_X:
84 case ELF::R_HEX_B13_PCREL_X:
86 case ELF::R_HEX_B9_PCREL_X:
88 case ELF::R_HEX_B7_PCREL_X:
92 case ELF::R_HEX_6_PCREL_X:
100 case ELF::R_HEX_11_X:
102 case ELF::R_HEX_12_X:
104 case ELF::R_HEX_16_X:
109 "In " +
G->getName() +
": Unsupported Hexagon relocation type " +
113 Error addRelocations()
override {
116 using Self = ELFLinkGraphBuilder_hexagon;
118 for (
const auto &RelSect : Base::Sections) {
122 "Unexpected SHT_REL section in Hexagon ELF object",
125 if (
Error Err = Base::forEachRelaRelocation(RelSect,
this,
126 &Self::addSingleRelocation))
138 auto ELFReloc = Rel.getType(
false);
143 uint32_t SymbolIndex = Rel.getSymbol(
false);
144 auto ObjSymbol = Base::Obj.getRelocationSymbol(Rel, Base::SymTabSec);
146 return ObjSymbol.takeError();
148 Symbol *GraphSymbol = Base::getGraphSymbol(SymbolIndex);
151 formatv(
"Could not find symbol at given index, did you add it to "
152 "JITSymbolTable? index: {0}, shndx: {1} Size of table: {2}",
153 SymbolIndex, (*ObjSymbol)->st_shndx,
154 Base::GraphSymbols.size()),
159 return Kind.takeError();
162 int64_t Addend = Rel.r_addend;
172 BlockToFix.
addEdge(std::move(GE));
177 ELFLinkGraphBuilder_hexagon(
StringRef FileName,
179 std::shared_ptr<orc::SymbolStringPool> SSP,
182 std::move(Features), FileName,
191 MemoryBufferRef ObjectBuffer, std::shared_ptr<orc::SymbolStringPool> SSP) {
193 dbgs() <<
"Building jitlink graph for new input "
199 return ELFObj.takeError();
201 auto Features = (*ELFObj)->getFeatures();
203 return Features.takeError();
206 "Only Hexagon is supported");
210 return ELFLinkGraphBuilder_hexagon(
211 (*ELFObj)->getFileName(), ELFObjFile.getELFFile(), std::move(SSP),
212 (*ELFObj)->makeTriple(), std::move(*Features))
217 std::unique_ptr<JITLinkContext> Ctx) {
219 const Triple &TT =
G->getTargetTriple();
220 if (Ctx->shouldAddDefaultTargetPasses(TT)) {
223 if (
auto MarkLive = Ctx->getMarkLivePass(TT))
228 if (
auto Err = Ctx->modifyPassConfig(*
G, Config))
229 return Ctx->notifyFailed(std::move(Err));
231 ELFJITLinker_hexagon::link(std::move(Ctx), std::move(
G), std::move(Config));
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)
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.
LinkGraph building code that's specific to the given ELFT, but common across all architectures.
Represents fixups and constraints in the LinkGraph.
static Expected< std::unique_ptr< ObjectFile > > createELFObjectFile(MemoryBufferRef Object, bool InitContent=true)
Represents an address in the executor process.
LLVM_ABI const char * getEdgeKindName(Edge::Kind K)
Returns a string name for the given Hexagon edge kind.
Error applyFixup(LinkGraph &G, Block &B, const Edge &E)
Apply fixup expression for edge to block content.
@ Word6_PCREL_X
6-bit PC-relative extended.
@ B22_PCREL
22-bit PC-relative branch (shifted right by 2).
@ B15_PCREL_X
15-bit PC-relative branch, lower 6 bits via extender.
@ Word9_X
9-bit absolute extended (6 effective bits).
@ Word32_6_X
32-bit absolute, upper 26 bits via constant extender (shifted right by 6).
@ B13_PCREL_X
13-bit PC-relative branch, lower 6 bits via extender.
@ Word16_X
16-bit absolute extended (6 effective bits).
@ B7_PCREL_X
7-bit PC-relative branch, lower 6 bits via extender.
@ HI16
High 16 bits of absolute address.
@ B9_PCREL_X
9-bit PC-relative branch, lower 6 bits via extender.
@ PCRel32
32-bit PC-relative.
@ Word11_X
11-bit absolute extended (6 effective bits).
@ B7_PCREL
7-bit PC-relative branch (shifted right by 2).
@ B15_PCREL
15-bit PC-relative branch (shifted right by 2).
@ Word6_X
6-bit absolute extended.
@ B32_PCREL_X
32-bit PC-relative, upper 26 bits via constant extender (shifted by 6).
@ Pointer32
Full 32-bit absolute pointer.
@ Word10_X
10-bit absolute extended (6 effective bits).
@ B13_PCREL
13-bit PC-relative branch (shifted right by 2).
@ B9_PCREL
9-bit PC-relative branch (shifted right by 2).
@ Word12_X
12-bit absolute extended.
@ B22_PCREL_X
22-bit PC-relative branch, lower 6 bits via extender.
@ LO16
Low 16 bits of absolute address.
@ Word8_X
8-bit absolute extended.
Expected< std::unique_ptr< LinkGraph > > createLinkGraphFromELFObject_hexagon(MemoryBufferRef ObjectBuffer, std::shared_ptr< orc::SymbolStringPool > SSP)
Create a LinkGraph from an ELF/Hexagon relocatable object.
LLVM_ABI Error markAllSymbolsLive(LinkGraph &G)
Marks all symbols in a graph live.
void link_ELF_hexagon(std::unique_ptr< LinkGraph > G, std::unique_ptr< JITLinkContext > Ctx)
jit-link the given object buffer, which must be a ELF Hexagon relocatable object file.
LLVM_ABI void printEdge(raw_ostream &OS, const Block &B, const Edge &E, StringRef EdgeKindName)
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.
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
An LinkGraph pass configuration, consisting of a list of pre-prune, post-prune, and post-fixup passes...
LinkGraphPassList PrePrunePasses
Pre-prune passes.
Elf_Rel_Impl< ELFType< E, Is64 >, true > Rela
Elf_Shdr_Impl< ELFType< E, Is64 > > Shdr