Implement AOT support for RISCV (#649)
Enable RISCV AOT support, the supported ABIs are LP64 and LP64D for riscv64, ILP32 and ILP32D for riscv32.
For wamrc:
use --target=riscv64/riscv32 to specify the target arch of output AOT file,
use --target-abi=lp64d/lp64/ilp32d/ilp32 to specify the target ABI,
if --target-abi isn't specified, by default lp64d is used for riscv64, and ilp32d is used for riscv32.
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
Co-authored-by: wenyongh <wenyong.huang@intel.com>
This commit is contained in:
@ -61,7 +61,9 @@ typedef pthread_t korp_thread;
|
||||
#if WASM_DISABLE_HW_BOUND_CHECK == 0
|
||||
#if defined(BUILD_TARGET_X86_64) \
|
||||
|| defined(BUILD_TARGET_AMD_64) \
|
||||
|| defined(BUILD_TARGET_AARCH64)
|
||||
|| defined(BUILD_TARGET_AARCH64) \
|
||||
|| defined(BUILD_TARGET_RISCV64_LP64D) \
|
||||
|| defined(BUILD_TARGET_RISCV64_LP64)
|
||||
|
||||
#include <setjmp.h>
|
||||
|
||||
@ -86,7 +88,7 @@ bool os_thread_signal_inited();
|
||||
void os_signal_unmask();
|
||||
|
||||
void os_sigreturn();
|
||||
#endif /* end of BUILD_TARGET_X86_64/AMD_64/AARCH64 */
|
||||
#endif /* end of BUILD_TARGET_X86_64/AMD_64/AARCH64/RISCV64 */
|
||||
#endif /* end of WASM_DISABLE_HW_BOUND_CHECK */
|
||||
|
||||
typedef long int __syscall_slong_t;
|
||||
|
||||
@ -44,8 +44,57 @@ os_mmap(void *hint, size_t size, int prot, int flags)
|
||||
if (flags & MMAP_MAP_FIXED)
|
||||
map_flags |= MAP_FIXED;
|
||||
|
||||
#if defined(BUILD_TARGET_RISCV64_LP64D) || defined(BUILD_TARGET_RISCV64_LP64)
|
||||
/* As AOT relocation in RISCV64 may require that the code/data mapped
|
||||
* is in range 0 to 2GB, we try to map the memory with hint address
|
||||
* (mmap's first argument) to meet the requirement.
|
||||
*/
|
||||
if (!hint && !(flags & MMAP_MAP_FIXED) && (flags & MMAP_MAP_32BIT)) {
|
||||
uint8 *stack_addr = (uint8*)&map_prot;
|
||||
uint8 *text_addr = (uint8*)os_mmap;
|
||||
/* hint address begins with 1MB */
|
||||
static uint8 *hint_addr = (uint8 *)(uintptr_t)BH_MB;
|
||||
|
||||
if ((hint_addr - text_addr >= 0
|
||||
&& hint_addr - text_addr < 100 * BH_MB)
|
||||
|| (text_addr - hint_addr >= 0
|
||||
&& text_addr - hint_addr < 100 * BH_MB)) {
|
||||
/* hint address is possibly in text section, skip it */
|
||||
hint_addr += 100 * BH_MB;
|
||||
}
|
||||
|
||||
if ((hint_addr - stack_addr >= 0
|
||||
&& hint_addr - stack_addr < 8 * BH_MB)
|
||||
|| (stack_addr - hint_addr >= 0
|
||||
&& stack_addr - hint_addr < 8 * BH_MB)) {
|
||||
/* hint address is possibly in native stack area, skip it */
|
||||
hint_addr += 8 * BH_MB;
|
||||
}
|
||||
|
||||
/* try 10 times, step with 1MB each time */
|
||||
for (i = 0;
|
||||
i < 10 && hint_addr < (uint8 *)(uintptr_t)(2ULL * BH_GB);
|
||||
i++) {
|
||||
addr = mmap(hint_addr, request_size, map_prot, map_flags, -1, 0);
|
||||
if (addr != MAP_FAILED) {
|
||||
if (addr > (uint8 *)(uintptr_t)(2ULL * BH_GB)) {
|
||||
/* unmap and try again if the mapped address doesn't
|
||||
* meet the requirement */
|
||||
os_munmap(addr, request_size);
|
||||
}
|
||||
else {
|
||||
/* reset next hint address */
|
||||
hint_addr += request_size;
|
||||
return addr;
|
||||
}
|
||||
}
|
||||
hint_addr += BH_MB;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* try 5 times */
|
||||
for (i = 0; i < 5; i ++) {
|
||||
for (i = 0; i < 5; i++) {
|
||||
addr = mmap(hint, request_size, map_prot, map_flags, -1, 0);
|
||||
if (addr != MAP_FAILED)
|
||||
break;
|
||||
|
||||
@ -62,7 +62,9 @@ typedef pthread_t korp_thread;
|
||||
#if WASM_DISABLE_HW_BOUND_CHECK == 0
|
||||
#if defined(BUILD_TARGET_X86_64) \
|
||||
|| defined(BUILD_TARGET_AMD_64) \
|
||||
|| defined(BUILD_TARGET_AARCH64)
|
||||
|| defined(BUILD_TARGET_AARCH64) \
|
||||
|| defined(BUILD_TARGET_RISCV64_LP64D) \
|
||||
|| defined(BUILD_TARGET_RISCV64_LP64)
|
||||
|
||||
#include <setjmp.h>
|
||||
|
||||
@ -87,7 +89,7 @@ bool os_thread_signal_inited();
|
||||
void os_signal_unmask();
|
||||
|
||||
void os_sigreturn();
|
||||
#endif /* end of BUILD_TARGET_X86_64/AMD_64/AARCH64 */
|
||||
#endif /* end of BUILD_TARGET_X86_64/AMD_64/AARCH64/RISCV64 */
|
||||
#endif /* end of WASM_DISABLE_HW_BOUND_CHECK */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -61,7 +61,9 @@ typedef pthread_t korp_thread;
|
||||
#if WASM_DISABLE_HW_BOUND_CHECK == 0
|
||||
#if defined(BUILD_TARGET_X86_64) \
|
||||
|| defined(BUILD_TARGET_AMD_64) \
|
||||
|| defined(BUILD_TARGET_AARCH64)
|
||||
|| defined(BUILD_TARGET_AARCH64) \
|
||||
|| defined(BUILD_TARGET_RISCV64_LP64D) \
|
||||
|| defined(BUILD_TARGET_RISCV64_LP64)
|
||||
|
||||
#include <setjmp.h>
|
||||
|
||||
@ -86,7 +88,7 @@ bool os_thread_signal_inited();
|
||||
void os_signal_unmask();
|
||||
|
||||
void os_sigreturn();
|
||||
#endif /* end of BUILD_TARGET_X86_64/AMD_64/AARCH64 */
|
||||
#endif /* end of BUILD_TARGET_X86_64/AMD_64/AARCH64/RISCV64 */
|
||||
#endif /* end of WASM_DISABLE_HW_BOUND_CHECK */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
Reference in New Issue
Block a user