[llvm-commits] [llvm] r59006 - in /llvm/trunk/lib/Target/ARM: ARMJITInfo.cpp ARMJITInfo.h
Evan Cheng
evan.cheng at apple.com
Mon Nov 10 15:14:52 PST 2008
Author: evancheng
Date: Mon Nov 10 17:14:47 2008
New Revision: 59006
URL: http://llvm.org/viewvc/llvm-project?rev=59006&view=rev
Log:
Correct PIC function stub codegen.
Modified:
llvm/trunk/lib/Target/ARM/ARMJITInfo.cpp
llvm/trunk/lib/Target/ARM/ARMJITInfo.h
Modified: llvm/trunk/lib/Target/ARM/ARMJITInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMJITInfo.cpp?rev=59006&r1=59005&r2=59006&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMJITInfo.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMJITInfo.cpp Mon Nov 10 17:14:47 2008
@@ -19,6 +19,7 @@
#include "llvm/Function.h"
#include "llvm/CodeGen/MachineCodeEmitter.h"
#include "llvm/Config/alloca.h"
+#include "llvm/Support/Debug.h"
#include "llvm/Support/Streams.h"
#include "llvm/System/Memory.h"
#include <cstdlib>
@@ -133,7 +134,9 @@
MachineCodeEmitter &MCE) {
MCE.startGVStub(GV, 4, 4);
MCE.emitWordLE((intptr_t)Ptr);
- return MCE.finishGVStub(GV);
+ void *PtrAddr = MCE.finishGVStub(GV);
+ addIndirectSymAddr(Ptr, (intptr_t)PtrAddr);
+ return PtrAddr;
}
void *ARMJITInfo::emitFunctionStub(const Function* F, void *Fn,
@@ -142,12 +145,34 @@
// 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.
- MCE.startGVStub(F, 8, 4);
- intptr_t Addr = (intptr_t)MCE.getCurrentPCValue();
- MCE.emitWordLE(0xe51ff004); // ldr pc, [pc, #-4]
- MCE.emitWordLE((intptr_t)Fn); // addr of function
- sys::Memory::InvalidateInstructionCache((void*)Addr, 8);
+ if (IsPIC) {
+ // The stub is 8-byte size and 4-aligned.
+ intptr_t LazyPtr = getIndirectSymAddr(Fn);
+ if (!LazyPtr) {
+ // In PIC mode, the function stub is loading a lazy-ptr.
+ LazyPtr= (intptr_t)emitGlobalValueIndirectSym((GlobalValue*)F, Fn, MCE);
+ if (F)
+ DOUT << "JIT: Indirect symbol emitted at [" << LazyPtr << "] for GV '"
+ << F->getName() << "'\n";
+ else
+ DOUT << "JIT: Stub emitted at [" << LazyPtr
+ << "] for external function at '" << Fn << "'\n";
+ }
+ MCE.startGVStub(F, 16, 4);
+ intptr_t Addr = (intptr_t)MCE.getCurrentPCValue();
+ MCE.emitWordLE(0xe59fc004); // ldr pc, [pc, #+4]
+ MCE.emitWordLE(0xe08fc00c); // L_func$scv: add ip, pc, ip
+ MCE.emitWordLE(0xe59cf000); // ldr pc, [ip]
+ MCE.emitWordLE(LazyPtr - (Addr+4+8)); // func - (L_func$scv+8)
+ sys::Memory::InvalidateInstructionCache((void*)Addr, 16);
+ } else {
+ // The stub is 8-byte size and 4-aligned.
+ MCE.startGVStub(F, 8, 4);
+ intptr_t Addr = (intptr_t)MCE.getCurrentPCValue();
+ MCE.emitWordLE(0xe51ff004); // ldr pc, [pc, #-4]
+ MCE.emitWordLE((intptr_t)Fn); // addr of function
+ sys::Memory::InvalidateInstructionCache((void*)Addr, 8);
+ }
} else {
// The compilation callback will overwrite the first two words of this
// stub with indirect branch instructions targeting the compiled code.
Modified: llvm/trunk/lib/Target/ARM/ARMJITInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMJITInfo.h?rev=59006&r1=59005&r2=59006&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMJITInfo.h (original)
+++ llvm/trunk/lib/Target/ARM/ARMJITInfo.h Mon Nov 10 17:14:47 2008
@@ -37,6 +37,10 @@
// PCLabelMap - A map from PC labels to addresses.
DenseMap<unsigned, intptr_t> PCLabelMap;
+ // Sym2IndirectSymMap - A map from symbol (GlobalValue and ExternalSymbol)
+ // addresses to their indirect symbol addresses.
+ DenseMap<void*, intptr_t> Sym2IndirectSymMap;
+
// IsPIC - True if the relocation model is PIC. This is used to determine
// how to codegen function stubs.
bool IsPIC;
@@ -147,6 +151,22 @@
PCLabelMap.insert(std::make_pair(Id, Addr));
}
+ /// getIndirectSymAddr - Retrieve the address of the indirect symbol of the
+ /// specified symbol located at address. Returns 0 if the indirect symbol
+ /// has not been emitted.
+ intptr_t getIndirectSymAddr(void *Addr) const {
+ DenseMap<void*,intptr_t>::const_iterator I= Sym2IndirectSymMap.find(Addr);
+ if (I != Sym2IndirectSymMap.end())
+ return I->second;
+ return 0;
+ }
+
+ /// addIndirectSymAddr - Add a mapping from address of an emitted symbol to
+ /// its indirect symbol address.
+ void addIndirectSymAddr(void *SymAddr, intptr_t IndSymAddr) {
+ Sym2IndirectSymMap.insert(std::make_pair(SymAddr, IndSymAddr));
+ }
+
private:
/// resolveRelocDestAddr - Resolve the resulting address of the relocation
/// if it's not already solved. Constantpool entries must be resolved by
More information about the llvm-commits
mailing list