From 3f3a2144111976fd8aa67d31e68252fb8ecb7b67 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 25 Apr 2025 10:28:35 +0900 Subject: [PATCH 01/11] build-scripts/build_llvm.py: bump to llvm 19 cf. https://github.com/bytecodealliance/wasm-micro-runtime/issues/4210 why 19, not 20? because, as of writing this, 19 is the latest released version for the xtensa fork of llvm: https://github.com/espressif/llvm-project while we can use different versions for different targets, it's nicer to use the same version everywhere when possible. --- build-scripts/build_llvm.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build-scripts/build_llvm.py b/build-scripts/build_llvm.py index d8bcbd26c..d94c691e6 100755 --- a/build-scripts/build_llvm.py +++ b/build-scripts/build_llvm.py @@ -294,17 +294,17 @@ def main(): "arc": { "repo": "https://github.com/llvm/llvm-project.git", "repo_ssh": "git@github.com:llvm/llvm-project.git", - "branch": "release/15.x", + "branch": "release/19.x", }, "xtensa": { "repo": "https://github.com/espressif/llvm-project.git", "repo_ssh": "git@github.com:espressif/llvm-project.git", - "branch": "xtensa_release_17.0.1", + "branch": "xtensa_release_19.1.2", }, "default": { "repo": "https://github.com/llvm/llvm-project.git", "repo_ssh": "git@github.com:llvm/llvm-project.git", - "branch": "release/15.x", + "branch": "release/19.x", }, } From 766145a16627e7b24f50391348cb785a8bceab03 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 25 Apr 2025 11:15:42 +0900 Subject: [PATCH 02/11] spec-test-script/runtest.py: --size-level=0 for x86-64 with the recent version of LLVM, wamrc --size-level=1 often generates R_X86_64_32S relocations which fail on load with the infamous error: "relocation truncated to fit R_X86_64_32S failed" it seems that these relocations are often for jump tables. this commit workarounds it with --size-level=0. an alternative is to disable jump tables. (although it seems that jump tables are not the only source of these relocations.) cf. https://github.com/bytecodealliance/wasm-micro-runtime/issues/3035 it might be better to do this in wamrc itself. however, currently target info is not available there in case of native compilation. related: https://github.com/bytecodealliance/wasm-micro-runtime/issues/3356 --- tests/wamr-test-suites/spec-test-script/runtest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/wamr-test-suites/spec-test-script/runtest.py b/tests/wamr-test-suites/spec-test-script/runtest.py index 8de001af6..158d759ed 100755 --- a/tests/wamr-test-suites/spec-test-script/runtest.py +++ b/tests/wamr-test-suites/spec-test-script/runtest.py @@ -46,7 +46,8 @@ temp_module_table = {} aot_target_options_map = { "i386": ["--target=i386"], "x86_32": ["--target=i386"], - "x86_64": ["--target=x86_64", "--cpu=skylake"], + # cf. https://github.com/bytecodealliance/wasm-micro-runtime/issues/3035 + "x86_64": ["--target=x86_64", "--cpu=skylake", "--size-level=0"], "aarch64": ["--target=aarch64", "--target-abi=eabi", "--cpu=cortex-a53"], "aarch64_vfp": ["--target=aarch64", "--target-abi=gnueabihf", "--cpu=cortex-a53"], "armv7": ["--target=armv7", "--target-abi=eabi", "--cpu=cortex-a9", "--cpu-features=-neon"], From b8bd1ef2747f57905808d3fdc6d3716b2a1a0d6a Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 25 Apr 2025 11:33:32 +0900 Subject: [PATCH 03/11] wamr-compiler: size_level=0 for sgx mode cf. https://github.com/bytecodealliance/wasm-micro-runtime/issues/3035 --- wamr-compiler/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wamr-compiler/main.c b/wamr-compiler/main.c index 4d1a24b54..f74b2fb15 100644 --- a/wamr-compiler/main.c +++ b/wamr-compiler/main.c @@ -712,7 +712,7 @@ main(int argc, char *argv[]) } if (sgx_mode) { - option.size_level = 1; + option.size_level = 0; option.is_sgx_platform = true; } From 4d73ab0bbcdbefb4bbd46c3aaf000539446544e6 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 1 May 2025 08:54:52 +0900 Subject: [PATCH 04/11] aot_resolve_object_relocation_group: adapt to LLVM 19 cf. https://github.com/llvm/llvm-project/pull/95031 https://github.com/llvm/llvm-project/pull/89693 --- core/iwasm/compilation/aot_emit_aot_file.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/iwasm/compilation/aot_emit_aot_file.c b/core/iwasm/compilation/aot_emit_aot_file.c index 5a7ba9e74..097727d13 100644 --- a/core/iwasm/compilation/aot_emit_aot_file.c +++ b/core/iwasm/compilation/aot_emit_aot_file.c @@ -4011,6 +4011,15 @@ aot_resolve_object_relocation_group(AOTObjectData *obj_data, #if LLVM_VERSION_MAJOR >= 16 /* cf. https://reviews.llvm.org/D123264 */ || str_starts_with(relocation->symbol_name, ".Lpcrel_hi") +#endif +#if LLVM_VERSION_MAJOR >= 19 + /* cf. + * https://github.com/llvm/llvm-project/pull/95031 + * https://github.com/llvm/llvm-project/pull/89693 + * + * note: the trailing space in ".L0 " is intentional. */ + || !strcmp(relocation->symbol_name, "") + || !strcmp(relocation->symbol_name, ".L0 ") #endif )) { /* change relocation->relocation_addend and From 0c9dd5a3465079b01eb7c42ca5159b66a024add0 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 1 May 2025 13:02:55 +0900 Subject: [PATCH 05/11] wamr-test-suites: disable xtensa text section literals for now --- tests/wamr-test-suites/spec-test-script/runtest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/wamr-test-suites/spec-test-script/runtest.py b/tests/wamr-test-suites/spec-test-script/runtest.py index 158d759ed..ebcbad0d1 100755 --- a/tests/wamr-test-suites/spec-test-script/runtest.py +++ b/tests/wamr-test-suites/spec-test-script/runtest.py @@ -67,7 +67,8 @@ aot_target_options_map = { # AOT compilation options mapping for XIP mode aot_target_options_map_xip = { # avoid l32r relocations for xtensa - "xtensa": ["--mllvm=-mtext-section-literals"], + # disabled for now: https://github.com/espressif/llvm-project/issues/112 + # "xtensa": ["--mllvm=-mtext-section-literals"], "riscv32_ilp32f": ["--enable-builtin-intrinsics=i64.common,f64.common,f32.const,f64.const,f64xi32,f64xi64,f64_promote_f32,f32_demote_f64"], } From 14be14f3374cae9cd5aa734af491afdaa9d66aca Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 1 May 2025 19:45:19 +0900 Subject: [PATCH 06/11] aot_create_comp_context: disable small data section I observed errors like the following when trying to upgrade our LLVM from 15 to 19. ``` AOT module load failed: resolve symbol .srodata.cst8 failed ``` The concept itself has been available since LLVM 9. I don't know what exactly happened to trigger the use of it. cf. https://reviews.llvm.org/D57493 --- core/iwasm/compilation/aot_llvm.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/iwasm/compilation/aot_llvm.c b/core/iwasm/compilation/aot_llvm.c index c1708e3f9..9fa415a6d 100644 --- a/core/iwasm/compilation/aot_llvm.c +++ b/core/iwasm/compilation/aot_llvm.c @@ -2617,6 +2617,15 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option) goto fail; } +#if LLVM_VERSION_MAJOR >= 9 + /* Disable small data section as our emitter/loader doesn't support it. + * https://reviews.llvm.org/D57493 */ + LLVMAddModuleFlag( + comp_ctx->module, LLVMModuleFlagBehaviorWarning, "SmallDataLimit", + strlen("SmallDataLimit"), + LLVMValueAsMetadata(LLVMConstInt(LLVMInt32Type(), 0, false))); +#endif + #if WASM_ENABLE_DEBUG_AOT != 0 if (!(comp_ctx->debug_builder = LLVMCreateDIBuilder(comp_ctx->module))) { aot_set_last_error("create LLVM Debug Infor builder failed."); From db6ea1d0f4c8d1c9bcb444c8b83c671c94c71b1c Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 1 May 2025 21:54:27 +0900 Subject: [PATCH 07/11] Revert "wamr-test-suites: disable xtensa text section literals for now" This reverts commit 6b7ff691fee2b342c5ddf065eac4ceb12456652a. --- tests/wamr-test-suites/spec-test-script/runtest.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/wamr-test-suites/spec-test-script/runtest.py b/tests/wamr-test-suites/spec-test-script/runtest.py index ebcbad0d1..158d759ed 100755 --- a/tests/wamr-test-suites/spec-test-script/runtest.py +++ b/tests/wamr-test-suites/spec-test-script/runtest.py @@ -67,8 +67,7 @@ aot_target_options_map = { # AOT compilation options mapping for XIP mode aot_target_options_map_xip = { # avoid l32r relocations for xtensa - # disabled for now: https://github.com/espressif/llvm-project/issues/112 - # "xtensa": ["--mllvm=-mtext-section-literals"], + "xtensa": ["--mllvm=-mtext-section-literals"], "riscv32_ilp32f": ["--enable-builtin-intrinsics=i64.common,f64.common,f32.const,f64.const,f64xi32,f64xi64,f64_promote_f32,f32_demote_f64"], } From 26c35cbb6c42ae8e6f8c20d57d9397508023ae3a Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 1 May 2025 21:58:42 +0900 Subject: [PATCH 08/11] spec_test_on_nuttx.yml: disable xtensa xip --- .github/workflows/spec_test_on_nuttx.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/spec_test_on_nuttx.yml b/.github/workflows/spec_test_on_nuttx.yml index 6c36c45ca..6daec91dc 100644 --- a/.github/workflows/spec_test_on_nuttx.yml +++ b/.github/workflows/spec_test_on_nuttx.yml @@ -139,6 +139,11 @@ jobs: - target_config: { target: "xtensa" } wamr_feature_option: { mode: "-G" } + # disabled for now: + # https://github.com/espressif/llvm-project/issues/112 + - target_config: { target: "xtensa" } + wamr_test_option: { mode: "-t aot -X" } + steps: # Note: we use an unreleased version nuttx for xtensa because # 12.4 doesn't contain necessary esp32s3 changes. From 0df6dc42af014e72548bb48720dcda0d8f8c4f3d Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 2 May 2025 14:00:37 +0900 Subject: [PATCH 09/11] Revert "aot_create_comp_context: disable small data section" This reverts commit 6ae395a8ceafcbdc2725452ab0e0cb73deb887a8. --- core/iwasm/compilation/aot_llvm.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/core/iwasm/compilation/aot_llvm.c b/core/iwasm/compilation/aot_llvm.c index 9fa415a6d..c1708e3f9 100644 --- a/core/iwasm/compilation/aot_llvm.c +++ b/core/iwasm/compilation/aot_llvm.c @@ -2617,15 +2617,6 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option) goto fail; } -#if LLVM_VERSION_MAJOR >= 9 - /* Disable small data section as our emitter/loader doesn't support it. - * https://reviews.llvm.org/D57493 */ - LLVMAddModuleFlag( - comp_ctx->module, LLVMModuleFlagBehaviorWarning, "SmallDataLimit", - strlen("SmallDataLimit"), - LLVMValueAsMetadata(LLVMConstInt(LLVMInt32Type(), 0, false))); -#endif - #if WASM_ENABLE_DEBUG_AOT != 0 if (!(comp_ctx->debug_builder = LLVMCreateDIBuilder(comp_ctx->module))) { aot_set_last_error("create LLVM Debug Infor builder failed."); From 0860d7fda6c793d88b4def68cf4143cb7112f669 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 2 May 2025 15:45:49 +0900 Subject: [PATCH 10/11] CI: make macos' build_samples_wasm_c_api similar to ubuntu --- .github/workflows/compilation_on_macos.yml | 62 +++++++++++++++++----- 1 file changed, 50 insertions(+), 12 deletions(-) diff --git a/.github/workflows/compilation_on_macos.yml b/.github/workflows/compilation_on_macos.yml index cf5578cfb..b59f841c5 100644 --- a/.github/workflows/compilation_on_macos.yml +++ b/.github/workflows/compilation_on_macos.yml @@ -46,11 +46,14 @@ concurrency: cancel-in-progress: true env: - AOT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0" - CLASSIC_INTERP_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=0 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0" - FAST_INTERP_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=0 -DWAMR_BUILD_FAST_INTERP=1 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0" - LLVM_LAZY_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=1" - LLVM_EAGER_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=0" + # For BUILD + AOT_BUILD_OPTIONS: " -DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_FAST_JIT=0 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0" + CLASSIC_INTERP_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=0 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_JIT=0 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0" + FAST_INTERP_BUILD_OPTIONS: " -DWAMR_BUILD_AOT=0 -DWAMR_BUILD_FAST_INTERP=1 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_JIT=0 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0" + FAST_JIT_BUILD_OPTIONS: " -DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0" + LLVM_LAZY_JIT_BUILD_OPTIONS: " -DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_FAST_JIT=0 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=1" + LLVM_EAGER_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_FAST_JIT=0 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=0" + MULTI_TIER_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=1" permissions: contents: read @@ -214,33 +217,68 @@ jobs: working-directory: product-mini/platforms/${{ matrix.platform }} build_samples_wasm_c_api: - needs: [build_iwasm] + needs: + [ + build_iwasm, + build_llvm_libraries_on_intel_macos, + build_wamrc, + ] runs-on: ${{ matrix.os }} strategy: matrix: make_options: [ - # Running modes supported + $AOT_BUILD_OPTIONS, $CLASSIC_INTERP_BUILD_OPTIONS, $FAST_INTERP_BUILD_OPTIONS, - # Running modes unsupported - #$LLVM_LAZY_JIT_BUILD_OPTIONS, - #$LLVM_EAGER_JIT_BUILD_OPTIONS, - #$AOT_BUILD_OPTIONS, + $FAST_JIT_BUILD_OPTIONS, + $LLVM_LAZY_JIT_BUILD_OPTIONS, + $LLVM_EAGER_JIT_BUILD_OPTIONS, + $MULTI_TIER_JIT_BUILD_OPTIONS, ] os: [macos-13] + include: + - os: macos-13 + llvm_cache_key: ${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }} + steps: - name: checkout uses: actions/checkout@v4 + - name: Get LLVM libraries + id: retrieve_llvm_libs + if: (!endsWith(matrix.make_options, '_INTERP_BUILD_OPTIONS')) + uses: actions/cache@v4 + with: + path: | + ./core/deps/llvm/build/bin + ./core/deps/llvm/build/include + ./core/deps/llvm/build/lib + ./core/deps/llvm/build/libexec + ./core/deps/llvm/build/share + key: ${{ matrix.llvm_cache_key }} + + - name: Quit if cache miss + if: (!endsWith(matrix.make_options, '_INTERP_BUILD_OPTIONS')) && (steps.retrieve_llvm_libs.outputs.cache-hit != 'true') + run: echo "::error::can not get prebuilt llvm libraries" && exit 1 + - name: install-wasi-sdk-wabt uses: ./.github/actions/install-wasi-sdk-wabt with: os: ${{ matrix.os }} + - name: Build wamrc + if: (!endsWith(matrix.make_options, '_INTERP_BUILD_OPTIONS')) + run: | + mkdir build && cd build + cmake .. + cmake --build . --config Release --parallel 4 + working-directory: wamr-compiler + - name: Build Sample [wasm-c-api] run: | + VERBOSE=1 cmake -S . -B build ${{ matrix.make_options }} - cmake --build build --config Release --parallel 4 + cmake --build build --config Debug --parallel 4 ctest --test-dir build --output-on-failure working-directory: samples/wasm-c-api From 10e7fb7012fc297eaf27f5996692c3af97c6150f Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 7 May 2025 17:51:49 +0900 Subject: [PATCH 11/11] JIT: don't join worker threads twice in case of WASM_ENABLE_LAZY_JIT==0, compile_jit_functions should have already joined these threads. joining them again here is an undefined behavior. --- core/iwasm/interpreter/wasm_loader.c | 2 ++ core/iwasm/interpreter/wasm_mini_loader.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index ef4020a36..8e21414ea 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -5711,6 +5711,7 @@ orcjit_thread_callback(void *arg) static void orcjit_stop_compile_threads(WASMModule *module) { +#if WASM_ENABLE_LAZY_JIT != 0 uint32 i, thread_num = (uint32)(sizeof(module->orcjit_thread_args) / sizeof(OrcJitThreadArg)); @@ -5719,6 +5720,7 @@ orcjit_stop_compile_threads(WASMModule *module) if (module->orcjit_threads[i]) os_thread_join(module->orcjit_threads[i], NULL); } +#endif } static bool diff --git a/core/iwasm/interpreter/wasm_mini_loader.c b/core/iwasm/interpreter/wasm_mini_loader.c index 23fb76370..4a4bed1cb 100644 --- a/core/iwasm/interpreter/wasm_mini_loader.c +++ b/core/iwasm/interpreter/wasm_mini_loader.c @@ -2493,6 +2493,7 @@ orcjit_thread_callback(void *arg) static void orcjit_stop_compile_threads(WASMModule *module) { +#if WASM_ENABLE_LAZY_JIT != 0 uint32 i, thread_num = (uint32)(sizeof(module->orcjit_thread_args) / sizeof(OrcJitThreadArg)); @@ -2501,6 +2502,7 @@ orcjit_stop_compile_threads(WASMModule *module) if (module->orcjit_threads[i]) os_thread_join(module->orcjit_threads[i], NULL); } +#endif } static bool