Index: include/llvm/Support/Memory.h =================================================================== --- include/llvm/Support/Memory.h +++ include/llvm/Support/Memory.h @@ -140,7 +140,10 @@ /// setExecutable - Before the JIT can run a block of code, it has to be /// given read and executable privilege. Return true if it is already r-x /// or the system is able to change its previlege. - static bool setExecutable(MemoryBlock &M, std::string *ErrMsg = nullptr); + /// If InvalidateCache is true, the instruction cache is also invalidated + // as result of this call. + static bool setExecutable(MemoryBlock &M, std::string *ErrMsg = nullptr, + bool InvalidateCache = false); /// setWritable - When adding to a block of code, the JIT may need /// to mark a block of code as RW since the protections are on page Index: lib/Support/Unix/Memory.inc =================================================================== --- lib/Support/Unix/Memory.inc +++ lib/Support/Unix/Memory.inc @@ -263,7 +263,8 @@ #endif } -bool Memory::setExecutable (MemoryBlock &M, std::string *ErrMsg) { +bool Memory::setExecutable(MemoryBlock &M, std::string *ErrMsg, + bool InvalidateCache) { #if defined(__APPLE__) && (defined(__arm__) || defined(__arm64__)) if (M.Address == 0 || M.Size == 0) return false; Memory::InvalidateInstructionCache(M.Address, M.Size); @@ -274,6 +275,8 @@ Memory::InvalidateInstructionCache(M.Address, M.Size); return true; #else + if (InvalidateCache) + Memory::InvalidateInstructionCache(M.Address, M.Size); return true; #endif } Index: lib/Support/Windows/Memory.inc =================================================================== --- lib/Support/Windows/Memory.inc +++ lib/Support/Windows/Memory.inc @@ -197,7 +197,8 @@ return true; } -bool Memory::setExecutable(MemoryBlock &M, std::string *ErrMsg) { +bool Memory::setExecutable(MemoryBlock &M, std::string *ErrMsg, + bool InvalidateCache) { if (!setRangeExecutable(M.Address, M.Size)) { return MakeErrMsg(ErrMsg, "Cannot set memory to executable: "); } Index: tools/llvm-rtdyld/llvm-rtdyld.cpp =================================================================== --- tools/llvm-rtdyld/llvm-rtdyld.cpp +++ tools/llvm-rtdyld/llvm-rtdyld.cpp @@ -385,8 +385,8 @@ sys::MemoryBlock &Data = MemMgr.FunctionMemory[i]; // Make sure the memory is executable. std::string ErrorStr; - sys::Memory::InvalidateInstructionCache(Data.base(), Data.size()); - if (!sys::Memory::setExecutable(Data, &ErrorStr)) + if (!sys::Memory::setExecutable(Data, &ErrorStr, + true /* invalidateCache */)) return Error("unable to mark function executable: '" + ErrorStr + "'"); }