2007-07-05 21:15:40 +00:00
|
|
|
//===-- ARMJITInfo.cpp - Implement the JIT interfaces for the ARM target --===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-07-05 21:15:40 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the JIT interfaces for the ARM target.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "jit"
|
|
|
|
#include "ARMJITInfo.h"
|
2008-11-12 01:02:24 +00:00
|
|
|
#include "ARMInstrInfo.h"
|
2008-11-04 00:50:32 +00:00
|
|
|
#include "ARMConstantPoolValue.h"
|
2007-07-05 21:15:40 +00:00
|
|
|
#include "ARMRelocations.h"
|
|
|
|
#include "ARMSubtarget.h"
|
2008-04-16 20:46:05 +00:00
|
|
|
#include "llvm/Function.h"
|
2009-05-30 20:51:52 +00:00
|
|
|
#include "llvm/CodeGen/JITCodeEmitter.h"
|
2008-11-10 23:14:47 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-07-08 18:01:40 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-07-25 00:23:56 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2008-10-20 21:39:23 +00:00
|
|
|
#include "llvm/System/Memory.h"
|
2007-07-05 21:15:40 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
void ARMJITInfo::replaceMachineCodeForFunction(void *Old, void *New) {
|
2009-07-08 18:01:40 +00:00
|
|
|
llvm_report_error("ARMJITInfo::replaceMachineCodeForFunction");
|
2007-07-05 21:15:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// JITCompilerFunction - This contains the address of the JIT function used to
|
|
|
|
/// compile a function lazily.
|
|
|
|
static TargetJITInfo::JITCompilerFn JITCompilerFunction;
|
|
|
|
|
2008-09-02 07:49:03 +00:00
|
|
|
// Get the ASMPREFIX for the current host. This is often '_'.
|
|
|
|
#ifndef __USER_LABEL_PREFIX__
|
|
|
|
#define __USER_LABEL_PREFIX__
|
|
|
|
#endif
|
|
|
|
#define GETASMPREFIX2(X) #X
|
|
|
|
#define GETASMPREFIX(X) GETASMPREFIX2(X)
|
|
|
|
#define ASMPREFIX GETASMPREFIX(__USER_LABEL_PREFIX__)
|
|
|
|
|
2007-07-05 21:15:40 +00:00
|
|
|
// CompilationCallback stub - We can't use a C function with inline assembly in
|
2008-10-20 21:39:23 +00:00
|
|
|
// it, because we the prolog/epilog inserted by GCC won't work for us (we need
|
|
|
|
// to preserve more context and manipulate the stack directly). Instead,
|
2009-08-11 15:33:49 +00:00
|
|
|
// write our own wrapper, which does things our way, so we have complete
|
2008-10-20 21:39:23 +00:00
|
|
|
// control over register saving and restoring.
|
2007-07-05 21:15:40 +00:00
|
|
|
extern "C" {
|
|
|
|
#if defined(__arm__)
|
2009-08-12 22:10:57 +00:00
|
|
|
void ARMCompilationCallback();
|
2007-07-05 21:15:40 +00:00
|
|
|
asm(
|
|
|
|
".text\n"
|
|
|
|
".align 2\n"
|
2008-09-02 07:49:03 +00:00
|
|
|
".globl " ASMPREFIX "ARMCompilationCallback\n"
|
|
|
|
ASMPREFIX "ARMCompilationCallback:\n"
|
2008-10-20 21:39:23 +00:00
|
|
|
// Save caller saved registers since they may contain stuff
|
|
|
|
// for the real target function right now. We have to act as if this
|
|
|
|
// whole compilation callback doesn't exist as far as the caller is
|
|
|
|
// concerned, so we can't just preserve the callee saved regs.
|
2008-10-21 16:54:12 +00:00
|
|
|
"stmdb sp!, {r0, r1, r2, r3, lr}\n"
|
2009-01-16 02:16:37 +00:00
|
|
|
#ifndef __SOFTFP__
|
2008-11-13 23:28:54 +00:00
|
|
|
"fstmfdd sp!, {d0, d1, d2, d3, d4, d5, d6, d7}\n"
|
|
|
|
#endif
|
2008-10-20 21:39:23 +00:00
|
|
|
// The LR contains the address of the stub function on entry.
|
|
|
|
// pass it as the argument to the C part of the callback
|
|
|
|
"mov r0, lr\n"
|
|
|
|
"sub sp, sp, #4\n"
|
|
|
|
// Call the C portion of the callback
|
|
|
|
"bl " ASMPREFIX "ARMCompilationCallbackC\n"
|
|
|
|
"add sp, sp, #4\n"
|
|
|
|
// Restoring the LR to the return address of the function that invoked
|
|
|
|
// the stub and de-allocating the stack space for it requires us to
|
|
|
|
// swap the two saved LR values on the stack, as they're backwards
|
|
|
|
// for what we need since the pop instruction has a pre-determined
|
|
|
|
// order for the registers.
|
|
|
|
// +--------+
|
|
|
|
// 0 | LR | Original return address
|
2009-08-11 15:33:49 +00:00
|
|
|
// +--------+
|
2008-10-20 21:39:23 +00:00
|
|
|
// 1 | LR | Stub address (start of stub)
|
|
|
|
// 2-5 | R3..R0 | Saved registers (we need to preserve all regs)
|
2008-11-13 23:28:54 +00:00
|
|
|
// 6-20 | D0..D7 | Saved VFP registers
|
2009-08-11 15:33:49 +00:00
|
|
|
// +--------+
|
2008-10-20 21:39:23 +00:00
|
|
|
//
|
2009-01-16 02:16:37 +00:00
|
|
|
#ifndef __SOFTFP__
|
2008-11-13 23:28:54 +00:00
|
|
|
// Restore VFP caller-saved registers.
|
|
|
|
"fldmfdd sp!, {d0, d1, d2, d3, d4, d5, d6, d7}\n"
|
|
|
|
#endif
|
|
|
|
//
|
2008-10-20 21:39:23 +00:00
|
|
|
// We need to exchange the values in slots 0 and 1 so we can
|
|
|
|
// return to the address in slot 1 with the address in slot 0
|
|
|
|
// restored to the LR.
|
|
|
|
"ldr r0, [sp,#20]\n"
|
|
|
|
"ldr r1, [sp,#16]\n"
|
|
|
|
"str r1, [sp,#20]\n"
|
|
|
|
"str r0, [sp,#16]\n"
|
|
|
|
// Return to the (newly modified) stub to invoke the real function.
|
|
|
|
// The above twiddling of the saved return addresses allows us to
|
|
|
|
// deallocate everything, including the LR the stub saved, all in one
|
|
|
|
// pop instruction.
|
2008-10-21 16:54:12 +00:00
|
|
|
"ldmia sp!, {r0, r1, r2, r3, lr, pc}\n"
|
2008-09-02 07:49:03 +00:00
|
|
|
);
|
|
|
|
#else // Not an ARM host
|
2007-07-05 21:15:40 +00:00
|
|
|
void ARMCompilationCallback() {
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("Cannot call ARMCompilationCallback() on a non-ARM arch!");
|
2007-07-05 21:15:40 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-08-11 15:33:49 +00:00
|
|
|
/// ARMCompilationCallbackC - This is the target-specific function invoked
|
|
|
|
/// by the function stub when we did not know the real target of a call.
|
|
|
|
/// This function must locate the start of the stub or call site and pass
|
2008-10-20 21:39:23 +00:00
|
|
|
/// it into the JIT compiler function.
|
|
|
|
extern "C" void ARMCompilationCallbackC(intptr_t StubAddr) {
|
|
|
|
// Get the address of the compiled code for this function.
|
|
|
|
intptr_t NewVal = (intptr_t)JITCompilerFunction((void*)StubAddr);
|
2007-07-05 21:15:40 +00:00
|
|
|
|
|
|
|
// Rewrite the call target... so that we don't end up here every time we
|
2008-10-20 21:39:23 +00:00
|
|
|
// execute the call. We're replacing the first two instructions of the
|
|
|
|
// stub with:
|
|
|
|
// ldr pc, [pc,#-4]
|
|
|
|
// <addr>
|
2008-11-08 08:16:49 +00:00
|
|
|
if (!sys::Memory::setRangeWritable((void*)StubAddr, 8)) {
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("ERROR: Unable to mark stub writable");
|
2008-11-08 08:16:49 +00:00
|
|
|
}
|
|
|
|
*(intptr_t *)StubAddr = 0xe51ff004; // ldr pc, [pc, #-4]
|
2008-10-20 21:39:23 +00:00
|
|
|
*(intptr_t *)(StubAddr+4) = NewVal;
|
2008-11-08 08:16:49 +00:00
|
|
|
if (!sys::Memory::setRangeExecutable((void*)StubAddr, 8)) {
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("ERROR: Unable to mark stub executable");
|
2008-11-08 08:16:49 +00:00
|
|
|
}
|
2007-07-05 21:15:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TargetJITInfo::LazyResolverFn
|
|
|
|
ARMJITInfo::getLazyResolverFunction(JITCompilerFn F) {
|
|
|
|
JITCompilerFunction = F;
|
|
|
|
return ARMCompilationCallback;
|
|
|
|
}
|
|
|
|
|
2008-11-10 01:08:07 +00:00
|
|
|
void *ARMJITInfo::emitGlobalValueIndirectSym(const GlobalValue *GV, void *Ptr,
|
2009-05-30 20:51:52 +00:00
|
|
|
JITCodeEmitter &JCE) {
|
2009-12-15 22:42:46 +00:00
|
|
|
uint8_t Buffer[4];
|
|
|
|
uint8_t *Cur = Buffer;
|
|
|
|
MachineCodeEmitter::emitWordLEInto(Cur, (intptr_t)Ptr);
|
|
|
|
void *PtrAddr = JCE.allocIndirectGV(
|
|
|
|
GV, Buffer, sizeof(Buffer), /*Alignment=*/4);
|
2008-11-10 23:14:47 +00:00
|
|
|
addIndirectSymAddr(Ptr, (intptr_t)PtrAddr);
|
|
|
|
return PtrAddr;
|
2008-11-08 01:31:27 +00:00
|
|
|
}
|
|
|
|
|
2009-11-23 23:35:19 +00:00
|
|
|
TargetJITInfo::StubLayout ARMJITInfo::getStubLayout() {
|
|
|
|
// The stub contains up to 3 4-byte instructions, aligned at 4 bytes, and a
|
|
|
|
// 4-byte address. See emitFunctionStub for details.
|
|
|
|
StubLayout Result = {16, 4};
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2008-04-16 20:46:05 +00:00
|
|
|
void *ARMJITInfo::emitFunctionStub(const Function* F, void *Fn,
|
2009-05-30 20:51:52 +00:00
|
|
|
JITCodeEmitter &JCE) {
|
2009-11-23 23:35:19 +00:00
|
|
|
void *Addr;
|
2007-07-05 21:15:40 +00:00
|
|
|
// 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) {
|
2008-11-08 01:31:27 +00:00
|
|
|
// Branch to the corresponding function addr.
|
2008-11-10 23:14:47 +00:00
|
|
|
if (IsPIC) {
|
2009-11-23 23:35:19 +00:00
|
|
|
// The stub is 16-byte size and 4-aligned.
|
2008-11-10 23:14:47 +00:00
|
|
|
intptr_t LazyPtr = getIndirectSymAddr(Fn);
|
|
|
|
if (!LazyPtr) {
|
|
|
|
// In PIC mode, the function stub is loading a lazy-ptr.
|
2009-05-30 20:51:52 +00:00
|
|
|
LazyPtr= (intptr_t)emitGlobalValueIndirectSym((GlobalValue*)F, Fn, JCE);
|
2009-07-25 00:23:56 +00:00
|
|
|
DEBUG(if (F)
|
2009-08-11 15:33:49 +00:00
|
|
|
errs() << "JIT: Indirect symbol emitted at [" << LazyPtr
|
2009-07-25 00:23:56 +00:00
|
|
|
<< "] for GV '" << F->getName() << "'\n";
|
|
|
|
else
|
|
|
|
errs() << "JIT: Stub emitted at [" << LazyPtr
|
|
|
|
<< "] for external function at '" << Fn << "'\n");
|
2008-11-10 23:14:47 +00:00
|
|
|
}
|
2009-11-23 23:35:19 +00:00
|
|
|
JCE.emitAlignment(4);
|
|
|
|
Addr = (void*)JCE.getCurrentPCValue();
|
|
|
|
if (!sys::Memory::setRangeWritable(Addr, 16)) {
|
2009-09-09 01:56:29 +00:00
|
|
|
llvm_unreachable("ERROR: Unable to mark stub writable");
|
|
|
|
}
|
2009-11-20 00:21:55 +00:00
|
|
|
JCE.emitWordLE(0xe59fc004); // ldr ip, [pc, #+4]
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE.emitWordLE(0xe08fc00c); // L_func$scv: add ip, pc, ip
|
|
|
|
JCE.emitWordLE(0xe59cf000); // ldr pc, [ip]
|
2009-11-23 23:35:19 +00:00
|
|
|
JCE.emitWordLE(LazyPtr - (intptr_t(Addr)+4+8)); // func - (L_func$scv+8)
|
|
|
|
sys::Memory::InvalidateInstructionCache(Addr, 16);
|
|
|
|
if (!sys::Memory::setRangeExecutable(Addr, 16)) {
|
2009-09-09 01:56:29 +00:00
|
|
|
llvm_unreachable("ERROR: Unable to mark stub executable");
|
|
|
|
}
|
2008-11-10 23:14:47 +00:00
|
|
|
} else {
|
|
|
|
// The stub is 8-byte size and 4-aligned.
|
2009-11-23 23:35:19 +00:00
|
|
|
JCE.emitAlignment(4);
|
|
|
|
Addr = (void*)JCE.getCurrentPCValue();
|
|
|
|
if (!sys::Memory::setRangeWritable(Addr, 8)) {
|
2009-09-09 01:56:29 +00:00
|
|
|
llvm_unreachable("ERROR: Unable to mark stub writable");
|
|
|
|
}
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE.emitWordLE(0xe51ff004); // ldr pc, [pc, #-4]
|
|
|
|
JCE.emitWordLE((intptr_t)Fn); // addr of function
|
2009-11-23 23:35:19 +00:00
|
|
|
sys::Memory::InvalidateInstructionCache(Addr, 8);
|
|
|
|
if (!sys::Memory::setRangeExecutable(Addr, 8)) {
|
2009-09-09 01:56:29 +00:00
|
|
|
llvm_unreachable("ERROR: Unable to mark stub executable");
|
|
|
|
}
|
2008-11-10 23:14:47 +00:00
|
|
|
}
|
2007-07-05 21:15:40 +00:00
|
|
|
} else {
|
2008-10-20 21:39:23 +00:00
|
|
|
// The compilation callback will overwrite the first two words of this
|
2009-08-11 15:33:49 +00:00
|
|
|
// stub with indirect branch instructions targeting the compiled code.
|
2008-10-20 21:39:23 +00:00
|
|
|
// This stub sets the return address to restart the stub, so that
|
|
|
|
// the new branch will be invoked when we come back.
|
|
|
|
//
|
2008-11-08 01:31:27 +00:00
|
|
|
// Branch and link to the compilation callback.
|
|
|
|
// The stub is 16-byte size and 4-byte aligned.
|
2009-11-23 23:35:19 +00:00
|
|
|
JCE.emitAlignment(4);
|
|
|
|
Addr = (void*)JCE.getCurrentPCValue();
|
|
|
|
if (!sys::Memory::setRangeWritable(Addr, 16)) {
|
2009-09-09 01:56:29 +00:00
|
|
|
llvm_unreachable("ERROR: Unable to mark stub writable");
|
|
|
|
}
|
2008-10-20 21:39:23 +00:00
|
|
|
// Save LR so the callback can determine which stub called it.
|
|
|
|
// The compilation callback is responsible for popping this prior
|
|
|
|
// to returning.
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE.emitWordLE(0xe92d4000); // push {lr}
|
2008-11-08 08:16:49 +00:00
|
|
|
// Set the return address to go back to the start of this stub.
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE.emitWordLE(0xe24fe00c); // sub lr, pc, #12
|
2008-11-08 08:16:49 +00:00
|
|
|
// Invoke the compilation callback.
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE.emitWordLE(0xe51ff004); // ldr pc, [pc, #-4]
|
2008-11-08 08:16:49 +00:00
|
|
|
// The address of the compilation callback.
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE.emitWordLE((intptr_t)ARMCompilationCallback);
|
2009-11-23 23:35:19 +00:00
|
|
|
sys::Memory::InvalidateInstructionCache(Addr, 16);
|
|
|
|
if (!sys::Memory::setRangeExecutable(Addr, 16)) {
|
2009-09-09 01:56:29 +00:00
|
|
|
llvm_unreachable("ERROR: Unable to mark stub executable");
|
|
|
|
}
|
2007-07-05 21:15:40 +00:00
|
|
|
}
|
|
|
|
|
2009-11-23 23:35:19 +00:00
|
|
|
return Addr;
|
2007-07-05 21:15:40 +00:00
|
|
|
}
|
|
|
|
|
2008-11-07 09:06:08 +00:00
|
|
|
intptr_t ARMJITInfo::resolveRelocDestAddr(MachineRelocation *MR) const {
|
2008-11-04 00:50:32 +00:00
|
|
|
ARM::RelocationType RT = (ARM::RelocationType)MR->getRelocationType();
|
2008-11-12 01:02:24 +00:00
|
|
|
switch (RT) {
|
|
|
|
default:
|
|
|
|
return (intptr_t)(MR->getResultPointer());
|
|
|
|
case ARM::reloc_arm_pic_jt:
|
2008-11-07 22:30:53 +00:00
|
|
|
// Destination address - jump table base.
|
|
|
|
return (intptr_t)(MR->getResultPointer()) - MR->getConstantVal();
|
2008-11-12 01:02:24 +00:00
|
|
|
case ARM::reloc_arm_jt_base:
|
2008-11-07 22:30:53 +00:00
|
|
|
// Jump table base address.
|
2008-11-07 09:06:08 +00:00
|
|
|
return getJumpTableBaseAddr(MR->getJumpTableIndex());
|
2008-11-12 01:02:24 +00:00
|
|
|
case ARM::reloc_arm_cp_entry:
|
|
|
|
case ARM::reloc_arm_vfp_cp_entry:
|
2008-11-07 22:30:53 +00:00
|
|
|
// Constant pool entry address.
|
2008-11-04 00:50:32 +00:00
|
|
|
return getConstantPoolEntryAddr(MR->getConstantPoolIndex());
|
2008-11-12 01:02:24 +00:00
|
|
|
case ARM::reloc_arm_machine_cp_entry: {
|
2008-11-07 22:57:53 +00:00
|
|
|
ARMConstantPoolValue *ACPV = (ARMConstantPoolValue*)MR->getConstantVal();
|
2008-11-04 00:50:32 +00:00
|
|
|
assert((!ACPV->hasModifier() && !ACPV->mustAddCurrentAddress()) &&
|
|
|
|
"Can't handle this machine constant pool entry yet!");
|
|
|
|
intptr_t Addr = (intptr_t)(MR->getResultPointer());
|
|
|
|
Addr -= getPCLabelAddr(ACPV->getLabelId()) + ACPV->getPCAdjustment();
|
|
|
|
return Addr;
|
|
|
|
}
|
2008-11-12 01:02:24 +00:00
|
|
|
}
|
2008-11-04 00:50:32 +00:00
|
|
|
}
|
|
|
|
|
2007-07-05 21:15:40 +00:00
|
|
|
/// relocate - Before the JIT can run a block of code that has been emitted,
|
|
|
|
/// it must rewrite the code to contain the actual addresses of any
|
|
|
|
/// referenced global symbols.
|
|
|
|
void ARMJITInfo::relocate(void *Function, MachineRelocation *MR,
|
|
|
|
unsigned NumRelocs, unsigned char* GOTBase) {
|
2007-08-07 01:37:15 +00:00
|
|
|
for (unsigned i = 0; i != NumRelocs; ++i, ++MR) {
|
|
|
|
void *RelocPos = (char*)Function + MR->getMachineCodeOffset();
|
2008-11-07 09:06:08 +00:00
|
|
|
intptr_t ResultPtr = resolveRelocDestAddr(MR);
|
2007-08-07 01:37:15 +00:00
|
|
|
switch ((ARM::RelocationType)MR->getRelocationType()) {
|
2008-10-29 23:55:43 +00:00
|
|
|
case ARM::reloc_arm_cp_entry:
|
2008-11-12 01:02:24 +00:00
|
|
|
case ARM::reloc_arm_vfp_cp_entry:
|
2007-08-07 01:37:15 +00:00
|
|
|
case ARM::reloc_arm_relative: {
|
2007-08-30 23:21:27 +00:00
|
|
|
// It is necessary to calculate the correct PC relative value. We
|
|
|
|
// subtract the base addr from the target addr to form a byte offset.
|
2008-11-12 01:02:24 +00:00
|
|
|
ResultPtr = ResultPtr - (intptr_t)RelocPos - 8;
|
2007-08-30 23:21:27 +00:00
|
|
|
// If the result is positive, set bit U(23) to 1.
|
|
|
|
if (ResultPtr >= 0)
|
2008-11-12 01:02:24 +00:00
|
|
|
*((intptr_t*)RelocPos) |= 1 << ARMII::U_BitShift;
|
2007-08-30 23:21:27 +00:00
|
|
|
else {
|
2008-11-12 01:02:24 +00:00
|
|
|
// Otherwise, obtain the absolute value and set bit U(23) to 0.
|
2008-11-12 21:37:59 +00:00
|
|
|
*((intptr_t*)RelocPos) &= ~(1 << ARMII::U_BitShift);
|
2008-11-12 01:02:24 +00:00
|
|
|
ResultPtr = - ResultPtr;
|
2007-08-30 23:21:27 +00:00
|
|
|
}
|
2008-11-04 00:50:32 +00:00
|
|
|
// Set the immed value calculated.
|
2008-11-12 01:02:24 +00:00
|
|
|
// VFP immediate offset is multiplied by 4.
|
|
|
|
if (MR->getRelocationType() == ARM::reloc_arm_vfp_cp_entry)
|
|
|
|
ResultPtr = ResultPtr >> 2;
|
|
|
|
*((intptr_t*)RelocPos) |= ResultPtr;
|
2008-11-04 00:50:32 +00:00
|
|
|
// Set register Rn to PC.
|
2008-11-12 01:02:24 +00:00
|
|
|
*((intptr_t*)RelocPos) |=
|
|
|
|
ARMRegisterInfo::getRegisterNumbering(ARM::PC) << ARMII::RegRnShift;
|
2007-08-07 01:37:15 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-11-07 22:30:53 +00:00
|
|
|
case ARM::reloc_arm_pic_jt:
|
2008-11-04 00:50:32 +00:00
|
|
|
case ARM::reloc_arm_machine_cp_entry:
|
2008-10-29 23:55:43 +00:00
|
|
|
case ARM::reloc_arm_absolute: {
|
2008-11-04 00:50:32 +00:00
|
|
|
// These addresses have already been resolved.
|
2008-11-12 01:02:24 +00:00
|
|
|
*((intptr_t*)RelocPos) |= (intptr_t)ResultPtr;
|
2008-10-29 23:55:43 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-08-07 01:37:15 +00:00
|
|
|
case ARM::reloc_arm_branch: {
|
2007-08-30 23:21:27 +00:00
|
|
|
// It is necessary to calculate the correct value of signed_immed_24
|
|
|
|
// field. We subtract the base addr from the target addr to form a
|
|
|
|
// byte offset, which must be inside the range -33554432 and +33554428.
|
|
|
|
// Then, we set the signed_immed_24 field of the instruction to bits
|
|
|
|
// [25:2] of the byte offset. More details ARM-ARM p. A4-11.
|
2008-11-07 09:06:08 +00:00
|
|
|
ResultPtr = ResultPtr - (intptr_t)RelocPos - 8;
|
2007-08-30 23:21:27 +00:00
|
|
|
ResultPtr = (ResultPtr & 0x03FFFFFC) >> 2;
|
|
|
|
assert(ResultPtr >= -33554432 && ResultPtr <= 33554428);
|
2008-11-12 01:02:24 +00:00
|
|
|
*((intptr_t*)RelocPos) |= ResultPtr;
|
2007-08-07 01:37:15 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-11-07 09:06:08 +00:00
|
|
|
case ARM::reloc_arm_jt_base: {
|
|
|
|
// JT base - (instruction addr + 8)
|
|
|
|
ResultPtr = ResultPtr - (intptr_t)RelocPos - 8;
|
2008-11-12 01:02:24 +00:00
|
|
|
*((intptr_t*)RelocPos) |= ResultPtr;
|
2008-11-07 09:06:08 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-08-07 01:37:15 +00:00
|
|
|
}
|
|
|
|
}
|
2007-07-05 21:15:40 +00:00
|
|
|
}
|