wasi-sdk icon indicating copy to clipboard operation
wasi-sdk copied to clipboard

How to link to the symbols from libc.imports?

Open zlonqi opened this issue 3 years ago • 3 comments

Hi, I write a HTTP/GET method by use some net/sys api from wasi-sdk, and build it to wasm by CMake. But When I execute the .wasm file, it output : 微信截图_20220109172947 However, I found those functions in path /opt/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi/libc.imports. It's a ASCII file. Does anyone know how to solve this problem? Thank you very much.

zlonqi avatar Jan 09 '22 09:01 zlonqi

What runtime are you using to try to run your binary? I looks like that runtime is not providing the necessary imports for the module. Does the runtime claim to support WASI?

Firstly, the functions that start with __cxa_ should be implemented by libc++/libc+-abi and should not be undefined in your final binary. Are you linking with clang++ (as opposed to clang)? I'm not sure how you were able to link your module at all as the linker should have error'ed out on these symbols. Maybe you are linking with --allow-undefined? If so I suggest you remove that flag to avoid this issue.

Secondly the was_snapshot_preview1 symbols should be provided by the runtime. The fact that they are not implies the runtime you are using does perhaps does not support wasi?

sbc100 avatar Jan 09 '22 15:01 sbc100

Thank you for your tips.

What runtime are you using to try to run your binary? I looks like that runtime is not providing the necessary imports for the module. Does the runtime claim to support WASI?

base WAMR and SGX Enclave.

Firstly, the functions that start with __cxa_ should be implemented by libc++/libc+-abi and should not be undefined in your final binary. Are you linking with clang++ (as opposed to clang)?

gcc

zlonqi avatar Jan 10 '22 09:01 zlonqi

Thank you for your tips.

What runtime are you using to try to run your binary? I looks like that runtime is not providing the necessary imports for the module. Does the runtime claim to support WASI?

base WAMR and SGX Enclave.

I think this is probably be bug better reported there then. Its that runtime that needs to support the wasi API, not wasi-sdk.

Firstly, the functions that start with __cxa_ should be implemented by libc++/libc+-abi and should not be undefined in your final binary. Are you linking with clang++ (as opposed to clang)?

gcc

wasi-sdk uses llvm tools (clang, clang++, wasm-ld) so I don't see how you could be using gcc.

Perhaps you could share the full command line use to link your application. (And make sure you tell cmake to be verbose so you can see the command lines used: https://bytefreaks.net/programming-2/make-building-with-cmake-verbose)

sbc100 avatar Jan 10 '22 13:01 sbc100

I'm going to close this since it seems to be a linking issue specific to WAMR.

abrown avatar Aug 22 '23 22:08 abrown