From e96a490d7a0e224961d37f60f85e8556a64ed2b1 Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Sat, 8 Nov 2008 01:31:27 +0000 Subject: [PATCH] Handle ARM machine constantpool entry with non-lazy ptr. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58882 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/ARM/ARMCodeEmitter.cpp | 9 +++++++-- lib/Target/ARM/ARMJITInfo.cpp | 15 +++++++++++---- lib/Target/ARM/ARMJITInfo.h | 6 ++++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/Target/ARM/ARMCodeEmitter.cpp b/lib/Target/ARM/ARMCodeEmitter.cpp index 32cf226c497..49d2cb0ae6e 100644 --- a/lib/Target/ARM/ARMCodeEmitter.cpp +++ b/lib/Target/ARM/ARMCodeEmitter.cpp @@ -336,8 +336,13 @@ void ARMCodeEmitter::emitConstPoolInstruction(const MachineInstr &MI) { GlobalValue *GV = ACPV->getGV(); if (GV) { assert(!ACPV->isStub() && "Don't know how to deal this yet!"); - emitGlobalAddress(GV, ARM::reloc_arm_machine_cp_entry, false, - (intptr_t)ACPV); + if (ACPV->isNonLazyPointer()) + MCE.addRelocation(MachineRelocation::getGVNonLazyPtr( + MCE.getCurrentPCOffset(), ARM::reloc_arm_machine_cp_entry, GV, + (intptr_t)ACPV, false)); + else + emitGlobalAddress(GV, ARM::reloc_arm_machine_cp_entry, + ACPV->isStub(), (intptr_t)ACPV); } else { assert(!ACPV->isNonLazyPointer() && "Don't know how to deal this yet!"); emitExternalSymbolAddress(ACPV->getSymbol(), ARM::reloc_arm_absolute); diff --git a/lib/Target/ARM/ARMJITInfo.cpp b/lib/Target/ARM/ARMJITInfo.cpp index c0b878251ba..4118d6de211 100644 --- a/lib/Target/ARM/ARMJITInfo.cpp +++ b/lib/Target/ARM/ARMJITInfo.cpp @@ -133,14 +133,21 @@ ARMJITInfo::getLazyResolverFunction(JITCompilerFn F) { return ARMCompilationCallback; } +void *ARMJITInfo::emitGlobalValueNonLazyPtr(const GlobalValue *GV, void *Ptr, + MachineCodeEmitter &MCE) { + MCE.startFunctionStub(GV, 4, 4); // FIXME: Rename this. + MCE.emitWordLE((intptr_t)Ptr); + return MCE.finishFunctionStub(GV); +} + void *ARMJITInfo::emitFunctionStub(const Function* F, void *Fn, MachineCodeEmitter &MCE) { unsigned addr = (intptr_t)Fn; // If this is just a call to an external function, emit a branch instead of a // call. The code is the same except for one bit of the last instruction. if (Fn != (void*)(intptr_t)ARMCompilationCallback) { - // branch to the corresponding function addr - // the stub is 8-byte size and 4-aligned + // Branch to the corresponding function addr. + // The stub is 8-byte size and 4-aligned. MCE.startFunctionStub(F, 8, 4); MCE.emitWordLE(0xe51ff004); // LDR PC, [PC,#-4] MCE.emitWordLE(addr); // addr of function @@ -150,8 +157,8 @@ void *ARMJITInfo::emitFunctionStub(const Function* F, void *Fn, // This stub sets the return address to restart the stub, so that // the new branch will be invoked when we come back. // - // branch and link to the compilation callback. - // the stub is 16-byte size and 4-byte aligned. + // Branch and link to the compilation callback. + // The stub is 16-byte size and 4-byte aligned. MCE.startFunctionStub(F, 16, 4); // Save LR so the callback can determine which stub called it. // The compilation callback is responsible for popping this prior diff --git a/lib/Target/ARM/ARMJITInfo.h b/lib/Target/ARM/ARMJITInfo.h index 3610a6e479f..91d51b4b5b7 100644 --- a/lib/Target/ARM/ARMJITInfo.h +++ b/lib/Target/ARM/ARMJITInfo.h @@ -49,6 +49,12 @@ namespace llvm { /// virtual void replaceMachineCodeForFunction(void *Old, void *New); + /// emitGlobalValueNonLazyPtr - Use the specified MachineCodeEmitter object + /// to emit a Mac OS X non-lazy pointer which contains the address of the + /// specified ptr. + virtual void *emitGlobalValueNonLazyPtr(const GlobalValue *GV, void *Ptr, + MachineCodeEmitter &MCE); + /// emitFunctionStub - Use the specified MachineCodeEmitter object to emit a /// small native function that simply calls the function at the specified /// address.