llvm: Fix memory leak on jit destroy

Fix msvc build
This commit is contained in:
DH 2025-04-08 20:31:15 +03:00
parent 62ad27d1e2
commit 79633a7740
3 changed files with 17 additions and 5 deletions

View file

@ -2,6 +2,7 @@
#include "Emu/Cell/ErrorCodes.h"
#include "Emu/Memory/vm_ptr.h"
#include <mutex>
// Return Codes
enum

View file

@ -509,10 +509,10 @@ enum class thread_state : u32;
class jit_compiler final
{
// Local LLVM context
std::unique_ptr<llvm::LLVMContext> m_context{};
std::unique_ptr<llvm::LLVMContext, void (*)(llvm::LLVMContext*)> m_context{nullptr, [](llvm::LLVMContext*) {}};
// Execution instance
std::unique_ptr<llvm::ExecutionEngine> m_engine{};
std::unique_ptr<llvm::ExecutionEngine, void (*)(llvm::ExecutionEngine*)> m_engine{nullptr, [](llvm::ExecutionEngine*) {}};
// Arch
std::string m_cpu{};

View file

@ -640,7 +640,11 @@ bool jit_compiler::add_sub_disk_space(ssz space)
}
jit_compiler::jit_compiler(const std::unordered_map<std::string, u64>& _link, const std::string& _cpu, u32 flags, std::function<u64(const std::string&)> symbols_cement) noexcept
: m_context(new llvm::LLVMContext), m_cpu(cpu(_cpu))
: m_context(new llvm::LLVMContext, [](llvm::LLVMContext* context)
{
delete context;
}),
m_cpu(cpu(_cpu))
{
[[maybe_unused]] static const bool s_install_llvm_error_handler = []()
{
@ -681,7 +685,9 @@ jit_compiler::jit_compiler(const std::unordered_map<std::string, u64>& _link, co
}
{
m_engine.reset(llvm::EngineBuilder(std::move(null_mod))
m_engine = std::unique_ptr<llvm::ExecutionEngine, void (*)(llvm::ExecutionEngine*)>{
llvm::EngineBuilder(std::move(null_mod))
.setErrorStr(&result)
.setEngineKind(llvm::EngineKind::JIT)
.setMCJITMemoryManager(std::move(mem))
@ -692,7 +698,12 @@ jit_compiler::jit_compiler(const std::unordered_map<std::string, u64>& _link, co
#endif
.setRelocationModel(llvm::Reloc::Model::PIC_)
.setMCPU(m_cpu)
.create());
.create(),
[](llvm::ExecutionEngine* engine)
{
delete engine;
},
};
}
if (!_link.empty())