15#define DEBUG_TYPE "jitlink"
28 return "Pointer32Signed";
40 return "Delta64FromGOT";
44 return "BranchPCRel32";
46 return "BranchPCRel32ToPtrJumpStub";
48 return "BranchPCRel32ToPtrJumpStubBypassable";
50 return "RequestGOTAndTransformToDelta32";
52 return "RequestGOTAndTransformToDelta64";
54 return "RequestGOTAndTransformToDelta64FromGOT";
56 return "PCRel32GOTLoadREXRelaxable";
58 return "RequestGOTAndTransformToPCRel32GOTLoadREXRelaxable";
60 return "PCRel32GOTLoadRelaxable";
62 return "RequestGOTAndTransformToPCRel32GOTLoadRelaxable";
64 return "PCRel32TLVPLoadREXRelaxable";
66 return "RequestTLVPAndTransformToPCRel32TLVPLoadREXRelaxable";
73 0x00, 0x00, 0x00, 0x00};
76 static_cast<char>(0xFFu), 0x25, 0x00, 0x00, 0x00, 0x00};
81 for (
auto *
B :
G.blocks())
82 for (
auto &
E :
B->edges()) {
87 assert(
E.getOffset() >= (REXPrefix ? 3u : 2u) &&
88 "GOT edge occurs too early in block");
90 auto *FixupData =
reinterpret_cast<uint8_t *
>(
91 const_cast<char *
>(
B->getContent().data())) +
93 const uint8_t Op = FixupData[-2];
94 const uint8_t ModRM = FixupData[-1];
96 auto &GOTEntryBlock =
E.getTarget().getBlock();
97 assert(GOTEntryBlock.getSize() ==
G.getPointerSize() &&
98 "GOT entry block should be pointer sized");
99 assert(GOTEntryBlock.edges_size() == 1 &&
100 "GOT entry should only have one outgoing edge");
101 auto &GOTTarget = GOTEntryBlock.edges().begin()->getTarget();
104 int64_t Displacement = TargetAddr - EdgeAddr + 4;
110 if (!(TargetInRangeForImmU32 || DisplacementInRangeForImmS32))
114 if (Op == 0x8b && DisplacementInRangeForImmS32) {
115 FixupData[-2] = 0x8d;
117 E.setTarget(GOTTarget);
118 E.setAddend(
E.getAddend() - 4);
120 dbgs() <<
" Replaced GOT load wih LEA:\n ";
128 if (Op == 0xff && TargetInRangeForImmU32) {
133 FixupData[-2] = 0x67;
134 FixupData[-1] = 0xe8;
136 dbgs() <<
" replaced call instruction's memory operand wih imm "
143 assert(ModRM == 0x25 &&
"Invalid ModRm for call/jmp instructions");
144 FixupData[-2] = 0xe9;
146 E.setOffset(
E.getOffset() - 1);
148 dbgs() <<
" replaced jmp instruction's memory operand wih imm "
155 E.setTarget(GOTTarget);
159 auto &StubBlock =
E.getTarget().getBlock();
161 "Stub block should be stub sized");
162 assert(StubBlock.edges_size() == 1 &&
163 "Stub block should only have one outgoing edge");
165 auto &GOTBlock = StubBlock.edges().begin()->getTarget().getBlock();
166 assert(GOTBlock.getSize() ==
G.getPointerSize() &&
167 "GOT block should be pointer sized");
168 assert(GOTBlock.edges_size() == 1 &&
169 "GOT block should only have one outgoing edge");
171 auto &GOTTarget = GOTBlock.edges().begin()->getTarget();
175 int64_t Displacement = TargetAddr - EdgeAddr + 4;
178 E.setTarget(GOTTarget);
180 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())
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
bool isInRangeForImmS32(int64_t Value)
Returns true if the given int64_t value is in range for an int32_t.
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.
bool isInRangeForImmU32(uint64_t Value)
Returns true if the given uint64_t value is in range for a uint32_t.
@ 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...
@ 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.