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
4 changes: 2 additions & 2 deletions .github/workflows/compilation_on_nuttx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ jobs:
- name: Install RISC-V Compilers
if: contains(matrix.nuttx_board_config, 'risc-v')
run: |
curl -L -k 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
curl -L https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases/download/v12.3.0-1/xpack-riscv-none-elf-gcc-12.3.0-1-linux-x64.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
echo "$PWD/xpack-riscv-none-elf-gcc-12.3.0-1/bin" >> $GITHUB_PATH

- name: Install WASI-SDK
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/spec_test_on_nuttx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ jobs:
- name: Install RISC-V Compilers
if: contains(matrix.nuttx_board_config, 'risc-v')
run: |
curl -L -k 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
curl -L https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases/download/v12.3.0-1/xpack-riscv-none-elf-gcc-12.3.0-1-linux-x64.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
echo "$PWD/xpack-riscv-none-elf-gcc-12.3.0-1/bin" >> $GITHUB_PATH

- name: Install WASI-SDK
run: |
Expand Down
24 changes: 22 additions & 2 deletions core/iwasm/compilation/aot_llvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1915,6 +1915,7 @@ static ArchItem valid_archs[] = {
static const char *valid_abis[] = {
"gnu",
"eabi",
"eabihf",
"gnueabihf",
"msvc",
"ilp32",
Expand Down Expand Up @@ -1992,6 +1993,18 @@ get_target_arch_from_triple(const char *triple, char *arch_buf, uint32 buf_size)
bh_assert(*triple == '-' || *triple == '\0');
}

static bool
is_baremetal_target(const char *target, const char *cpu, const char *abi)
{
/* TODO: support more baremetal targets */
if (target) {
/* If target is thumbxxx, then it is baremetal target */
if (!strncmp(target, "thumb", strlen("thumb")))
return true;
}
return false;
}

void
aot_handle_llvm_errmsg(const char *string, LLVMErrorRef err)
{
Expand Down Expand Up @@ -2214,7 +2227,7 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option)
char *triple_norm_new = NULL, *cpu_new = NULL;
char *err = NULL, *fp_round = "round.tonearest",
*fp_exce = "fpexcept.strict";
char triple_buf[32] = { 0 }, features_buf[128] = { 0 };
char triple_buf[128] = { 0 }, features_buf[128] = { 0 };
uint32 opt_level, size_level, i;
LLVMCodeModel code_model;
LLVMTargetDataRef target_data_ref;
Expand Down Expand Up @@ -2510,14 +2523,18 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option)
* for Windows/MacOS under Linux host, or generating AOT file for
* Linux/MacOS under Windows host.
*/

if (!strcmp(abi, "msvc")) {
if (!strcmp(arch1, "i386"))
vendor_sys = "-pc-win32-";
else
vendor_sys = "-pc-windows-";
}
else {
vendor_sys = "-pc-linux-";
if (is_baremetal_target(arch, cpu, abi))
vendor_sys = "-unknown-none-";
else
vendor_sys = "-pc-linux-";
}

bh_assert(strlen(arch1) + strlen(vendor_sys) + strlen(abi)
Expand Down Expand Up @@ -2553,6 +2570,9 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option)
if (!abi)
abi = "msvc";
}
else if (is_baremetal_target(arch, cpu, abi)) {
vendor_sys = "-unknown-none-";
}
else {
vendor_sys = "-pc-linux-";
if (!abi)
Expand Down
11 changes: 10 additions & 1 deletion core/iwasm/libraries/libc-uvwasi/libc_uvwasi_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,16 @@
wasm_runtime_module_free(module_inst, offset)
/* clang-format on */

#define wasi_errno_t uvwasi_errno_t
// uvwasi_errno_t is typedef'd to uint16 which is correct according to the ABI
// specification. However, in WASM, the smallest integer type is int32. If we
// return uint16, we would rely on language SDKs to implement the correct
// behaviour of casting to uint16 before checking the value or using it any way.
// Failure to do so can cause tricky bugs as the upper 16 bits of the error
// result are not guaranteed to be zero'ed by us so the result essentially
// contains garbage from the WASM app perspective. To prevent this, we return
// uint32 directly instead so as not to be reliant on the correct behaviour of
// any current/future SDK implementations.
#define wasi_errno_t uint32_t
#define wasi_fd_t uvwasi_fd_t
#define wasi_clockid_t uvwasi_clockid_t
#define wasi_timestamp_t uvwasi_timestamp_t
Expand Down
11 changes: 10 additions & 1 deletion core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ typedef __wasi_advice_t wasi_advice_t;
typedef __wasi_ciovec_t wasi_ciovec_t;
typedef __wasi_clockid_t wasi_clockid_t;
typedef __wasi_dircookie_t wasi_dircookie_t;
typedef __wasi_errno_t wasi_errno_t;
// __wasi_errno_t is typedef'd to uint16 which is correct according to the ABI
// specification. However, in WASM, the smallest integer type is int32. If we
// return uint16, we would rely on language SDKs to implement the correct
// behaviour of casting to uint16 before checking the value or using it any way.
// Failure to do so can cause tricky bugs as the upper 16 bits of the error
// result are not guaranteed to be zero'ed by us so the result essentially
// contains garbage from the WASM app perspective. To prevent this, we return
// uint32 directly instead so as not to be reliant on the correct behaviour of
// any current/future WASI SDK implemenations.
typedef uint32_t wasi_errno_t;
typedef __wasi_event_t wasi_event_t;
typedef __wasi_exitcode_t wasi_exitcode_t;
typedef __wasi_fdflags_t wasi_fdflags_t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ fd_object_release(wasm_exec_env_t env, struct fd_object *fo)
error = os_closedir(fo->directory.handle);
break;
}
// Fallthrough.
default:
// The env == NULL case is for
// fd_table_destroy, path_get, path_put,
Expand Down
2 changes: 1 addition & 1 deletion doc/export_native_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ As function parameters are always passed in 32 bits numbers, you can also use 'i
//
// If the function signature used i32 data type ("i")
// for buffer address or string parameters, here
// is how to do address conversation and boundary check manually
// is how to do address conversion and boundary check manually
//
void foo2(wasm_exec_env_t exec_env,
uint32 msg_offset,
Expand Down
4 changes: 2 additions & 2 deletions product-mini/platforms/zephyr/simple/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ app_instance_main(wasm_module_inst_t module_inst)
if (wasm_runtime_lookup_function(module_inst, "main", NULL)
|| wasm_runtime_lookup_function(module_inst, "__main_argc_argv",
NULL)) {
LOG_VERBOSE("Calling main funciton\n");
LOG_VERBOSE("Calling main function\n");
wasm_application_execute_main(module_inst, app_argc, app_argv);
}
else if ((func = wasm_runtime_lookup_function(module_inst, "app_main",
Expand All @@ -80,7 +80,7 @@ app_instance_main(wasm_module_inst_t module_inst)
return NULL;
}

LOG_VERBOSE("Calling app_main funciton\n");
LOG_VERBOSE("Calling app_main function\n");
wasm_runtime_call_wasm(exec_env, func, 0, argv);

if (!wasm_runtime_get_exception(module_inst)) {
Expand Down