Some fixes for x86-64 JIT.  Make it use small code
model, except for external calls; this makes
addressing modes PC-relative.  Incomplete.

The assertion at the top of Emitter::runOnMachineFunction
was obviously bogus (always true) so I removed it.
If someone knows what the correct test should be to cover
all the various targets, please fix.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@54656 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/X86/X86TargetMachine.cpp b/lib/Target/X86/X86TargetMachine.cpp
index e163956..8e10ee9 100644
--- a/lib/Target/X86/X86TargetMachine.cpp
+++ b/lib/Target/X86/X86TargetMachine.cpp
@@ -194,12 +194,14 @@
 bool X86TargetMachine::addCodeEmitter(PassManagerBase &PM, bool Fast,
                                       bool DumpAsm, MachineCodeEmitter &MCE) {
   // FIXME: Move this to TargetJITInfo!
-  if (DefRelocModel == Reloc::Default)
+  // Do not override 64-bit setting made in X86TargetMachine().
+  if (DefRelocModel == Reloc::Default && !Subtarget.is64Bit())
     setRelocationModel(Reloc::Static);
   
-  // JIT cannot ensure globals are placed in the lower 4G of address.
+  // 64-bit JIT places everything in the same buffer except external functions.
+  // Use small code model but hack the call instruction for externals.
   if (Subtarget.is64Bit())
-    setCodeModel(CodeModel::Large);
+    setCodeModel(CodeModel::Small);
 
   PM.add(createX86CodeEmitterPass(*this, MCE));
   if (DumpAsm)