You can't just blat the address into memory, you have to blat its

displacement.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9210 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Brian Gaeke 2003-10-17 21:47:25 +00:00
parent 0e077f7251
commit e5f6859911

View File

@ -143,9 +143,12 @@ bool X86TargetMachine::addPassesToJITCompile(FunctionPassManager &PM) {
}
bool X86TargetMachine::replaceMachineCodeForFunction (void *Old, void *New) {
// FIXME: This code could perhaps live in a more appropriate place.
char *OldByte = (char *) Old;
*OldByte++ = 0xE9; // JMP
unsigned *OldWord = (unsigned *) OldByte;
*OldWord = (unsigned) New;
return false;
*OldByte++ = 0xE9; // Emit JMP opcode.
int32_t *OldWord = (int32_t *) OldByte;
int32_t NewAddr = (int32_t) New;
int32_t OldAddr = (int32_t) OldWord;
*OldWord = NewAddr - OldAddr - 4; // Emit PC-relative addr of New code.
return false; // success!
}