LLVM: include/llvm/ExecutionEngine/JITLink/ppc64.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef LLVM_EXECUTIONENGINE_JITLINK_PPC64_H
14#define LLVM_EXECUTIONENGINE_JITLINK_PPC64_H
15
20
22
23
67
76
82
87};
88
93
94template <llvm::endianness Endianness>
97 switch (StubKind) {
101
102 Content = Content.slice(4);
103 size_t Offset = isLE ? 0 : 2;
105 Content,
107 };
108 }
112 size_t Offset = isLE ? 4 : 6;
114 Content,
116 };
117 }
121 size_t Offset = isLE ? 16 : 18;
122 Edge::AddendT Addend = isLE ? 8 : 10;
124 Content,
126 };
127 }
128 }
130}
131
133 Symbol *InitialTarget = nullptr,
134 uint64_t InitialAddend = 0) {
136 "LinkGraph's pointer size should be consistent with size of "
137 "NullPointerContent");
140 if (InitialTarget)
141 B.addEdge(Pointer64, 0, *InitialTarget, InitialAddend);
142 return G.addAnonymousSymbol(B, 0, G.getPointerSize(), false, false);
143}
144
145template <llvm::endianness Endianness>
148 Symbol &PointerSymbol,
151 Block &B = G.createContentBlock(StubSection, StubInfo.Content,
153 for (auto const &Reloc : StubInfo.Relocs)
155 return G.addAnonymousSymbol(B, 0, StubInfo.Content.size(), true, false);
156}
157
158template <llvm::endianness Endianness>
160public:
161
163
165 Edge::Kind K = E.getKind();
166 switch (K) {
173
174 getOrCreateTOCSection(G);
175 return false;
179 return true;
180 default:
181 return false;
182 }
183 }
184
188
189private:
192 if (!TOCSection)
194 return *TOCSection;
195 }
196
197 Section *TOCSection = nullptr;
198};
199
200template <llvm::endianness Endianness>
202public:
204
206
207
208
209
210
212 bool isExternal = E.getTarget().isExternal();
213 Edge::Kind K = E.getKind();
215 if (isExternal) {
218
219
220
222
223 E.setAddend(0);
224 } else
225
226
227
228
230 return true;
231 }
236 return true;
237 }
238 return false;
239 }
240
243 G, getOrCreateStubsSection(G), TOC.getEntryForTarget(G, Target),
244 this->StubKind);
245 }
246
247private:
250 if (!PLTSection)
253 return *PLTSection;
254 }
255
256 TOCTableManager &TOC;
257 Section *PLTSection = nullptr;
258 PLTCallStubKind StubKind;
259};
260
261
262
264
270 return ((x + 0x8000) >> 16) & 0xffff;
271}
274 return ((x + 0x8000) >> 32) & 0xffff;
275}
278
279
280
281
282
283
284
285template <llvm::endianness Endianness>
289 return isLE ? (Inst << 32) | (Inst >> 32) : Inst;
290}
291
292template <llvm::endianness Endianness>
295 Inst = isLE ? (Inst << 32) | (Inst >> 32) : Inst;
297}
298
299template <llvm::endianness Endianness>
301 switch (K) {
306 break;
310 break;
315 break;
320 break;
323 break;
326 break;
329 break;
332 break;
335 break;
338 break;
343 break;
347 break;
348 default:
351 " relocation does not write at half16 field");
352 }
354}
355
356
357template <llvm::endianness Endianness>
359 const Symbol *TOCSymbol) {
360 char *BlockWorkingMem = B.getAlreadyMutableContent().data();
361 char *FixupPtr = BlockWorkingMem + E.getOffset();
363 int64_t S = E.getTarget().getAddress().getValue();
364 int64_t A = E.getAddend();
365 int64_t P = FixupAddress.getValue();
366 int64_t TOCBase = TOCSymbol ? TOCSymbol->getAddress().getValue() : 0;
367 Edge::Kind K = E.getKind();
368
370 dbgs() << " Applying fixup on " << G.getEdgeKindName(K)
371 << " edge, (S, A, P, .TOC.) = (" << formatv("{0:x}", S) << ", "
372 << formatv("{0:x}", A) << ", " << formatv("{0:x}", P) << ", "
373 << formatv("{0:x}", TOCBase) << ")\n";
374 });
375
376 switch (K) {
380 break;
381 }
386 int64_t Value = S + A - P;
389 }
391 }
392 case TOC:
394 break;
410 }
412 }
414 static const uint32_t Low14Mask = 0xfffc;
416 assert((Value & 3) == 0 && "Pointer14 requires 4-byte alignment");
419 }
422 (Value & Low14Mask));
423 break;
424 }
431 int64_t Value = S + A - TOCBase;
434 }
436 }
439 int64_t Value = S + A - P;
442 }
445 (Value & 0x03fffffc));
448 assert(NopInst == 0x60000000 &&
449 "NOP should be placed here for restoring r2");
450 (void)NopInst;
451
453 }
454 break;
455 }
457 int64_t Value = S + A - P;
459 break;
460 }
462 int64_t Value = S + A - P;
465 static const uint64_t SI0Mask = 0x00000003ffff0000;
466 static const uint64_t SI1Mask = 0x000000000000ffff;
467 static const uint64_t FullMask = 0x0003ffff0000ffff;
470 FixupPtr, Inst | ((Value & SI0Mask) << 16) | (Value & SI1Mask));
471 break;
472 }
474 int64_t Value = S + A - P;
477 }
479 break;
480 }
482 int64_t Value = P - S + A;
485 }
487 break;
488 }
489 default:
491 "In graph " + G.getName() + ", section " + B.getSection().getName() +
493 }
495}
496
497}
498
499#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
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 DEBUG_WITH_TYPE(TYPE,...)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Target - Wrapper for Target specific information.
LLVM Value Representation.
An Addressable with content and edges.
Represents fixups and constraints in the LinkGraph.
Represents an object file section.
orc::ExecutorAddr getAddress() const
Returns the address of this symbol.
A CRTP base for tables that are built on demand, e.g.
Symbol & getEntryForTarget(LinkGraph &G, Symbol &Target)
static StringRef getSectionName()
Definition ppc64.h:205
bool visitEdge(LinkGraph &G, Block *B, Edge &E)
Definition ppc64.h:211
Symbol & createEntry(LinkGraph &G, Symbol &Target)
Definition ppc64.h:241
PLTTableManager(TOCTableManager< Endianness > &TOC)
Definition ppc64.h:203
static StringRef getSectionName()
Definition ppc64.h:162
bool visitEdge(LinkGraph &G, Block *B, Edge &E)
Definition ppc64.h:164
Symbol & createEntry(LinkGraph &G, Symbol &Target)
Definition ppc64.h:185
Represents an address in the executor process.
uint64_t getValue() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static uint64_t lo(uint64_t x)
Definition ppc64.h:266
static uint64_t high(uint64_t x)
Definition ppc64.h:268
Error relocateHalf16(char *FixupPtr, int64_t Value, Edge::Kind K)
Definition ppc64.h:300
LLVM_ABI const char PointerJumpStubNoTOCContent_big[32]
static uint64_t higha(uint64_t x)
Definition ppc64.h:269
PLTCallStubInfo pickStub(PLTCallStubKind StubKind)
Definition ppc64.h:95
Symbol & createAnonymousPointer(LinkGraph &G, Section &PointerSection, Symbol *InitialTarget=nullptr, uint64_t InitialAddend=0)
Definition ppc64.h:132
Error applyFixup(LinkGraph &G, Block &B, const Edge &E, const Symbol *TOCSymbol)
Apply fixup expression for edge to block content.
Definition ppc64.h:358
static uint16_t highesta(uint64_t x)
Definition ppc64.h:277
EdgeKind_ppc64
Represents ppc64 fixups and other ppc64-specific edge kinds.
Definition ppc64.h:24
@ Delta64
Definition ppc64.h:40
@ Pointer16HA
Definition ppc64.h:29
@ RequestTLSDescInGOTAndTransformToTOCDelta16HA
Definition ppc64.h:63
@ Delta34
Definition ppc64.h:41
@ Pointer16LODS
Definition ppc64.h:38
@ Pointer16HIGHER
Definition ppc64.h:33
@ TOCDelta16HI
Definition ppc64.h:52
@ Pointer64
Definition ppc64.h:25
@ TOCDelta16DS
Definition ppc64.h:50
@ RequestCallNoTOC
Definition ppc64.h:62
@ TOCDelta16HA
Definition ppc64.h:51
@ Pointer32
Definition ppc64.h:26
@ Delta16
Definition ppc64.h:44
@ RequestCall
Definition ppc64.h:60
@ TOCDelta16LODS
Definition ppc64.h:54
@ Pointer16HIGH
Definition ppc64.h:31
@ Pointer16HI
Definition ppc64.h:30
@ Pointer16HIGHERA
Definition ppc64.h:34
@ CallBranchDelta
Definition ppc64.h:56
@ NegDelta32
Definition ppc64.h:43
@ TOCDelta16
Definition ppc64.h:49
@ Delta16HI
Definition ppc64.h:46
@ Pointer16DS
Definition ppc64.h:28
@ Pointer16HIGHESTA
Definition ppc64.h:36
@ CallBranchDeltaRestoreTOC
Definition ppc64.h:58
@ TOC
Definition ppc64.h:48
@ RequestGOTAndTransformToDelta34
Definition ppc64.h:55
@ Pointer16LO
Definition ppc64.h:37
@ Delta16HA
Definition ppc64.h:45
@ TOCDelta16LO
Definition ppc64.h:53
@ RequestTLSDescInGOTAndTransformToTOCDelta16LO
Definition ppc64.h:64
@ Pointer16HIGHA
Definition ppc64.h:32
@ Pointer16
Definition ppc64.h:27
@ Delta16LO
Definition ppc64.h:47
@ Pointer16HIGHEST
Definition ppc64.h:35
@ Delta32
Definition ppc64.h:42
@ Pointer14
Definition ppc64.h:39
@ RequestTLSDescInGOTAndTransformToDelta34
Definition ppc64.h:65
LLVM_ABI const char PointerJumpStubContent_little[20]
LLVM_ABI const char PointerJumpStubContent_big[20]
static uint64_t higher(uint64_t x)
Definition ppc64.h:272
LLVM_ABI const char NullPointerContent[8]
LLVM_ABI const char PointerJumpStubNoTOCContent_little[32]
static uint64_t readPrefixedInstruction(const char *Loc)
Definition ppc64.h:286
static void writePrefixedInstruction(char *Loc, uint64_t Inst)
Definition ppc64.h:293
Symbol & createAnonymousPointerJumpStub(LinkGraph &G, Section &StubSection, Symbol &PointerSymbol, PLTCallStubKind StubKind)
Definition ppc64.h:146
static uint16_t highest(uint64_t x)
Definition ppc64.h:276
static uint64_t highera(uint64_t x)
Definition ppc64.h:273
PLTCallStubKind
Definition ppc64.h:68
@ LongBranch
Definition ppc64.h:70
@ LongBranchSaveR2
Definition ppc64.h:72
@ LongBranchNoTOC
Definition ppc64.h:74
LLVM_ABI const char * getEdgeKindName(Edge::Kind K)
Returns a string name for the given ppc64 edge.
static uint16_t hi(uint64_t x)
Definition ppc64.h:267
static uint16_t ha(uint64_t x)
Definition ppc64.h:265
LLVM_ABI Error makeTargetOutOfRangeError(const LinkGraph &G, const Block &B, const Edge &E)
Create an out of range error for the given edge in the given block.
uint32_t read32(const void *P, endianness E)
void write32(void *P, uint32_t V, endianness E)
uint64_t read64(const void *P, endianness E)
void write16(void *P, uint16_t V, endianness E)
void write64(void *P, uint64_t V, endianness E)
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
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.
ArrayRef< char > Content
Definition ppc64.h:90
SmallVector< PLTCallStubReloc, 2 > Relocs
Definition ppc64.h:91
Edge::Kind K
Definition ppc64.h:84
Edge::AddendT A
Definition ppc64.h:86
size_t Offset
Definition ppc64.h:85