15#define DEBUG_TYPE "jitlink"
28 return "Pointer32Signed";
44 return "Delta64FromGOT";
48 return "BranchPCRel32";
50 return "BranchPCRel32ToPtrJumpStub";
52 return "BranchPCRel32ToPtrJumpStubBypassable";
54 return "RequestGOTAndTransformToDelta32";
56 return "RequestGOTAndTransformToDelta64";
58 return "RequestGOTAndTransformToDelta64FromGOT";
60 return "PCRel32GOTLoadREXRelaxable";
62 return "RequestGOTAndTransformToPCRel32GOTLoadREXRelaxable";
64 return "PCRel32GOTLoadRelaxable";
66 return "RequestGOTAndTransformToPCRel32GOTLoadRelaxable";
68 return "PCRel32TLVPLoadREXRelaxable";
70 return "RequestTLVPAndTransformToPCRel32TLVPLoadREXRelaxable";
77 0x00, 0x00, 0x00, 0x00};
80 static_cast<char>(0xFFu), 0x25, 0x00, 0x00, 0x00, 0x00};
85 for (
auto *
B :
G.blocks())
86 for (
auto &
E :
B->edges()) {
91 assert(
E.getOffset() >= (REXPrefix ? 3u : 2u) &&
92 "GOT edge occurs too early in block");
94 auto *FixupData =
reinterpret_cast<uint8_t *
>(
95 const_cast<char *
>(
B->getContent().data())) +
97 const uint8_t
Op = FixupData[-2];
98 const uint8_t ModRM = FixupData[-1];
100 auto &GOTEntryBlock =
E.getTarget().getBlock();
101 assert(GOTEntryBlock.getSize() ==
G.getPointerSize() &&
102 "GOT entry block should be pointer sized");
103 assert(GOTEntryBlock.edges_size() == 1 &&
104 "GOT entry should only have one outgoing edge");
105 auto &GOTTarget = GOTEntryBlock.edges().begin()->getTarget();
108 int64_t Displacement = TargetAddr - EdgeAddr + 4;
109 bool TargetInRangeForImmU32 = isUInt<32>(TargetAddr.
getValue());
110 bool DisplacementInRangeForImmS32 = isInt<32>(Displacement);
114 if (!(TargetInRangeForImmU32 || DisplacementInRangeForImmS32))
118 if (
Op == 0x8b && DisplacementInRangeForImmS32) {
119 FixupData[-2] = 0x8d;
121 E.setTarget(GOTTarget);
122 E.setAddend(
E.getAddend() - 4);
124 dbgs() <<
" Replaced GOT load wih LEA:\n ";
132 if (
Op == 0xff && TargetInRangeForImmU32) {
137 FixupData[-2] = 0x67;
138 FixupData[-1] = 0xe8;
140 dbgs() <<
" replaced call instruction's memory operand wih imm "
147 assert(ModRM == 0x25 &&
"Invalid ModRm for call/jmp instructions");
148 FixupData[-2] = 0xe9;
150 E.setOffset(
E.getOffset() - 1);
152 dbgs() <<
" replaced jmp instruction's memory operand wih imm "
159 E.setTarget(GOTTarget);
163 auto &StubBlock =
E.getTarget().getBlock();
165 "Stub block should be stub sized");
166 assert(StubBlock.edges_size() == 1 &&
167 "Stub block should only have one outgoing edge");
169 auto &GOTBlock = StubBlock.edges().begin()->getTarget().getBlock();
170 assert(GOTBlock.getSize() ==
G.getPointerSize() &&
171 "GOT block should be pointer sized");
172 assert(GOTBlock.edges_size() == 1 &&
173 "GOT block should only have one outgoing edge");
175 auto &GOTTarget = GOTBlock.edges().begin()->getTarget();
179 int64_t Displacement = TargetAddr - EdgeAddr + 4;
180 if (isInt<32>(Displacement)) {
182 E.setTarget(GOTTarget);
184 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.