Do not make the JIT memory manager manage the memory for globals.  Instead
just have the JIT malloc them.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28062 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/ExecutionEngine/JIT/JIT.cpp b/lib/ExecutionEngine/JIT/JIT.cpp
index 5f426b8..4d3b5a3 100644
--- a/lib/ExecutionEngine/JIT/JIT.cpp
+++ b/lib/ExecutionEngine/JIT/JIT.cpp
@@ -301,10 +301,22 @@
     // If the global hasn't been emitted to memory yet, allocate space.  We will
     // actually initialize the global after current function has finished
     // compilation.
-    uint64_t S = getTargetData().getTypeSize(GV->getType()->getElementType());
-    unsigned char A =
-      getTargetData().getTypeAlignment(GV->getType()->getElementType());
-    Ptr = MCE->allocateGlobal(S, A);
+    const Type *GlobalType = GV->getType()->getElementType();
+    size_t S = getTargetData().getTypeSize(GlobalType);
+    size_t A = getTargetData().getTypeAlignment(GlobalType);
+    if (A <= 8) {
+      Ptr = malloc(S);
+    } else {
+      // Allocate S+A bytes of memory, then use an aligned pointer within that
+      // space.
+      Ptr = malloc(S+A);
+      unsigned MisAligned = ((intptr_t)Ptr & (A-1));
+      unsigned Offset = MisAligned ? (A-MisAligned) : 0;
+      
+      // Trim the tail off the memory block.
+      realloc(Ptr, S+Offset);
+      Ptr = (char*)Ptr + Offset;
+    }
     state.getPendingGlobals(locked).push_back(GV);
   }
   addGlobalMapping(GV, Ptr);