diff options
Diffstat (limited to 'llvm/lib/ExecutionEngine/JIT/JIT.cpp')
-rw-r--r-- | llvm/lib/ExecutionEngine/JIT/JIT.cpp | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/llvm/lib/ExecutionEngine/JIT/JIT.cpp b/llvm/lib/ExecutionEngine/JIT/JIT.cpp index 5f426b877ef..4d3b5a349f7 100644 --- a/llvm/lib/ExecutionEngine/JIT/JIT.cpp +++ b/llvm/lib/ExecutionEngine/JIT/JIT.cpp @@ -301,10 +301,22 @@ void *JIT::getOrEmitGlobalVariable(const GlobalVariable *GV) { // 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); |