From 9340be464163a778890c5f4187e0d313736454de Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Tue, 4 Nov 2008 09:30:48 +0000 Subject: [PATCH] For some targets, it's not possible to place GVs in the same memory buffer as the MachineCodeEmitter allocated memory. Code and data has different read / write / execution privilege requirements. This is a short term workaround. The current solution is for the JIT memory manager to manage code and data memory separately. llvm-svn: 58688 --- llvm/include/llvm/Target/TargetJITInfo.h | 5 +++++ llvm/lib/ExecutionEngine/JIT/JIT.cpp | 10 ++++++++++ llvm/lib/Target/ARM/ARMJITInfo.h | 11 +++++++++++ 3 files changed, 26 insertions(+) diff --git a/llvm/include/llvm/Target/TargetJITInfo.h b/llvm/include/llvm/Target/TargetJITInfo.h index 09ef15eb49f1..fb89292c537c 100644 --- a/llvm/include/llvm/Target/TargetJITInfo.h +++ b/llvm/include/llvm/Target/TargetJITInfo.h @@ -110,6 +110,11 @@ namespace llvm { /// hasCustomConstantPool - Allows a target to specify that constant /// pool address resolution is handled by the target. virtual bool hasCustomConstantPool() const { return false; } + + /// allocateSeparateGVMemory - If true, globals should be placed in + /// separately allocated heap memory rather than in the same + /// code memory allocated by MachineCodeEmitter. + virtual bool allocateSeparateGVMemory() const { return false; } protected: bool useGOT; }; diff --git a/llvm/lib/ExecutionEngine/JIT/JIT.cpp b/llvm/lib/ExecutionEngine/JIT/JIT.cpp index b768f4d31c2d..83923a2b8e35 100644 --- a/llvm/lib/ExecutionEngine/JIT/JIT.cpp +++ b/llvm/lib/ExecutionEngine/JIT/JIT.cpp @@ -565,6 +565,16 @@ void *JIT::getOrEmitGlobalVariable(const GlobalVariable *GV) { if (GV->isThreadLocal()) { MutexGuard locked(lock); Ptr = TJI.allocateThreadLocalMemory(S); + } else if (TJI.allocateSeparateGVMemory()) { + 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)); + Ptr = (char*)Ptr + (MisAligned ? (A-MisAligned) : 0); + } } else { Ptr = MCE->allocateSpace(S, A); } diff --git a/llvm/lib/Target/ARM/ARMJITInfo.h b/llvm/lib/Target/ARM/ARMJITInfo.h index ba8768aec4ba..2a3a7f8f37c5 100644 --- a/llvm/lib/Target/ARM/ARMJITInfo.h +++ b/llvm/lib/Target/ARM/ARMJITInfo.h @@ -65,6 +65,17 @@ namespace llvm { /// pool address resolution is handled by the target. virtual bool hasCustomConstantPool() const { return true; } + /// allocateSeparateGVMemory - If true, globals should be placed in + /// separately allocated heap memory rather than in the same + /// code memory allocated by MachineCodeEmitter. + virtual bool allocateSeparateGVMemory() const { +#ifdef __APPLE__ + return true; +#else + return false; +#endif + } + /// Initialize - Initialize internal stage. Get the list of constant pool /// Resize constant pool ids to CONSTPOOL_ENTRY addresses map. void Initialize(const std::vector *mcpes) {