Skip to content

Adjust SIMD* compilation flags to satisfy both fast-interpreter and AOT on Windows #4216

@lum1n0us

Description

@lum1n0us

There is a problem during invokeNative() when using the main branch with fast-interpreter running mode on Windows.

It can be reproduced by a simple "Hello World" program.

// in hello.c
#include <stdio.h>

int main() {
    printf("Hello, World!\n");
    return 0;
}

use /opt/wasi-sdk-25.0-x86_64-linux/bin/clang-19 -o hello.wasm ./hello.c to generate a .wasm.

iwasm should be compiled with these options.

# in wasm-micro-runtime/product-mini/platforms/windows
$ cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DWAMR_BUILD_REF_TYPES=1

-- Building for: Visual Studio 17 2022
-- The C compiler identification is MSVC 19.41.34123.0
-- The ASM compiler identification is MSVC
-- Found assembler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.41.34120/bin/Hostx64/x64/cl.exe
-- The CXX compiler identification is MSVC 19.41.34123.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.41.34120/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features       
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.41.34120/bin/Hostx64/x64/cl.exe - skipped
...

You will see the result like this.

$ wasm-micro-runtime/product-mini/platforms/windows/build/Debug/iwasm.exe ./hello.wasm 

Segmentation fault   <-- 💣 💥 

If you take a closer look, you will find that when invoking a native function, like wasi_fd_fdstat_get(), all arguments are invalid, such as being NULL.

This is because invokeNative_em64_simd.asm is used when WAMR_BUILD_SIMD is enabled in core/iwasm/common/iwasm_common.cmake.

However, at the same time, config_common.cmake disables WASM_ENABLE_SIMD,

if (WAMR_BUILD_SIMD EQUAL 1)
  if (WAMR_BUILD_FAST_INTERP EQUAL 1 AND WAMR_BUILD_SIMDE EQUAL 0)
    set(SIMD_ENABLED 0)
    message("     SIMD disabled for fast-interp as simde is not being built")
  elseif (WAMR_BUILD_TARGET MATCHES "RISCV64.*")
    set(SIMD_ENABLED 0)
    message ("     SIMD disabled due to not supported on target RISCV64")
  else()
    set(SIMD_ENABLED 1)
    message ("     SIMD enabled")
  endif ()
  add_definitions(-DWASM_ENABLE_SIMD=${SIMD_ENABLED})
endif ()

which leads to wasm_runtime_invoke_native() preparing argv1 under the condition of #if WASM_ENABLE_SIMD==0.

You will also see that during the CMake compilation information.

-- SIMDe doesnt support platform windows     <-  1‍⃣ 
-- WAMR version: 2.2.0
-- Build Configurations:
     Build as target X86_64
     Build for platform windows
     CMAKE_BUILD_TYPE Debug
     BUILD_SHARED_LIBS OFF
     WAMR Interpreter enabled
     Fast interpreter enabled
     WAMR AOT enabled
     WAMR Fast JIT disabled
     WAMR LLVM ORC JIT disabled
     Libc builtin enabled
     Libc WASI enabled
     Multiple modules disabled
     Copy callstack disabled
     Wakeup of blocking operations enabled
     SIMD disabled for fast-interp as simde is not being built   <- 2‍⃣ 
     GC performance profiling disabled
     Module instance context enabled
     Quick AOT/JIT entries enabled
     AOT intrinsics enabled
     Shrunk memory enabled
-- About Wasm Proposals:
     Always-on:
       "Extended Constant Expressions"
       "Multi-value"
       "Non-trapping float-to-int conversions"
       "Sign-extension operators"
       "WebAssembly C and C++ API"
     Configurable. 0 is OFF. 1 is ON:
       "Bulk Memory Operation" via WAMR_BUILD_BULK_MEMORY: 1
       "Fixed-width SIMD" via WAMR_BUILD_SIMD: 1                   <- 3‍⃣ 
       "Garbage collection" via WAMR_BUILD_GC: 0
       "Legacy Exception handling" via WAMR_BUILD_EXCE_HANDLING: 0
       "Memory64" via WAMR_BUILD_MEMORY64: 0
       "Multiple memories" via WAMR_BUILD_MULTI_MEMORY: 0
       "Reference Types" via WAMR_BUILD_REF_TYPES: 1
       "Reference-Typed Strings" via WAMR_BUILD_STRINGREF: 0
       "Tail call" via WAMR_BUILD_TAIL_CALL: 0
       "Threads" via WAMR_BUILD_SHARED_MEMORY: 0
       "Typed Function References" via WAMR_BUILD_GC: 0
     Unsupported (>= Phase4):
       "Branch Hinting"
       "Custom Annotation Syntax in the Text Format"
       "Exception handling"
       "Import/Export of Mutable Globals"
       "JS String Builtins"
       "Relaxed SIMD"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions