Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/compilation_on_nuttx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ jobs:

- name: Install RISC-V Compilers
if: contains(matrix.nuttx_board_config, 'risc-v')
run: sudo apt install -y gcc-riscv64-unknown-elf
run: |
curl -L https://static.dev.sifive.com/dev-tools/freedom-tools/v2020.12/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14.tar.gz > riscv.tar.gz
tar xvf riscv.tar.gz
echo "$PWD/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14/bin" >> $GITHUB_PATH

- name: Checkout NuttX
uses: actions/checkout@v3
Expand All @@ -113,9 +116,8 @@ jobs:

- name: Enable WAMR for NuttX
run: |
find nuttx/boards -name defconfig | xargs sed -i '$a\CONFIG_EOL_IS_CR=y\n${{ matrix.wamr_config_option }}'
find nuttx/boards -name defconfig | xargs sed -i '$a\CONFIG_EOL_IS_LF=y\n${{ matrix.wamr_config_option }}'
find nuttx/boards/sim -name defconfig | xargs sed -i '$a\CONFIG_LIBM=y\n'
find nuttx/boards/risc-v -name defconfig | xargs sed -i '$a\CONFIG_LIBM=y\n'

- name: Build
run: |
Expand Down
2 changes: 1 addition & 1 deletion build-scripts/build_llvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def main():
},
"xtensa": {
"repo": "https://github.com/espressif/llvm-project.git",
"branch": "xtensa_release_13.0.0",
"branch": "xtensa_release_15.x",
},
"default": {
"repo": "https://github.com/llvm/llvm-project.git",
Expand Down
60 changes: 59 additions & 1 deletion core/iwasm/aot/arch/aot_reloc_riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,47 +16,105 @@
#define RV_OPCODE_SW 0x23

/* clang-format off */
void __adddf3();
void __addsf3();
void __divdi3();
void __divsi3();
void __divsf3();
void __eqsf2();
void __eqdf2();
void __extendsfdf2();
void __fixdfdi();
void __fixdfsi();
void __fixsfdi();
void __fixsfsi();
void __fixunsdfdi();
void __fixunsdfsi();
void __fixunssfdi();
void __fixunssfsi();
void __floatdidf();
void __floatdisf();
void __floatsisf();
void __floatsidf();
void __floatundidf();
void __floatundisf();
void __floatunsisf();
void __floatunsidf();
void __gedf2();
void __gesf2();
void __gtsf2();
void __ledf2();
void __lesf2();
void __moddi3();
void __modsi3();
void __muldf3();
void __muldi3();
void __mulsf3();
void __mulsi3();
void __nedf2();
void __nesf2();
void __subdf3();
void __subsf3();
void __truncdfsf2();
void __udivdi3();
void __udivsi3();
void __umoddi3();
void __umodsi3();
void __unorddf2();
void __unordsf2();
/* clang-format on */

static SymbolMap target_sym_map[] = {
/* clang-format off */
REG_COMMON_SYMBOLS
#ifndef __riscv_flen
REG_SYM(__adddf3),
REG_SYM(__addsf3),
REG_SYM(__divsf3),
REG_SYM(__gedf2),
REG_SYM(__gesf2),
REG_SYM(__gtsf2),
REG_SYM(__ledf2),
REG_SYM(__lesf2),
REG_SYM(__muldf3),
REG_SYM(__nedf2),
REG_SYM(__nesf2),
REG_SYM(__eqsf2),
REG_SYM(__eqdf2),
REG_SYM(__extendsfdf2),
REG_SYM(__fixunsdfdi),
REG_SYM(__fixunsdfsi),
REG_SYM(__fixunssfsi),
REG_SYM(__subdf3),
REG_SYM(__subsf3),
REG_SYM(__truncdfsf2),
REG_SYM(__unorddf2),
REG_SYM(__unordsf2),
#endif
REG_SYM(__divdi3),
REG_SYM(__divsi3),
#if __riscv_xlen == 32
REG_SYM(__fixdfdi),
REG_SYM(__fixdfsi),
REG_SYM(__fixsfdi),
REG_SYM(__fixsfsi),
#endif
REG_SYM(__fixunsdfdi),
REG_SYM(__fixunssfdi),
#if __riscv_xlen == 32
REG_SYM(__floatdidf),
REG_SYM(__floatdisf),
REG_SYM(__floatsisf),
REG_SYM(__floatsidf),
REG_SYM(__floatundidf),
REG_SYM(__floatundisf),
REG_SYM(__floatunsisf),
REG_SYM(__floatunsidf),
#endif
REG_SYM(__moddi3),
REG_SYM(__modsi3),
REG_SYM(__muldi3),
#if __riscv_xlen == 32
REG_SYM(__mulsf3),
REG_SYM(__mulsi3),
#endif
REG_SYM(__udivdi3),
Expand Down
4 changes: 3 additions & 1 deletion core/iwasm/aot/arch/aot_reloc_xtensa.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,9 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
if (relative_offset < -256 * BH_KB || relative_offset > -4) {
set_error_buf(error_buf, error_buf_size,
"AOT module load failed: "
"target address out of range.");
"target address out of range.\n"
"Try using `wamrc --size-level=0` to generate "
".literal island.");
return false;
}

Expand Down
80 changes: 64 additions & 16 deletions core/iwasm/common/wasm_c_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ WASM_DEFINE_VEC_OWN(module, wasm_module_delete_internal)
WASM_DEFINE_VEC_OWN(store, wasm_store_delete)
WASM_DEFINE_VEC_OWN(valtype, wasm_valtype_delete)

#ifndef NDEBUG
#define WASM_C_DUMP_PROC_MEM() LOG_PROC_MEM()
#else
#define WASM_C_DUMP_PROC_MEM() (void)0
#endif

/* Runtime Environment */
own wasm_config_t *
wasm_config_new(void)
Expand Down Expand Up @@ -307,6 +313,14 @@ wasm_engine_new_internal(mem_alloc_type_t type, const MemAllocOption *opts)
RuntimeInitArgs init_args = { 0 };
init_args.mem_alloc_type = type;

#ifndef NDEBUG
bh_log_set_verbose_level(BH_LOG_LEVEL_VERBOSE);
#else
bh_log_set_verbose_level(BH_LOG_LEVEL_WARNING);
#endif

WASM_C_DUMP_PROC_MEM();

if (type == Alloc_With_Pool) {
if (!opts) {
return NULL;
Expand Down Expand Up @@ -337,14 +351,6 @@ wasm_engine_new_internal(mem_alloc_type_t type, const MemAllocOption *opts)
goto failed;
}

#ifndef NDEBUG
/*DEBUG*/
bh_log_set_verbose_level(BH_LOG_LEVEL_VERBOSE);
#else
/*VERBOSE*/
bh_log_set_verbose_level(BH_LOG_LEVEL_WARNING);
#endif

/* create wasm_engine_t */
if (!(engine = malloc_internal(sizeof(wasm_engine_t)))) {
goto failed;
Expand All @@ -358,6 +364,8 @@ wasm_engine_new_internal(mem_alloc_type_t type, const MemAllocOption *opts)

engine->ref_count = 1;

WASM_C_DUMP_PROC_MEM();

RETURN_OBJ(engine, wasm_engine_delete_internal)
}

Expand Down Expand Up @@ -442,6 +450,8 @@ wasm_store_new(wasm_engine_t *engine)
{
wasm_store_t *store = NULL;

WASM_C_DUMP_PROC_MEM();

if (!engine || singleton_engine != engine) {
return NULL;
}
Expand Down Expand Up @@ -474,6 +484,8 @@ wasm_store_new(wasm_engine_t *engine)
goto failed;
}

WASM_C_DUMP_PROC_MEM();

return store;
failed:
wasm_store_delete(store);
Expand Down Expand Up @@ -1903,6 +1915,8 @@ wasm_module_new(wasm_store_t *store, const wasm_byte_vec_t *binary)

bh_assert(singleton_engine);

WASM_C_DUMP_PROC_MEM();

if (!store || !binary || binary->size == 0 || binary->size > UINT32_MAX)
goto quit;

Expand Down Expand Up @@ -1958,6 +1972,9 @@ wasm_module_new(wasm_store_t *store, const wasm_byte_vec_t *binary)
goto destroy_lock;

module_ex->ref_count = 1;

WASM_C_DUMP_PROC_MEM();

return module_ext_to_module(module_ex);

destroy_lock:
Expand Down Expand Up @@ -4427,34 +4444,38 @@ aot_process_export(wasm_store_t *store, const AOTModuleInstance *inst_aot,

wasm_instance_t *
wasm_instance_new(wasm_store_t *store, const wasm_module_t *module,
const wasm_extern_vec_t *imports, own wasm_trap_t **traps)
const wasm_extern_vec_t *imports, own wasm_trap_t **trap)
{
return wasm_instance_new_with_args(store, module, imports, traps,
return wasm_instance_new_with_args(store, module, imports, trap,
KILOBYTE(32), KILOBYTE(32));
}

wasm_instance_t *
wasm_instance_new_with_args(wasm_store_t *store, const wasm_module_t *module,
const wasm_extern_vec_t *imports,
own wasm_trap_t **traps, const uint32 stack_size,
own wasm_trap_t **trap, const uint32 stack_size,
const uint32 heap_size)
{
char error_buf[128] = { 0 };
char sub_error_buf[128] = { 0 };
char error_buf[256] = { 0 };
uint32 import_count = 0;
bool import_count_verified = false;
wasm_instance_t *instance = NULL;
uint32 i = 0;
bool processed = false;
(void)traps;

bh_assert(singleton_engine);

if (!module) {
return NULL;
}

WASM_C_DUMP_PROC_MEM();

instance = malloc_internal(sizeof(wasm_instance_t));
if (!instance) {
snprintf(sub_error_buf, sizeof(sub_error_buf),
"Failed to malloc instance");
goto failed;
}

Expand All @@ -4471,6 +4492,8 @@ wasm_instance_new_with_args(wasm_store_t *store, const wasm_module_t *module,
/* make sure a complete import list */
if ((int32)import_count < 0
|| import_count != actual_link_import_count) {
snprintf(sub_error_buf, sizeof(sub_error_buf),
"Failed to validate imports");
goto failed;
}
}
Expand All @@ -4489,6 +4512,8 @@ wasm_instance_new_with_args(wasm_store_t *store, const wasm_module_t *module,
import_count = aot_link(instance, MODULE_AOT(module),
(wasm_extern_t **)imports->data);
if ((int32)import_count < 0) {
snprintf(sub_error_buf, sizeof(sub_error_buf),
"Failed to validate imports");
goto failed;
}
}
Expand All @@ -4501,18 +4526,21 @@ wasm_instance_new_with_args(wasm_store_t *store, const wasm_module_t *module,
* also leads to below branch
*/
if (!import_count_verified) {
snprintf(sub_error_buf, sizeof(sub_error_buf),
"Failed to verify import count");
goto failed;
}
}

instance->inst_comm_rt = wasm_runtime_instantiate(
*module, stack_size, heap_size, error_buf, sizeof(error_buf));
*module, stack_size, heap_size, sub_error_buf, sizeof(sub_error_buf));
if (!instance->inst_comm_rt) {
LOG_ERROR(error_buf);
goto failed;
}

if (!wasm_runtime_create_exec_env_singleton(instance->inst_comm_rt)) {
snprintf(sub_error_buf, sizeof(sub_error_buf),
"Failed to create exec env singleton");
goto failed;
}

Expand All @@ -4537,6 +4565,8 @@ wasm_instance_new_with_args(wasm_store_t *store, const wasm_module_t *module,
instance->inst_comm_rt;
break;
default:
snprintf(sub_error_buf, sizeof(sub_error_buf),
"Unknown import kind");
goto failed;
}
}
Expand All @@ -4553,6 +4583,8 @@ wasm_instance_new_with_args(wasm_store_t *store, const wasm_module_t *module,
if (!interp_process_export(store,
(WASMModuleInstance *)instance->inst_comm_rt,
instance->exports)) {
snprintf(sub_error_buf, sizeof(sub_error_buf),
"Interpreter failed to process exports");
goto failed;
}

Expand All @@ -4575,6 +4607,8 @@ wasm_instance_new_with_args(wasm_store_t *store, const wasm_module_t *module,
if (!aot_process_export(store,
(AOTModuleInstance *)instance->inst_comm_rt,
instance->exports)) {
snprintf(sub_error_buf, sizeof(sub_error_buf),
"AOT failed to process exports");
goto failed;
}

Expand All @@ -4587,18 +4621,32 @@ wasm_instance_new_with_args(wasm_store_t *store, const wasm_module_t *module,
* leads to below branch
*/
if (!processed) {
snprintf(sub_error_buf, sizeof(sub_error_buf),
"Incorrect filetype and compilation flags");
goto failed;
}

/* add it to a watching list in store */
if (!bh_vector_append((Vector *)store->instances, &instance)) {
snprintf(sub_error_buf, sizeof(sub_error_buf),
"Failed to add to store instances");
goto failed;
}

WASM_C_DUMP_PROC_MEM();

return instance;

failed:
LOG_DEBUG("%s failed", __FUNCTION__);
snprintf(error_buf, sizeof(error_buf), "%s failed: %s", __FUNCTION__,
sub_error_buf);
if (trap != NULL) {
wasm_message_t message = { 0 };
wasm_name_new_from_string(&message, error_buf);
*trap = wasm_trap_new(store, &message);
wasm_byte_vec_delete(&message);
}
LOG_DEBUG(error_buf);
wasm_instance_delete_internal(instance);
return NULL;
}
Expand Down
Loading