Commit e02d8938 by Ben Clayton

LLVMJIT: Fix memory leak

We were calling `new MemoryMapper` and passing it into the `llvm::SectionMemoryManager`, but the `SectionMemoryManager` does not take ownership, resulting in a leak. Given that the `MemoryMapper` is entirely stateless, just use a pointer to a single static instance. Bug: b/171402030 Change-Id: Ic3a118a5f4aeea6b6b60861399993e81827c9d48 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/49488Reviewed-by: 's avatarAntonio Maiorano <amaiorano@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Kokoro-Result: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarBen Clayton <bclayton@google.com>
parent 4bc9f6e5
...@@ -484,9 +484,6 @@ auto &Unwrap(T &&v) ...@@ -484,9 +484,6 @@ auto &Unwrap(T &&v)
// settings and no Reactor routine directly links against another. // settings and no Reactor routine directly links against another.
class JITRoutine : public rr::Routine class JITRoutine : public rr::Routine
{ {
using ObjLayer = llvm::orc::RTDyldObjectLinkingLayer;
using CompileLayer = llvm::orc::IRCompileLayer;
llvm::orc::RTDyldObjectLinkingLayer objectLayer; llvm::orc::RTDyldObjectLinkingLayer objectLayer;
llvm::orc::IRCompileLayer compileLayer; llvm::orc::IRCompileLayer compileLayer;
llvm::orc::MangleAndInterner mangle; llvm::orc::MangleAndInterner mangle;
...@@ -501,7 +498,10 @@ public: ...@@ -501,7 +498,10 @@ public:
llvm::Function **funcs, llvm::Function **funcs,
size_t count, size_t count,
const rr::Config &config) const rr::Config &config)
: objectLayer(session, []() { return std::make_unique<llvm::SectionMemoryManager>(new MemoryMapper()); }) : objectLayer(session, []() {
static MemoryMapper mm;
return std::make_unique<llvm::SectionMemoryManager>(&mm);
})
, compileLayer(session, objectLayer, std::make_unique<llvm::orc::ConcurrentIRCompiler>(JITGlobals::get()->getTargetMachineBuilder(config.getOptimization().getLevel()))) , compileLayer(session, objectLayer, std::make_unique<llvm::orc::ConcurrentIRCompiler>(JITGlobals::get()->getTargetMachineBuilder(config.getOptimization().getLevel())))
, mangle(session, JITGlobals::get()->getDataLayout()) , mangle(session, JITGlobals::get()->getDataLayout())
, ctx(std::make_unique<llvm::LLVMContext>()) , ctx(std::make_unique<llvm::LLVMContext>())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment