diff --git a/core/iwasm/compilation/aot_llvm.c b/core/iwasm/compilation/aot_llvm.c index 8fd6e82920..96d6c8c620 100644 --- a/core/iwasm/compilation/aot_llvm.c +++ b/core/iwasm/compilation/aot_llvm.c @@ -1610,7 +1610,74 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option) abi = "ilp32d"; } - if (arch) { +#if defined(__APPLE__) || defined(__MACH__) + if (!abi) { + /* On MacOS platform, set abi to "gnu" to avoid generating + object file of Mach-O binary format which is unsupported */ + abi = "gnu"; + if (!arch && !cpu && !features) { + /* Get CPU name of the host machine to avoid checking + SIMD capability failed */ + if (!(cpu = cpu_new = LLVMGetHostCPUName())) { + aot_set_last_error("llvm get host cpu name failed."); + goto fail; + } + } + } +#endif + + if (abi) { + /* Construct target triple: --- */ + const char *vendor_sys; + char *arch1 = arch, default_arch[32] = { 0 }; + + if (!arch1) { + char *default_triple = LLVMGetDefaultTargetTriple(); + + if (!default_triple) { + aot_set_last_error( + "llvm get default target triple failed."); + goto fail; + } + + vendor_sys = strstr(default_triple, "-"); + bh_assert(vendor_sys); + bh_memcpy_s(default_arch, sizeof(default_arch), default_triple, + vendor_sys - default_triple); + arch1 = default_arch; + + LLVMDisposeMessage(default_triple); + } + + /** + * Set - according to abi to generate the object file + * with the correct file format which might be different from the + * default object file format of the host, e.g., generating AOT file + * 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-"; + } + + bh_assert(strlen(arch1) + strlen(vendor_sys) + strlen(abi) + < sizeof(triple_buf)); + bh_memcpy_s(triple_buf, sizeof(triple_buf), arch1, strlen(arch1)); + bh_memcpy_s(triple_buf + strlen(arch1), + sizeof(triple_buf) - strlen(arch1), vendor_sys, + strlen(vendor_sys)); + bh_memcpy_s(triple_buf + strlen(arch1) + strlen(vendor_sys), + sizeof(triple_buf) - strlen(arch1) - strlen(vendor_sys), + abi, strlen(abi)); + triple = triple_buf; + } + else if (arch) { /* Construct target triple: --- */ const char *vendor_sys; char *default_triple = LLVMGetDefaultTargetTriple(); @@ -1640,10 +1707,13 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option) bh_assert(strlen(arch) + strlen(vendor_sys) + strlen(abi) < sizeof(triple_buf)); - memcpy(triple_buf, arch, strlen(arch)); - memcpy(triple_buf + strlen(arch), vendor_sys, strlen(vendor_sys)); - memcpy(triple_buf + strlen(arch) + strlen(vendor_sys), abi, - strlen(abi)); + bh_memcpy_s(triple_buf, sizeof(triple_buf), arch, strlen(arch)); + bh_memcpy_s(triple_buf + strlen(arch), + sizeof(triple_buf) - strlen(arch), vendor_sys, + strlen(vendor_sys)); + bh_memcpy_s(triple_buf + strlen(arch) + strlen(vendor_sys), + sizeof(triple_buf) - strlen(arch) - strlen(vendor_sys), + abi, strlen(abi)); triple = triple_buf; } diff --git a/core/shared/platform/common/posix/posix_memmap.c b/core/shared/platform/common/posix/posix_memmap.c index 3ba77baaa6..3a22a5064e 100644 --- a/core/shared/platform/common/posix/posix_memmap.c +++ b/core/shared/platform/common/posix/posix_memmap.c @@ -16,6 +16,7 @@ static size_t total_size_munmapped = 0; #define HUGE_PAGE_SIZE (2 * 1024 * 1024) +#if !defined(__APPLE__) && !defined(__NuttX__) static inline uintptr_t round_up(uintptr_t v, uintptr_t b) { @@ -29,6 +30,7 @@ round_down(uintptr_t v, uintptr_t b) uintptr_t m = b - 1; return v & ~m; } +#endif void * os_mmap(void *hint, size_t size, int prot, int flags) diff --git a/product-mini/platforms/darwin/CMakeLists.txt b/product-mini/platforms/darwin/CMakeLists.txt index 5ef30eb4cb..4dc6da7afa 100644 --- a/product-mini/platforms/darwin/CMakeLists.txt +++ b/product-mini/platforms/darwin/CMakeLists.txt @@ -55,8 +55,8 @@ if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN) endif () if (NOT DEFINED WAMR_BUILD_LIBC_WASI) - # Disable libc wasi support by default - set (WAMR_BUILD_LIBC_WASI 0) + # Enable libc wasi support by default + set (WAMR_BUILD_LIBC_WASI 1) endif () if (NOT DEFINED WAMR_BUILD_FAST_INTERP) @@ -65,7 +65,7 @@ if (NOT DEFINED WAMR_BUILD_FAST_INTERP) endif () if (NOT DEFINED WAMR_BUILD_MULTI_MODULE) - # Enable multiple modules + # Disable multiple module by default set (WAMR_BUILD_MULTI_MODULE 0) endif () diff --git a/tests/wamr-test-suites/spec-test-script/all.py b/tests/wamr-test-suites/spec-test-script/all.py index 65a102a315..e19ad6fde9 100644 --- a/tests/wamr-test-suites/spec-test-script/all.py +++ b/tests/wamr-test-suites/spec-test-script/all.py @@ -21,7 +21,8 @@ The script itself has to be put under the same directory with the "spec". """ -IWASM_CMD = "../../../product-mini/platforms/linux/build/iwasm" +PLATFORM_NAME = os.uname().sysname.lower() +IWASM_CMD = "../../../product-mini/platforms/" + PLATFORM_NAME + "/build/iwasm" IWASM_SGX_CMD = "../../../product-mini/platforms/linux-sgx/enclave-sample/iwasm" SPEC_TEST_DIR = "spec/test/core" WAST2WASM_CMD = "./wabt/out/gcc/Release/wat2wasm" diff --git a/tests/wamr-test-suites/spec-test-script/runtest.py b/tests/wamr-test-suites/spec-test-script/runtest.py index 7db0c042aa..920b0d0f36 100755 --- a/tests/wamr-test-suites/spec-test-script/runtest.py +++ b/tests/wamr-test-suites/spec-test-script/runtest.py @@ -141,6 +141,8 @@ def cleanup(self): os.killpg(self.p.pid, signal.SIGTERM) except OSError: pass + except IOError: + pass self.p = None self.stdin.close() if self.stdin != self.stdout: diff --git a/wamr-compiler/main.c b/wamr-compiler/main.c index c25d1ef1b7..885a1382fa 100644 --- a/wamr-compiler/main.c +++ b/wamr-compiler/main.c @@ -79,7 +79,7 @@ main(int argc, char *argv[]) AOTCompOption option = { 0 }; char error_buf[128]; int log_verbose_level = 2; - bool sgx_mode = false; + bool sgx_mode = false, size_level_set = false; int exit_status = EXIT_FAILURE; option.opt_level = 3; @@ -133,6 +133,7 @@ main(int argc, char *argv[]) option.size_level = (uint32)atoi(argv[0] + 13); if (option.size_level > 3) option.size_level = 3; + size_level_set = true; } else if (!strcmp(argv[0], "-sgx")) { sgx_mode = true; @@ -207,6 +208,26 @@ main(int argc, char *argv[]) if (argc == 0 || !out_file_name) return print_help(); + if (!size_level_set) { + /** + * Set opt level to 1 by default for Windows and MacOS as + * they can not memory map out 0-2GB memory and might not + * be able to meet the requirements of some AOT relocation + * operations. + */ + if (option.target_abi && !strcmp(option.target_abi, "msvc")) { + LOG_VERBOSE("Set size level to 1 for Windows AOT file"); + option.size_level = 1; + } +#if defined(_WIN32) || defined(_WIN32_) || defined(__APPLE__) \ + || defined(__MACH__) + if (!option.target_abi) { + LOG_VERBOSE("Set size level to 1 for Windows or MacOS AOT file"); + option.size_level = 1; + } +#endif + } + if (sgx_mode) { option.size_level = 1; option.is_sgx_platform = true;