when i use llvm to build wasm file(shared library), i get some trouble
(Forgive my bad english - -!)
test1.c
int g_a = 1;
int test1() {
return 100 + g_a;
}
void setV(int v) {
g_a = v;
}
test2.c
int test2() {
return 200;
}
this is compile result
zhanheng@ubuntu:~/WASM/test$ /home/zhanheng/WASM/emsdk/upstream/bin/clang --target=wasm32 -nostdlib -Wl,--export-all -Wl,--shared -o test12.wasm -fPIC test1.c test2.c
wasm-ld: warning: creating shared libraries, with -shared, is not yet stable
wasm-ld: error: /tmp/test1-6da457.o: relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol g_a; recompile with -fPIC
wasm-ld: error: /tmp/test1-6da457.o: relocation R_WASM_MEMORY_ADDR_LEB cannot be used against symbol g_a; recompile with -fPIC
clang-14: error: linker command failed with exit code 1 (use -v to see invocation)
it seem like link a static library
if i won use --export-all i can't export global g_a
but i use emcc to compile,it can work
emcc test1.c test2.c -s SIDE_MODULE=2 -s LINKABLE=1 -o test12_emcc.wasm
this is wasm-objdump -x result
when i use llvm to build wasm file(shared library), i get some trouble (Forgive my bad english - -!) test1.c
test2.c
this is compile result
it seem like link a static library
if i won use
--export-all
i can't export globalg_a
but i use emcc to compile,it can work
emcc test1.c test2.c -s SIDE_MODULE=2 -s LINKABLE=1 -o test12_emcc.wasm
this iswasm-objdump -x
resultit can export g_a with GOT.mem,but it global[4] i32 g_a is not a mutable global.
i want know how to compile use llvm to build the wasm file.