Description
Hi,
I encounter this error when trying to compile some C code to wasm. To reproduce this error:
$ wasi-sdk-22.0/bin/clang -v -Wl,--version --target=wasm32-wasip2
clang version 18.1.2 (https://github.com/llvm/llvm-project 26a1d6601d727a96f4301d0d8647b5a42760ae0c)
Target: wasm32-unknown-wasip2
Thread model: posix
InstalledDir: wasi-sdk-22.0/bin
"wasi-sdk-22.0/bin/wasm-component-ld" -m wasm32 --wasm-ld-path wasi-sdk-22.0/bin/wasm-ld -Lwasi-sdk-22.0/bin/../share/wasi-sysroot/lib/wasm32-wasip2 wasi-sdk-22.0/bin/../share/wasi-sysroot/lib/wasm32-wasip2/crt1-command.o --version -lc wasi-sdk-22.0/lib/clang/18/lib/wasip2/libclang_rt.builtins-wasm32.a -o a.out
error: invalid option '--version'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
So basically it fails to check the version of linker when I set --target=wasm32-wasip2.
However, if I set the target to wasm32-wasi-threads, it works fine:
$ wasi-sdk-22.0/bin/clang -v -Wl,--version --target=wasm32-wasi-threads
clang version 18.1.2 (https://github.com/llvm/llvm-project 26a1d6601d727a96f4301d0d8647b5a42760ae0c)
Target: wasm32-unknown-wasi-threads
Thread model: posix
InstalledDir: wasi-sdk-22.0/bin
"wasi-sdk-22.0/bin/wasm-ld" -m wasm32 -Lwasi-sdk-22.0/bin/../share/wasi-sysroot/lib/wasm32-wasi-threads wasi-sdk-22.0/bin/../share/wasi-sysroot/lib/wasm32-wasi-threads/crt1-command.o --version -lc wasi-sdk-22.0/lib/clang/18/lib/wasi/libclang_rt.builtins-wasm32.a -o a.out
LLD 18.1.2
I do notice that when setting target to "wasm32-wasi-threads" it uses "wasm-ld", while "wasm-component-ld" is used when setting target to "wasm32-wasip2". I guess there might be something related to #426
Also, I'm using clang from wasi-sdk-22.0 with sysroot built from source with the latest wasi-libc repo. Not sure if it has anything to do with this error. But even if I specify --sysroot to "wasi-libc/sysroot", same error happens.
I just want to understand why this is happening and how to avoid this when using wasm32-wasip2 as target. Because this version check is a part of my project. Thanks a lot!