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

llvm-svn: 9210
diff --git a/llvm/lib/Target/X86/X86TargetMachine.cpp b/llvm/lib/Target/X86/X86TargetMachine.cpp
index 14af520..0a42f19 100644
--- a/llvm/lib/Target/X86/X86TargetMachine.cpp
+++ b/llvm/lib/Target/X86/X86TargetMachine.cpp
@@ -143,9 +143,12 @@
 }
 
 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!
 }