15#define DEBUG_TYPE "jitlink"
28 return "Pointer32Signed";
50 return "Delta64FromGOT";
54 return "BranchPCRel32";
56 return "BranchPCRel32ToPtrJumpStub";
58 return "BranchPCRel32ToPtrJumpStubBypassable";
60 return "RequestGOTAndTransformToDelta32";
62 return "RequestGOTAndTransformToDelta64";
64 return "RequestGOTAndTransformToDelta64FromGOT";
66 return "PCRel32GOTLoadREXRelaxable";
68 return "RequestGOTAndTransformToPCRel32GOTLoadREXRelaxable";
70 return "PCRel32GOTLoadRelaxable";
72 return "RequestGOTAndTransformToPCRel32GOTLoadRelaxable";
74 return "PCRel32TLVPLoadREXRelaxable";
76 return "RequestTLVPAndTransformToPCRel32TLVPLoadREXRelaxable";
83 0x00, 0x00, 0x00, 0x00};
86 static_cast<char>(0xFFu), 0x25, 0x00, 0x00, 0x00, 0x00};
89 static_cast<char>(0xe8), 0x00, 0x00, 0x00, 0x00
95 for (
auto *
B :
G.blocks())
96 for (
auto &
E :
B->edges()) {
101 assert(
E.getOffset() >= (REXPrefix ? 3u : 2u) &&
102 "GOT edge occurs too early in block");
104 auto *FixupData =
reinterpret_cast<uint8_t *
>(
105 const_cast<char *
>(
B->getContent().data())) +
108 const uint8_t ModRM = FixupData[-1];
110 auto &GOTEntryBlock =
E.getTarget().getBlock();
111 assert(GOTEntryBlock.getSize() ==
G.getPointerSize() &&
112 "GOT entry block should be pointer sized");
113 assert(GOTEntryBlock.edges_size() == 1 &&
114 "GOT entry should only have one outgoing edge");
115 auto &GOTTarget = GOTEntryBlock.edges().begin()->getTarget();
118 int64_t Displacement = TargetAddr - EdgeAddr + 4;
119 bool TargetInRangeForImmU32 = isUInt<32>(TargetAddr.
getValue());
120 bool DisplacementInRangeForImmS32 = isInt<32>(Displacement);
124 if (!(TargetInRangeForImmU32 || DisplacementInRangeForImmS32))
128 if (
Op == 0x8b && DisplacementInRangeForImmS32) {
129 FixupData[-2] = 0x8d;
131 E.setTarget(GOTTarget);
132 E.setAddend(
E.getAddend() - 4);
134 dbgs() <<
" Replaced GOT load wih LEA:\n ";
142 if (
Op == 0xff && TargetInRangeForImmU32) {
147 FixupData[-2] = 0x67;
148 FixupData[-1] = 0xe8;
150 dbgs() <<
" replaced call instruction's memory operand wih imm "
157 assert(ModRM == 0x25 &&
"Invalid ModRm for call/jmp instructions");
158 FixupData[-2] = 0xe9;
160 E.setOffset(
E.getOffset() - 1);
162 dbgs() <<
" replaced jmp instruction's memory operand wih imm "
169 E.setTarget(GOTTarget);
173 auto &StubBlock =
E.getTarget().getBlock();
175 "Stub block should be stub sized");
176 assert(StubBlock.edges_size() == 1 &&
177 "Stub block should only have one outgoing edge");
179 auto &GOTBlock = StubBlock.edges().begin()->getTarget().getBlock();
180 assert(GOTBlock.getSize() ==
G.getPointerSize() &&
181 "GOT block should be pointer sized");
182 assert(GOTBlock.edges_size() == 1 &&
183 "GOT block should only have one outgoing edge");
185 auto &GOTTarget = GOTBlock.edges().begin()->getTarget();
189 int64_t Displacement = TargetAddr - EdgeAddr + 4;
190 if (isInt<32>(Displacement)) {
192 E.setTarget(GOTTarget);
194 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 ReentryTrampolineContent[5]
x86-64 reentry trampoline.
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.
@ Size64
A 64-bit size relocation.
@ 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.
@ Size32
A 32-bit size 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.