Go to the documentation of this file.
15 #define DEBUG_TYPE "jitlink"
28 return "Pointer32Signed";
38 return "Delta64FromGOT";
40 return "BranchPCRel32";
42 return "BranchPCRel32ToPtrJumpStub";
44 return "BranchPCRel32ToPtrJumpStubBypassable";
46 return "RequestGOTAndTransformToDelta32";
48 return "RequestGOTAndTransformToDelta64";
50 return "RequestGOTAndTransformToDelta64FromGOT";
52 return "PCRel32GOTLoadREXRelaxable";
54 return "RequestGOTAndTransformToPCRel32GOTLoadREXRelaxable";
56 return "PCRel32GOTLoadRelaxable";
58 return "RequestGOTAndTransformToPCRel32GOTLoadRelaxable";
60 return "PCRel32TLVPLoadREXRelaxable";
62 return "RequestTLVPAndTransformToPCRel32TLVPLoadREXRelaxable";
69 0x00, 0x00, 0x00, 0x00};
72 static_cast<char>(0xFFu), 0x25, 0x00, 0x00, 0x00, 0x00};
77 for (
auto *
B :
G.blocks())
78 for (
auto &
E :
B->edges()) {
83 assert(
E.getOffset() >= (REXPrefix ? 3u : 2u) &&
84 "GOT edge occurs too early in block");
86 auto *FixupData =
reinterpret_cast<uint8_t *
>(
87 const_cast<char *
>(
B->getContent().data())) +
89 const uint8_t
Op = FixupData[-2];
90 const uint8_t ModRM = FixupData[-1];
92 auto &GOTEntryBlock =
E.getTarget().getBlock();
93 assert(GOTEntryBlock.getSize() ==
G.getPointerSize() &&
94 "GOT entry block should be pointer sized");
95 assert(GOTEntryBlock.edges_size() == 1 &&
96 "GOT entry should only have one outgoing edge");
97 auto &GOTTarget = GOTEntryBlock.edges().begin()->getTarget();
100 int64_t Displacement = TargetAddr - EdgeAddr + 4;
106 if (!(TargetInRangeForImmU32 || DisplacementInRangeForImmS32))
110 if (
Op == 0x8b && DisplacementInRangeForImmS32) {
111 FixupData[-2] = 0x8d;
113 E.setTarget(GOTTarget);
114 E.setAddend(
E.getAddend() - 4);
116 dbgs() <<
" Replaced GOT load wih LEA:\n ";
124 if (
Op == 0xff && TargetInRangeForImmU32) {
129 FixupData[-2] = 0x67;
130 FixupData[-1] = 0xe8;
132 dbgs() <<
" replaced call instruction's memory operand wih imm "
139 assert(ModRM == 0x25 &&
"Invalid ModRm for call/jmp instructions");
140 FixupData[-2] = 0xe9;
142 E.setOffset(
E.getOffset() - 1);
144 dbgs() <<
" replaced jmp instruction's memory operand wih imm "
151 E.setTarget(GOTTarget);
155 auto &StubBlock =
E.getTarget().getBlock();
157 "Stub block should be stub sized");
158 assert(StubBlock.edges_size() == 1 &&
159 "Stub block should only have one outgoing edge");
161 auto &GOTBlock = StubBlock.edges().begin()->getTarget().getBlock();
162 assert(GOTBlock.getSize() ==
G.getPointerSize() &&
163 "GOT block should be pointer sized");
164 assert(GOTBlock.edges_size() == 1 &&
165 "GOT block should only have one outgoing edge");
167 auto &GOTTarget = GOTBlock.edges().begin()->getTarget();
171 int64_t Displacement = TargetAddr - EdgeAddr + 4;
174 E.setTarget(GOTTarget);
176 dbgs() <<
" Replaced stub branch with direct branch:\n ";
Represents an address in the executor process.
@ PCRel32TLVPLoadREXRelaxable
A PC-relative REX load of a Thread Local Variable Pointer (TLVP) entry, relaxable if the TLVP entry t...
This is an optimization pass for GlobalISel generic memory operations.
@ NegDelta32
A 32-bit negative delta.
@ RequestGOTAndTransformToDelta64
A GOT entry getter/constructor, transformed to Delta64 pointing at the GOT entry for the original tar...
static ErrorSuccess success()
Create a success value.
@ RequestGOTAndTransformToDelta32
A GOT entry getter/constructor, transformed to Delta32 pointing at the GOT entry for the original tar...
uint64_t getValue() const
@ Pointer64
A plain 64-bit pointer value relocation.
@ BranchPCRel32ToPtrJumpStub
A 32-bit PC-relative branch to a pointer jump stub.
@ PCRel32GOTLoadREXRelaxable
A PC-relative REX load of a GOT entry, relaxable if GOT entry target is in-range of the fixup.
void printEdge(raw_ostream &OS, const Block &B, const Edge &E, StringRef EdgeKindName)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
@ PCRel32GOTLoadRelaxable
A PC-relative load of a GOT entry, relaxable if GOT entry target is in-range of the fixup.
@ Delta64FromGOT
A 64-bit GOT delta.
Error optimizeGOTAndStubAccesses(LinkGraph &G)
Optimize the GOT and Stub relocations if the edge target address is in range.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
@ RequestGOTAndTransformToPCRel32GOTLoadRelaxable
A GOT entry getter/constructor, transformed to PCRel32ToGOTLoadRelaxable pointing at the GOT entry fo...
const char * getGenericEdgeKindName(Edge::Kind K)
Returns the string name of the given generic edge kind, or "unknown" otherwise.
const char * getEdgeKindName(Edge::Kind K)
Returns a string name for the given x86-64 edge.
@ RequestGOTAndTransformToDelta64FromGOT
A GOT entry offset within GOT getter/constructor, transformed to Delta64FromGOT pointing at the GOT e...
@ BranchPCRel32
A 32-bit PC-relative branch.
constexpr uint64_t PointerSize
x86_64 pointer size.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
@ RequestTLVPAndTransformToPCRel32TLVPLoadREXRelaxable
A TLVP entry getter/constructor, transformed to Delta32ToTLVPLoadREXRelaxable.
bool isInRangeForImmU32(uint64_t Value)
Returns true if the given uint64_t value is in range for a uint32_t.
@ RequestGOTAndTransformToPCRel32GOTLoadREXRelaxable
A GOT entry getter/constructor, transformed to PCRel32ToGOTLoadREXRelaxable pointing at the GOT entry...
const char NullPointerContent[PointerSize]
x86-64 null pointer content.
Lightweight error class with error context and mandatory checking.
const char PointerJumpStubContent[6]
x86-64 pointer jump stub content.
bool isInRangeForImmS32(int64_t Value)
Returns true if the given int64_t value is in range for an int32_t.
@ NegDelta64
A 64-bit negative delta.
@ BranchPCRel32ToPtrJumpStubBypassable
A relaxable version of BranchPCRel32ToPtrJumpStub.
@ Pointer32
A plain 32-bit pointer value relocation.
@ Pointer32Signed
A signed 32-bit pointer value relocation.