mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-06-18 02:59:21 +00:00
Compare commits
7 Commits
3cfdf97cde
...
f84d905a97
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f84d905a97 | ||
![]() |
0e8b57d8a8 | ||
![]() |
88b5f6a535 | ||
![]() |
ac2fe552d5 | ||
![]() |
ea417d7619 | ||
![]() |
bb36a43fa4 | ||
![]() |
d3a2cdd8f7 |
|
@ -898,6 +898,17 @@ aot_intrinsic_fill_capability_flags(AOTCompContext *comp_ctx)
|
|||
if (!strncmp(comp_ctx->target_arch, "riscv32", 7)) {
|
||||
add_i64_common_intrinsics(comp_ctx);
|
||||
}
|
||||
/*
|
||||
* LLVM 16 and later expands cttz intrinsic to a table lookup,
|
||||
* which involves some relocations. (unless ZBB is available,
|
||||
* in which case the native instructions are preferred over
|
||||
* the table-based lowering.)
|
||||
* https://reviews.llvm.org/D128911
|
||||
*/
|
||||
#if LLVM_VERSION_MAJOR >= 16
|
||||
add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_I32_CTZ);
|
||||
add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_I64_CTZ);
|
||||
#endif
|
||||
}
|
||||
else if (!strncmp(comp_ctx->target_arch, "xtensa", 6)) {
|
||||
/*
|
||||
|
|
|
@ -4195,13 +4195,13 @@ aot_emit_object_file(AOTCompContext *comp_ctx, char *file_name)
|
|||
bh_print_time("Begin to emit object file");
|
||||
|
||||
if (comp_ctx->external_llc_compiler || comp_ctx->external_asm_compiler) {
|
||||
char cmd[1024];
|
||||
int ret;
|
||||
|
||||
if (comp_ctx->external_llc_compiler) {
|
||||
const char *stack_usage_flag = "";
|
||||
char bc_file_name[64];
|
||||
char su_file_name[65]; /* See the comment below */
|
||||
char *stack_usage_flag = "";
|
||||
char bc_file_name[64] = { 0 };
|
||||
char su_file_name[65] = { 0 };
|
||||
char *argv[10] = { 0 };
|
||||
|
||||
if (comp_ctx->stack_usage_file != NULL) {
|
||||
/*
|
||||
|
@ -4229,14 +4229,16 @@ aot_emit_object_file(AOTCompContext *comp_ctx, char *file_name)
|
|||
return false;
|
||||
}
|
||||
|
||||
snprintf(cmd, sizeof(cmd), "%s%s %s -o %s %s",
|
||||
comp_ctx->external_llc_compiler, stack_usage_flag,
|
||||
comp_ctx->llc_compiler_flags ? comp_ctx->llc_compiler_flags
|
||||
: "-O3 -c",
|
||||
file_name, bc_file_name);
|
||||
LOG_VERBOSE("invoking external LLC compiler:\n\t%s", cmd);
|
||||
argv[0] = stack_usage_flag;
|
||||
argv[1] = comp_ctx->llc_compiler_flags
|
||||
? (char *)comp_ctx->llc_compiler_flags
|
||||
: "-O3 -c";
|
||||
argv[2] = "-o";
|
||||
argv[3] = file_name;
|
||||
argv[4] = bc_file_name;
|
||||
argv[5] = NULL;
|
||||
|
||||
ret = bh_system(cmd);
|
||||
ret = bh_execve(comp_ctx->external_llc_compiler, argv, 6);
|
||||
/* remove temp bitcode file */
|
||||
unlink(bc_file_name);
|
||||
|
||||
|
@ -4263,7 +4265,8 @@ aot_emit_object_file(AOTCompContext *comp_ctx, char *file_name)
|
|||
}
|
||||
}
|
||||
else if (comp_ctx->external_asm_compiler) {
|
||||
char asm_file_name[64];
|
||||
char asm_file_name[64] = { 0 };
|
||||
char *argv[10] = { 0 };
|
||||
|
||||
if (!aot_generate_tempfile_name("wamrc-asm", "s", asm_file_name,
|
||||
sizeof(asm_file_name))) {
|
||||
|
@ -4282,14 +4285,15 @@ aot_emit_object_file(AOTCompContext *comp_ctx, char *file_name)
|
|||
return false;
|
||||
}
|
||||
|
||||
snprintf(cmd, sizeof(cmd), "%s %s -o %s %s",
|
||||
comp_ctx->external_asm_compiler,
|
||||
comp_ctx->asm_compiler_flags ? comp_ctx->asm_compiler_flags
|
||||
: "-O3 -c",
|
||||
file_name, asm_file_name);
|
||||
LOG_VERBOSE("invoking external ASM compiler:\n\t%s", cmd);
|
||||
argv[0] = comp_ctx->asm_compiler_flags
|
||||
? (char *)comp_ctx->asm_compiler_flags
|
||||
: "-O3 -c";
|
||||
argv[1] = "-o";
|
||||
argv[2] = file_name;
|
||||
argv[3] = asm_file_name;
|
||||
argv[4] = NULL;
|
||||
|
||||
ret = bh_system(cmd);
|
||||
ret = bh_execve(comp_ctx->external_asm_compiler, argv, 5);
|
||||
/* remove temp assembly file */
|
||||
unlink(asm_file_name);
|
||||
|
||||
|
|
|
@ -4007,8 +4007,12 @@ aot_resolve_object_relocation_group(AOTObjectData *obj_data,
|
|||
&& (str_starts_with(relocation->symbol_name, ".LCPI")
|
||||
|| str_starts_with(relocation->symbol_name, ".LJTI")
|
||||
|| str_starts_with(relocation->symbol_name, ".LBB")
|
||||
|| str_starts_with(relocation->symbol_name,
|
||||
".Lswitch.table."))) {
|
||||
|| str_starts_with(relocation->symbol_name, ".Lswitch.table.")
|
||||
#if LLVM_VERSION_MAJOR >= 16
|
||||
/* cf. https://reviews.llvm.org/D123264 */
|
||||
|| str_starts_with(relocation->symbol_name, ".Lpcrel_hi")
|
||||
#endif
|
||||
)) {
|
||||
/* change relocation->relocation_addend and
|
||||
relocation->symbol_name */
|
||||
LLVMSectionIteratorRef contain_section;
|
||||
|
@ -4348,18 +4352,23 @@ aot_obj_data_create(AOTCompContext *comp_ctx)
|
|||
else if (!strncmp(LLVMGetTargetName(target), "arc", 3)) {
|
||||
/* Emit to assembly file instead for arc target
|
||||
as it cannot emit to object file */
|
||||
char file_name[] = "wasm-XXXXXX", buf[128];
|
||||
char file_name[] = "wasm-XXXXXX";
|
||||
char assembly_file_name[64] = { 0 };
|
||||
char object_file_name[64] = { 0 };
|
||||
int ret;
|
||||
char *argv[] = { "-mcpu=arcem", "-o", object_file_name, "-c",
|
||||
assembly_file_name, NULL };
|
||||
|
||||
if (!bh_mkstemp(file_name, sizeof(file_name))) {
|
||||
aot_set_last_error("make temp file failed.");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
snprintf(buf, sizeof(buf), "%s%s", file_name, ".s");
|
||||
snprintf(assembly_file_name, sizeof(assembly_file_name) - 1, "%s.s",
|
||||
file_name);
|
||||
if (LLVMTargetMachineEmitToFile(comp_ctx->target_machine,
|
||||
comp_ctx->module, buf, LLVMAssemblyFile,
|
||||
&err)
|
||||
comp_ctx->module, assembly_file_name,
|
||||
LLVMAssemblyFile, &err)
|
||||
!= 0) {
|
||||
if (err) {
|
||||
LLVMDisposeMessage(err);
|
||||
|
@ -4372,14 +4381,14 @@ aot_obj_data_create(AOTCompContext *comp_ctx)
|
|||
/* call arc gcc to compile assembly file to object file */
|
||||
/* TODO: get arc gcc from environment variable firstly
|
||||
and check whether the toolchain exists actually */
|
||||
snprintf(buf, sizeof(buf), "%s%s%s%s%s%s",
|
||||
"/opt/zephyr-sdk/arc-zephyr-elf/bin/arc-zephyr-elf-gcc ",
|
||||
"-mcpu=arcem -o ", file_name, ".o -c ", file_name, ".s");
|
||||
snprintf(object_file_name, sizeof(object_file_name) - 1, "%s.o",
|
||||
file_name);
|
||||
/* TODO: use try..catch to handle possible exceptions */
|
||||
ret = bh_system(buf);
|
||||
/* TODO: use ZEPHYR_SDK_INSTALL_DIR to construct the path */
|
||||
ret = bh_execve("/opt/zephyr-sdk/arc-zephyr-elf/bin/arc-zephyr-elf-gcc",
|
||||
argv, 6);
|
||||
/* remove temp assembly file */
|
||||
snprintf(buf, sizeof(buf), "%s%s", file_name, ".s");
|
||||
unlink(buf);
|
||||
unlink(assembly_file_name);
|
||||
|
||||
if (ret != 0) {
|
||||
aot_set_last_error("failed to compile asm file to obj file "
|
||||
|
@ -4388,12 +4397,10 @@ aot_obj_data_create(AOTCompContext *comp_ctx)
|
|||
}
|
||||
|
||||
/* create memory buffer from object file */
|
||||
snprintf(buf, sizeof(buf), "%s%s", file_name, ".o");
|
||||
ret = LLVMCreateMemoryBufferWithContentsOfFile(buf, &obj_data->mem_buf,
|
||||
&err);
|
||||
ret = LLVMCreateMemoryBufferWithContentsOfFile(
|
||||
object_file_name, &obj_data->mem_buf, &err);
|
||||
/* remove temp object file */
|
||||
snprintf(buf, sizeof(buf), "%s%s", file_name, ".o");
|
||||
unlink(buf);
|
||||
unlink(object_file_name);
|
||||
|
||||
if (ret != 0) {
|
||||
if (err) {
|
||||
|
|
|
@ -9197,6 +9197,15 @@ preserve_referenced_local(WASMLoaderContext *loader_ctx, uint8 opcode,
|
|||
loader_ctx->preserved_local_offset += 2;
|
||||
emit_label(EXT_OP_COPY_STACK_TOP_I64);
|
||||
}
|
||||
|
||||
/* overflow */
|
||||
if (preserved_offset > loader_ctx->preserved_local_offset) {
|
||||
set_error_buf_v(error_buf, error_buf_size,
|
||||
"too much local cells 0x%x",
|
||||
loader_ctx->preserved_local_offset);
|
||||
return false;
|
||||
}
|
||||
|
||||
emit_operand(loader_ctx, local_index);
|
||||
emit_operand(loader_ctx, preserved_offset);
|
||||
emit_label(opcode);
|
||||
|
|
|
@ -4778,6 +4778,11 @@ preserve_referenced_local(WASMLoaderContext *loader_ctx, uint8 opcode,
|
|||
loader_ctx->preserved_local_offset += 2;
|
||||
emit_label(EXT_OP_COPY_STACK_TOP_I64);
|
||||
}
|
||||
|
||||
/* overflow */
|
||||
bh_assert(preserved_offset
|
||||
<= loader_ctx->preserved_local_offset);
|
||||
|
||||
emit_operand(loader_ctx, local_index);
|
||||
emit_operand(loader_ctx, preserved_offset);
|
||||
emit_label(opcode);
|
||||
|
|
|
@ -167,15 +167,39 @@ wa_strdup(const char *s)
|
|||
}
|
||||
|
||||
#if WASM_ENABLE_WAMR_COMPILER != 0 || WASM_ENABLE_JIT != 0
|
||||
/* need to make sure that The `argv[]` must be terminated by a NULL pointer. */
|
||||
int
|
||||
bh_system(const char *cmd)
|
||||
bh_execve(const char *pathname, char *const argv[], int argc)
|
||||
{
|
||||
int ret;
|
||||
/* no environment variables */
|
||||
char *const envp[] = { NULL };
|
||||
|
||||
if (pathname == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (argc > 0) {
|
||||
if (argv == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* The `argv[]` must be terminated by a NULL pointer. */
|
||||
if (argv[argc - 1] != NULL) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
#if !(defined(_WIN32) || defined(_WIN32_))
|
||||
ret = system(cmd);
|
||||
ret = execve(pathname, argv, envp);
|
||||
#ifndef NDEBUG
|
||||
if (ret == -1) {
|
||||
LOG_WARNING("execute \"%s\" failed because of \"%s\"", pathname,
|
||||
strerror(errno));
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
ret = _spawnlp(_P_WAIT, "cmd.exe", "/c", cmd, NULL);
|
||||
ret = _execve(pathname, argv, envp);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -67,9 +67,19 @@ char *
|
|||
wa_strdup(const char *s);
|
||||
|
||||
#if WASM_ENABLE_WAMR_COMPILER != 0 || WASM_ENABLE_JIT != 0
|
||||
/* Executes a system command in bash/cmd.exe */
|
||||
/*
|
||||
* Executes a program referred to by cmd in bash/cmd.exe
|
||||
* Always be sure that argv[argc-1] == NULL
|
||||
*
|
||||
* @param pathname The program to execute. need to be absolute path.
|
||||
* @param argv The command line arguments.
|
||||
* @param argc The number of command line arguments.
|
||||
*
|
||||
* like to execute "ls -l /tmp":
|
||||
* bh_execve("/bin/ls", (char *const []){ "-l", "/tmp", NULL }, 3);
|
||||
*/
|
||||
int
|
||||
bh_system(const char *cmd);
|
||||
bh_execve(const char *pathname, char *const argv[], int argc);
|
||||
|
||||
/* Tests whether can create a temporary file with the given name */
|
||||
bool
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
# WARM API
|
||||
# WAMR API
|
||||
|
||||
* **Notice**: The python package `wamr.wamrapi.wamr` need python >= `3.10`.
|
||||
* **Notice**: The python package `wamr.wamrapi.wamr` requires a python version >= `3.10`.
|
||||
|
||||
## Setup
|
||||
|
||||
### Pre-requisites
|
||||
#### Install requirements
|
||||
Before proceeding it is necessary to make sure your Python environment is correctly configured. To do ths open a terminal session in this directory and perfom the following:
|
||||
|
||||
Install requirements,
|
||||
|
||||
```shell
|
||||
python3 -m venv venv
|
||||
source venv/bin/activate
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
|
|
|
@ -205,12 +205,3 @@ foreach(EX ${EXAMPLES})
|
|||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
endforeach()
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
find_program(VALGRIND
|
||||
valgrind
|
||||
REQUIRED
|
||||
)
|
||||
|
||||
# run `ctest -T memcheck -V --test-dir build`
|
||||
endif()
|
||||
|
|
|
@ -25,6 +25,6 @@ set (unit_test_sources
|
|||
|
||||
add_executable (shared_utils_test ${unit_test_sources})
|
||||
|
||||
target_link_libraries (shared_utils_test gtest_main)
|
||||
target_link_libraries (shared_utils_test gtest_main ${LLVM_AVAILABLE_LIBS})
|
||||
|
||||
gtest_discover_tests(shared_utils_test)
|
||||
|
|
|
@ -94,3 +94,13 @@ TEST_F(bh_common_test_suite, b_memcpy_s)
|
|||
EXPECT_EQ(-1, b_memcpy_s(dest, sizeof(dest), nullptr, sizeof(STR_TEST)));
|
||||
EXPECT_EQ(-1, b_memcpy_s(dest, sizeof(dest), STR_TEST, sizeof(dest) + 1));
|
||||
}
|
||||
|
||||
TEST_F(bh_common_test_suite, bh_execve)
|
||||
{
|
||||
#if WASM_ENABLE_WAMR_COMPILER != 0 || WASM_ENABLE_JIT != 0
|
||||
char *const argv[] = { "-n", "\"hello\"", "world", "\n", nullptr };
|
||||
EXPECT_EQ(0, bh_execve("/usr/bin/echo", argv, 5));
|
||||
#else
|
||||
GTEST_SKIP() << "bh_execve() is not supported";
|
||||
#endif
|
||||
}
|
Loading…
Reference in New Issue
Block a user