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

Upgrade Clang in order to allow using the -shared option

Open Keithcat1 opened this issue 4 years ago • 5 comments
trafficstars

Hi, I would like to build WASM modules that are loadable with the Wasmtime runtime, but this seems to require the -shared option and I ran into a couple errors while using that:

C:\py> C:\py>C:\wasi-sdk\bin\clang -shared add.c clang: warning: argument unused during compilation: '-shared' [-Wunused-command-line-argument] wasm-ld: error: c:/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi\libc.a(__main_argc_argv.o): undefined symbol: main clang: error: linker command failed with exit code 1 (use -v to see invocation)

C:\py>C:\wasi-sdk\bin\clang -Wl,--shared add.c wasm-ld: warning: creating shared libraries, with -shared, is not yet stable wasm-ld: error: c:/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi\libc.a(sbrk.o): relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol errno; recompile with -fPIC wasm-ld: error: c:/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi\libc.a(dlmalloc.o): relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol gm; recompile with -fPIC wasm-ld: error: c:/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi\libc.a(dlmalloc.o): relocation R_WASM_MEMORY_ADDR_SLEB cannot be used against symbol __heap_base; recompile with -fPIC wasm-ld: error: c:/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi\libc.a(dlmalloc.o): relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol mparams; recompile with -fPIC wasm-ld: error: c:/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi\libc.a(dlmalloc.o): relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol mparams; recompile with -fPIC wasm-ld: error: c:/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi\libc.a(dlmalloc.o): relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol mparams; recompile with -fPIC wasm-ld: error: c:/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi\libc.a(dlmalloc.o): relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol mparams; recompile with -fPIC wasm-ld: error: c:/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi\libc.a(dlmalloc.o): relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol mparams; recompile with -fPIC wasm-ld: error: c:/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi\libc.a(dlmalloc.o): relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol gm; recompile with -fPIC wasm-ld: error: c:/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi\libc.a(dlmalloc.o): relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol gm; recompile with -fPIC wasm-ld: error: c:/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi\libc.a(dlmalloc.o): relocation R_WASM_MEMORY_ADDR_SLEB cannot be used against symbol __heap_base; recompile with -fPIC wasm-ld: error: c:/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi\libc.a(dlmalloc.o): relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol gm; recompile with -fPIC wasm-ld: error: c:/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi\libc.a(dlmalloc.o): relocation R_WASM_MEMORY_ADDR_SLEB cannot be used against symbol __heap_base; recompile with -fPIC wasm-ld: error: c:/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi\libc.a(dlmalloc.o): relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol gm; recompile with -fPIC wasm-ld: error: c:/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi\libc.a(dlmalloc.o): relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol gm; recompile with -fPIC wasm-ld: error: c:/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi\libc.a(dlmalloc.o): relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol gm; recompile with -fPIC wasm-ld: error: c:/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi\libc.a(dlmalloc.o): relocation R_WASM_MEMORY_ADDR_SLEB cannot be used against symbol gm; recompile with -fPIC wasm-ld: error: c:/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi\libc.a(dlmalloc.o): relocation R_WASM_MEMORY_ADDR_SLEB cannot be used against symbol gm; recompile with -fPIC wasm-ld: error: c:/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi\libc.a(dlmalloc.o): relocation R_WASM_MEMORY_ADDR_SLEB cannot be used against symbol gm; recompile with -fPIC wasm-ld: error: c:/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi\libc.a(dlmalloc.o): relocation R_WASM_MEMORY_ADDR_SLEB cannot be used against symbol __heap_base; recompile with -fPIC wasm-ld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors) clang: error: linker command failed with exit code 1 (use -v to see invocation)

C:\py>

clang version 11.0.0 (https://github.com/llvm/llvm-project 176249bd6732a8044d457092ed932768724a6f06) Target: wasm32-unknown-wasi Thread model: posix InstalledDir: C:\wasi-sdk\bin

I wasn't able to use Emscripten because it seems to be generating WASM for the web but not for Wasmtime.

Keithcat1 avatar Oct 09 '21 18:10 Keithcat1

Upstream LLVM's wasm32-wasi target does not support -shared yet. Can you say more about your use case and what -shared is being used for?

sunfishcode avatar Oct 11 '21 16:10 sunfishcode

It doesn't? Weird. I was trying to learn how to use Wasmtime from Python. I assumed that in order to load a WASM module and call its exported functions, it had to be built with the -shared option since it's not an executable.

On 10/11/21, Dan Gohman @.***> wrote:

Upstream LLVM's wasm32-wasi target does not support -shared yet. Can you say more about your use case and what -shared is being used for?

-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/WebAssembly/wasi-sdk/issues/199#issuecomment-940171918

Keithcat1 avatar Oct 12 '21 17:10 Keithcat1

There is a -shared option, but it was only implemented for Emscripten targets, and it doesn't work outside of Emscripten. The option in clang and wasi-sdk for building a wasm module without a main function is -mexec-model=reactor.

sunfishcode avatar Oct 22 '21 22:10 sunfishcode

Ok, how do I export symbols so that Wasmtime can find and call them? Simply compiling a .C file with some functions in it does not expose them.

Keithcat1 avatar Oct 30 '21 19:10 Keithcat1

I believe you can either add __attribute__((export_name("foo"))) to the functions you want to export or build with -Wl,--export=foo

sbc100 avatar Nov 01 '21 16:11 sbc100

@Keithcat1, you may be interested in https://github.com/WebAssembly/wasi-sdk/pull/338? Let's close this issue since that PR is much newer and should resolve it.

abrown avatar Aug 22 '23 22:08 abrown