From 62c0a1e7d408cd9cb0ba116bb54b29ee8deb80f1 Mon Sep 17 00:00:00 2001 From: Mark Zhuang Date: Tue, 3 Jun 2025 09:35:52 +0800 Subject: [PATCH] RISCV: fix flush cache for linux riscv when clang <= 18 for __builtin___clear_cache, clang-18 generates __clear_cache: https://godbolt.org/z/K5Kx6EEhq, which is an empty function. clang-19 can generates __riscv_flush_icache: https://godbolt.org/z/TKe6Kh61a --- src/common/memmap.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/common/memmap.cpp b/src/common/memmap.cpp index da6af3e0a..013af87af 100644 --- a/src/common/memmap.cpp +++ b/src/common/memmap.cpp @@ -35,6 +35,9 @@ #include #include #endif +#if defined(__linux__) && defined(CPU_ARCH_RISCV64) +#include +#endif #if defined(__linux__) && !defined(MAP_FIXED_NOREPLACE) // Compatibility with old libc. @@ -812,7 +815,11 @@ void MemMap::ReleaseJITMemory(void* ptr, size_t size) void MemMap::FlushInstructionCache(void* address, size_t size) { +#if defined(CPU_ARCH_RISCV64) && defined(__linux__) && defined(__clang__) && (__clang_major__ <= 18) + __riscv_flush_icache(reinterpret_cast(address), reinterpret_cast(address) + size, 0); +#else __builtin___clear_cache(reinterpret_cast(address), reinterpret_cast(address) + size); +#endif } #endif