From 17aa7971da2396b8ec489c7f9c3fd975bce743eb Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Wed, 15 Nov 2017 19:30:24 +0000 Subject: [PATCH] JIT: use MAP_32BIT on Linux and FreeBSD Unless RLIMIT_DATA is low enough FreeBSD by default reserves lower 2Gb for brk(2) style heap, ignoring mmap(2) address hint requested by RPCS3. Passing MAP_32BIT fixes the following crash Assertion failed: ((Type == ELF::R_X86_64_32 && (Value <= UINT32_MAX)) || (Type == ELF::R_X86_64_32S && ((int64_t)Value <= INT32_MAX && (int64_t)Value >= INT32_MIN))), function resolveX86_64Relocation, file /usr/ports/devel/llvm40/work/llvm-4.0.1.src/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp, line 287. --- Utilities/JIT.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Utilities/JIT.cpp b/Utilities/JIT.cpp index f9bfd7d390..7e3bd23f5b 100644 --- a/Utilities/JIT.cpp +++ b/Utilities/JIT.cpp @@ -30,6 +30,8 @@ #ifdef _WIN32 #include +#else +#include #endif #include "JIT.h" @@ -47,6 +49,11 @@ static void* const s_memory = []() -> void* llvm::InitializeNativeTargetAsmPrinter(); LLVMLinkInMCJIT(); +#ifdef MAP_32BIT + auto ptr = ::mmap(nullptr, s_memory_size, PROT_NONE, MAP_ANON | MAP_PRIVATE | MAP_32BIT, -1, 0); + if (ptr != MAP_FAILED) + return ptr; +#else for (u64 addr = 0x10000000; addr <= 0x80000000 - s_memory_size; addr += 0x1000000) { if (auto ptr = utils::memory_reserve(s_memory_size, (void*)addr)) @@ -54,6 +61,7 @@ static void* const s_memory = []() -> void* return ptr; } } +#endif return utils::memory_reserve(s_memory_size); }();