Skip to content

Commit 30d355a

Browse files
committed
Merge 81422 from mainline.
Proper support of non-lazy indirect symbols. llvm-svn: 81648
1 parent cdf29d8 commit 30d355a

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

llvm/lib/Target/ARM/ARMCodeEmitter.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ namespace {
6060
ARMJITInfo *JTI;
6161
const ARMInstrInfo *II;
6262
const TargetData *TD;
63+
const ARMSubtarget *Subtarget;
6364
TargetMachine &TM;
6465
CodeEmitter &MCE;
6566
const std::vector<MachineConstantPoolEntry> *MCPEs;
@@ -163,7 +164,7 @@ namespace {
163164
/// Routines that handle operands which add machine relocations which are
164165
/// fixed up by the relocation stage.
165166
void emitGlobalAddress(GlobalValue *GV, unsigned Reloc,
166-
bool NeedStub, intptr_t ACPV = 0);
167+
bool NeedStub, bool Indirect, intptr_t ACPV = 0);
167168
void emitExternalSymbolAddress(const char *ES, unsigned Reloc);
168169
void emitConstPoolAddress(unsigned CPI, unsigned Reloc);
169170
void emitJumpTableAddress(unsigned JTIndex, unsigned Reloc);
@@ -195,9 +196,10 @@ bool Emitter<CodeEmitter>::runOnMachineFunction(MachineFunction &MF) {
195196
assert((MF.getTarget().getRelocationModel() != Reloc::Default ||
196197
MF.getTarget().getRelocationModel() != Reloc::Static) &&
197198
"JIT relocation model must be set to static or default!");
199+
JTI = ((ARMTargetMachine&)MF.getTarget()).getJITInfo();
198200
II = ((ARMTargetMachine&)MF.getTarget()).getInstrInfo();
199201
TD = ((ARMTargetMachine&)MF.getTarget()).getTargetData();
200-
JTI = ((ARMTargetMachine&)MF.getTarget()).getJITInfo();
202+
Subtarget = &TM.getSubtarget<ARMSubtarget>();
201203
MCPEs = &MF.getConstantPool()->getConstants();
202204
MJTEs = &MF.getJumpTableInfo()->getJumpTables();
203205
IsPIC = TM.getRelocationModel() == Reloc::PIC_;
@@ -244,7 +246,7 @@ unsigned Emitter<CodeEmitter>::getMachineOpValue(const MachineInstr &MI,
244246
else if (MO.isImm())
245247
return static_cast<unsigned>(MO.getImm());
246248
else if (MO.isGlobal())
247-
emitGlobalAddress(MO.getGlobal(), ARM::reloc_arm_branch, true);
249+
emitGlobalAddress(MO.getGlobal(), ARM::reloc_arm_branch, true, false);
248250
else if (MO.isSymbol())
249251
emitExternalSymbolAddress(MO.getSymbolName(), ARM::reloc_arm_branch);
250252
else if (MO.isCPI()) {
@@ -270,9 +272,14 @@ unsigned Emitter<CodeEmitter>::getMachineOpValue(const MachineInstr &MI,
270272
///
271273
template<class CodeEmitter>
272274
void Emitter<CodeEmitter>::emitGlobalAddress(GlobalValue *GV, unsigned Reloc,
273-
bool NeedStub, intptr_t ACPV) {
274-
MCE.addRelocation(MachineRelocation::getGV(MCE.getCurrentPCOffset(), Reloc,
275-
GV, ACPV, NeedStub));
275+
bool NeedStub, bool Indirect,
276+
intptr_t ACPV) {
277+
MachineRelocation MR = Indirect
278+
? MachineRelocation::getIndirectSymbol(MCE.getCurrentPCOffset(), Reloc,
279+
GV, ACPV, NeedStub)
280+
: MachineRelocation::getGV(MCE.getCurrentPCOffset(), Reloc,
281+
GV, ACPV, NeedStub);
282+
MCE.addRelocation(MR);
276283
}
277284

278285
/// emitExternalSymbolAddress - Arrange for the address of an external symbol to
@@ -423,8 +430,11 @@ void Emitter<CodeEmitter>::emitConstPoolInstruction(const MachineInstr &MI) {
423430

424431
GlobalValue *GV = ACPV->getGV();
425432
if (GV) {
433+
Reloc::Model RelocM = TM.getRelocationModel();
426434
emitGlobalAddress(GV, ARM::reloc_arm_machine_cp_entry,
427-
isa<Function>(GV), (intptr_t)ACPV);
435+
isa<Function>(GV),
436+
Subtarget->GVIsIndirectSymbol(GV, RelocM),
437+
(intptr_t)ACPV);
428438
} else {
429439
emitExternalSymbolAddress(ACPV->getSymbol(), ARM::reloc_arm_absolute);
430440
}
@@ -443,7 +453,7 @@ void Emitter<CodeEmitter>::emitConstPoolInstruction(const MachineInstr &MI) {
443453
});
444454

445455
if (GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
446-
emitGlobalAddress(GV, ARM::reloc_arm_absolute, isa<Function>(GV));
456+
emitGlobalAddress(GV, ARM::reloc_arm_absolute, isa<Function>(GV), false);
447457
emitWordLE(0);
448458
} else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
449459
uint32_t Val = *(uint32_t*)CI->getValue().getRawData();

llvm/lib/Target/ARM/ARMJITInfo.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ void *ARMJITInfo::emitGlobalValueIndirectSym(const GlobalValue *GV, void *Ptr,
147147
llvm_unreachable("ERROR: Unable to mark indirect symbol writable");
148148
}
149149
JCE.emitWordLE((intptr_t)Ptr);
150+
if (!sys::Memory::setRangeExecutable((void*)Addr, 4)) {
151+
llvm_unreachable("ERROR: Unable to mark indirect symbol executable");
152+
}
150153
void *PtrAddr = JCE.finishGVStub(GV);
151154
addIndirectSymAddr(Ptr, (intptr_t)PtrAddr);
152155
return PtrAddr;

0 commit comments

Comments
 (0)