15#define DEBUG_TYPE "jitlink"
28 return "Pointer32Signed";
42 return "Delta64FromGOT";
46 return "BranchPCRel32";
48 return "BranchPCRel32ToPtrJumpStub";
50 return "BranchPCRel32ToPtrJumpStubBypassable";
52 return "RequestGOTAndTransformToDelta32";
54 return "RequestGOTAndTransformToDelta64";
56 return "RequestGOTAndTransformToDelta64FromGOT";
58 return "PCRel32GOTLoadREXRelaxable";
60 return "RequestGOTAndTransformToPCRel32GOTLoadREXRelaxable";
62 return "PCRel32GOTLoadRelaxable";
64 return "RequestGOTAndTransformToPCRel32GOTLoadRelaxable";
66 return "PCRel32TLVPLoadREXRelaxable";
68 return "RequestTLVPAndTransformToPCRel32TLVPLoadREXRelaxable";
75 0x00, 0x00, 0x00, 0x00};
78 static_cast<char>(0xFFu), 0x25, 0x00, 0x00, 0x00, 0x00};
83 for (
auto *
B :
G.blocks())
84 for (
auto &
E :
B->edges()) {
89 assert(
E.getOffset() >= (REXPrefix ? 3u : 2u) &&
90 "GOT edge occurs too early in block");
92 auto *FixupData =
reinterpret_cast<uint8_t *
>(
93 const_cast<char *
>(
B->getContent().data())) +
95 const uint8_t
Op = FixupData[-2];
96 const uint8_t ModRM = FixupData[-1];
98 auto &GOTEntryBlock =
E.getTarget().getBlock();
99 assert(GOTEntryBlock.getSize() ==
G.getPointerSize() &&
100 "GOT entry block should be pointer sized");
101 assert(GOTEntryBlock.edges_size() == 1 &&
102 "GOT entry should only have one outgoing edge");
103 auto &GOTTarget = GOTEntryBlock.edges().begin()->getTarget();
106 int64_t Displacement = TargetAddr - EdgeAddr + 4;
107 bool TargetInRangeForImmU32 = isUInt<32>(TargetAddr.
getValue());
108 bool DisplacementInRangeForImmS32 = isInt<32>(Displacement);
112 if (!(TargetInRangeForImmU32 || DisplacementInRangeForImmS32))
116 if (
Op == 0x8b && DisplacementInRangeForImmS32) {
117 FixupData[-2] = 0x8d;
119 E.setTarget(GOTTarget);
120 E.setAddend(
E.getAddend() - 4);
122 dbgs() <<
" Replaced GOT load wih LEA:\n ";
130 if (
Op == 0xff && TargetInRangeForImmU32) {
135 FixupData[-2] = 0x67;
136 FixupData[-1] = 0xe8;
138 dbgs() <<
" replaced call instruction's memory operand wih imm "
145 assert(ModRM == 0x25 &&
"Invalid ModRm for call/jmp instructions");
146 FixupData[-2] = 0xe9;
148 E.setOffset(
E.getOffset() - 1);
150 dbgs() <<
" replaced jmp instruction's memory operand wih imm "
157 E.setTarget(GOTTarget);
161 auto &StubBlock =
E.getTarget().getBlock();
163 "Stub block should be stub sized");
164 assert(StubBlock.edges_size() == 1 &&
165 "Stub block should only have one outgoing edge");
167 auto &GOTBlock = StubBlock.edges().begin()->getTarget().getBlock();
168 assert(GOTBlock.getSize() ==
G.getPointerSize() &&
169 "GOT block should be pointer sized");
170 assert(GOTBlock.edges_size() == 1 &&
171 "GOT block should only have one outgoing edge");
173 auto &GOTTarget = GOTBlock.edges().begin()->getTarget();
177 int64_t Displacement = TargetAddr - EdgeAddr + 4;
178 if (isInt<32>(Displacement)) {
180 E.setTarget(GOTTarget);
182 dbgs() <<
" Replaced stub branch with direct branch:\n ";
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())
This class represents an Operation in the Expression.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Represents an address in the executor process.
uint64_t getValue() const
const char * getEdgeKindName(Edge::Kind K)
Returns a string name for the given x86-64 edge.
constexpr uint64_t PointerSize
x86_64 pointer size.
const char NullPointerContent[PointerSize]
x86-64 null pointer content.
Error optimizeGOTAndStubAccesses(LinkGraph &G)
Optimize the GOT and Stub relocations if the edge target address is in range.
const char PointerJumpStubContent[6]
x86-64 pointer jump stub content.
@ Delta64FromGOT
A 64-bit GOT delta.
@ Pointer32
A plain 32-bit pointer value relocation.
@ RequestGOTAndTransformToDelta32
A GOT entry getter/constructor, transformed to Delta32 pointing at the GOT entry for the original tar...
@ Pointer8
A plain 8-bit pointer value relocation.
@ PCRel32GOTLoadRelaxable
A PC-relative load of a GOT entry, relaxable if GOT entry target is in-range of the fixup.
@ Pointer32Signed
A signed 32-bit pointer value relocation.
@ BranchPCRel32
A 32-bit PC-relative branch.
@ RequestGOTAndTransformToDelta64
A GOT entry getter/constructor, transformed to Delta64 pointing at the GOT entry for the original tar...
@ RequestTLVPAndTransformToPCRel32TLVPLoadREXRelaxable
A TLVP entry getter/constructor, transformed to Delta32ToTLVPLoadREXRelaxable.
@ RequestGOTAndTransformToDelta64FromGOT
A GOT entry offset within GOT getter/constructor, transformed to Delta64FromGOT pointing at the GOT e...
@ PCRel32TLVPLoadREXRelaxable
A PC-relative REX load of a Thread Local Variable Pointer (TLVP) entry, relaxable if the TLVP entry t...
@ PCRel32
A 32-bit PC-relative relocation.
@ PCRel32GOTLoadREXRelaxable
A PC-relative REX load of a GOT entry, relaxable if GOT entry target is in-range of the fixup.
@ NegDelta64
A 64-bit negative delta.
@ Pointer16
A plain 16-bit pointer value relocation.
@ RequestGOTAndTransformToPCRel32GOTLoadRelaxable
A GOT entry getter/constructor, transformed to PCRel32ToGOTLoadRelaxable pointing at the GOT entry fo...
@ Pointer64
A plain 64-bit pointer value relocation.
@ BranchPCRel32ToPtrJumpStub
A 32-bit PC-relative branch to a pointer jump stub.
@ RequestGOTAndTransformToPCRel32GOTLoadREXRelaxable
A GOT entry getter/constructor, transformed to PCRel32ToGOTLoadREXRelaxable pointing at the GOT entry...
@ BranchPCRel32ToPtrJumpStubBypassable
A relaxable version of BranchPCRel32ToPtrJumpStub.
@ NegDelta32
A 32-bit negative delta.
const char * getGenericEdgeKindName(Edge::Kind K)
Returns the string name of the given generic edge kind, or "unknown" otherwise.
void printEdge(raw_ostream &OS, const Block &B, const Edge &E, StringRef EdgeKindName)
This is an optimization pass for GlobalISel generic memory operations.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.