Skip to content

Commit 0ecc9f2

Browse files
committed
fix missing ___clear_cache when targetting iOS
1 parent 102f8ac commit 0ecc9f2

2 files changed

Lines changed: 30 additions & 8 deletions

File tree

CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ src/virtual_machine.cpp
5656
src/vm_compiled_light.cpp
5757
src/blake2/blake2b.c)
5858

59+
if (NOT WIN32)
60+
check_symbol_exists("__builtin___clear_cache" "stdlib.h" HAVE_BUILTIN_CLEAR_CACHE)
61+
if (HAVE_BUILTIN_CLEAR_CACHE)
62+
add_definitions(-DHAVE_BUILTIN_CLEAR_CACHE)
63+
endif()
64+
endif()
65+
66+
if (CMAKE_CXX_COMPILER_ID MATCHES GNU)
67+
add_definitions(-D_GNU_SOURCE -DHAVE_BUILTIN_CLEAR_CACHE)
68+
endif()
69+
5970
if(NOT ARCH_ID)
6071
# allow cross compiling
6172
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "")

src/jit_compiler_a64.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3232
#include "program.hpp"
3333
#include "reciprocal.h"
3434
#include "virtual_memory.h"
35+
#ifndef HAVE_BUILTIN_CLEAR_CACHE
36+
#include <libkern/OSCacheControl.h>
37+
#endif
3538

3639
namespace ARMV8A {
3740

@@ -98,8 +101,10 @@ JitCompilerA64::JitCompilerA64()
98101
memset(reg_changed_offset, 0, sizeof(reg_changed_offset));
99102
memcpy(code, (void*) randomx_program_aarch64, CodeSize);
100103

101-
#ifdef __GNUC__
102-
__builtin___clear_cache(reinterpret_cast<char*>(code), reinterpret_cast<char*>(code + CodeSize));
104+
#ifdef HAVE_BUILTIN_CLEAR_CACHE
105+
__builtin___clear_cache(reinterpret_cast<char*>(code), reinterpret_cast<char*>(code + CodeSize));
106+
#else
107+
sys_icache_invalidate(code, (size_t)(CodeSize));
103108
#endif
104109
}
105110

@@ -169,8 +174,10 @@ void JitCompilerA64::generateProgram(Program& program, ProgramConfiguration& con
169174
codePos = ((uint8_t*)randomx_program_aarch64_update_spMix1) - ((uint8_t*)randomx_program_aarch64);
170175
emit32(ARMV8A::EOR | 10 | (IntRegMap[config.readReg0] << 5) | (IntRegMap[config.readReg1] << 16), code, codePos);
171176

172-
#ifdef __GNUC__
173-
__builtin___clear_cache(reinterpret_cast<char*>(code + MainLoopBegin), reinterpret_cast<char*>(code + codePos));
177+
#ifdef HAVE_BUILTIN_CLEAR_CACHE
178+
__builtin___clear_cache(reinterpret_cast<char*>(code), reinterpret_cast<char*>(code + CodeSize));
179+
#else
180+
sys_icache_invalidate(code, (size_t)(CodeSize));
174181
#endif
175182
}
176183

@@ -226,8 +233,10 @@ void JitCompilerA64::generateProgramLight(Program& program, ProgramConfiguration
226233
emit32(ARMV8A::ADD_IMM_LO | 2 | (2 << 5) | (imm_lo << 10), code, codePos);
227234
emit32(ARMV8A::ADD_IMM_HI | 2 | (2 << 5) | (imm_hi << 10), code, codePos);
228235

229-
#ifdef __GNUC__
230-
__builtin___clear_cache(reinterpret_cast<char*>(code + MainLoopBegin), reinterpret_cast<char*>(code + codePos));
236+
#ifdef HAVE_BUILTIN_CLEAR_CACHE
237+
__builtin___clear_cache(reinterpret_cast<char*>(code), reinterpret_cast<char*>(code + CodeSize));
238+
#else
239+
sys_icache_invalidate(code, (size_t)(CodeSize));
231240
#endif
232241
}
233242

@@ -344,8 +353,10 @@ void JitCompilerA64::generateSuperscalarHash(SuperscalarProgram(&programs)[N], s
344353
memcpy(code + codePos, p1, p2 - p1);
345354
codePos += p2 - p1;
346355

347-
#ifdef __GNUC__
348-
__builtin___clear_cache(reinterpret_cast<char*>(code + CodeSize), reinterpret_cast<char*>(code + codePos));
356+
#ifdef HAVE_BUILTIN_CLEAR_CACHE
357+
__builtin___clear_cache(reinterpret_cast<char*>(code), reinterpret_cast<char*>(code + CodeSize));
358+
#else
359+
sys_icache_invalidate(code, (size_t)(CodeSize));
349360
#endif
350361
}
351362

0 commit comments

Comments
 (0)