You can't just blat the address into memory, you have to blat its
authorBrian Gaeke <gaeke@uiuc.edu>
Fri, 17 Oct 2003 21:47:25 +0000 (21:47 +0000)
committerBrian Gaeke <gaeke@uiuc.edu>
Fri, 17 Oct 2003 21:47:25 +0000 (21:47 +0000)
displacement.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9210 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86TargetMachine.cpp

index 14af52099dd410f102368ec4bb5c1f82b306b3a9..0a42f19733c67340b60c76c1daf01552e3376f4b 100644 (file)
@@ -143,9 +143,12 @@ bool X86TargetMachine::addPassesToJITCompile(FunctionPassManager &PM) {
 }
 
 bool X86TargetMachine::replaceMachineCodeForFunction (void *Old, void *New) {
 }
 
 bool X86TargetMachine::replaceMachineCodeForFunction (void *Old, void *New) {
+  // FIXME: This code could perhaps live in a more appropriate place.
   char *OldByte = (char *) Old;
   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!
 }
 }