Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linker error when setting target to wasm32-wasip2 #433

Closed
wynterr opened this issue Jun 28, 2024 · 3 comments
Closed

Linker error when setting target to wasm32-wasip2 #433

wynterr opened this issue Jun 28, 2024 · 3 comments

Comments

@wynterr
Copy link

wynterr commented Jun 28, 2024

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!

@alexcrichton
Copy link
Collaborator

The wasm-component-ld distributed with wasi-sdk-22 didn't support --version, but the latest version does now. I plan on updating wasm-component-ld after #429 lands.

@alexcrichton
Copy link
Collaborator

If you'd like you can build the latest source of the binary itself and configure that to be used instead

@alexcrichton
Copy link
Collaborator

I believe this is fixed in wasi-sdk-23.0, so closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants