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

Upgrade Clang in order to allow using the -shared option #199

Closed
Keithcat1 opened this issue Oct 9, 2021 · 6 comments
Closed

Upgrade Clang in order to allow using the -shared option #199

Keithcat1 opened this issue Oct 9, 2021 · 6 comments

Comments

@Keithcat1
Copy link

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.

@sunfishcode
Copy link
Member

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?

@Keithcat1
Copy link
Author

Keithcat1 commented Oct 12, 2021 via email

@sunfishcode
Copy link
Member

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.

@Keithcat1
Copy link
Author

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.

@sbc100
Copy link
Member

sbc100 commented Nov 1, 2021

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

@abrown
Copy link
Collaborator

abrown commented Aug 22, 2023

@Keithcat1, you may be interested in #338? Let's close this issue since that PR is much newer and should resolve it.

@abrown abrown closed this as completed Aug 22, 2023
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

4 participants