kateinoigakukun / wasi-vfs

A virtual filesystem layer for WASI.
Apache License 2.0
150 stars 11 forks source link

Duplicate symbols when building with wasi-sdk 20 #11

Open kesmit13 opened 1 year ago

kesmit13 commented 1 year ago

I was getting a crash when initializing a wasm module that used wasi-vfs. I was using wasi-sdk 20 and thought that maybe I should build wasi-vfs against that to make sure that wasn't the issue. However, after getting it built, I get the following errors when attempting to link libwasi_vfs.a into a module. The libc included with wasi-sdk includes the rintf and rint functions already. I was wondering if you had run across this before, or if this is possibly an addition to one of wasi-vfs' dependencies?

wasm-ld: error: duplicate symbol: rintf
>>> defined in /opt/lib/libwasi_vfs.a(compiler_builtins-d324d30d7b4a99a9.compiler_builtins.50f24778-cgu.60.rcgu.o)
>>> defined in /opt/wasi-sdk-20.0+threads/bin/../share/wasi-sysroot/lib/wasm32-wasi/libc.a(math-builtins.o)

wasm-ld: error: duplicate symbol: rint
>>> defined in /opt/lib/libwasi_vfs.a(compiler_builtins-d324d30d7b4a99a9.compiler_builtins.50f24778-cgu.70.rcgu.o)
>>> defined in /opt/wasi-sdk-20.0+threads/bin/../share/wasi-sysroot/lib/wasm32-wasi/libc.a(math-builtins.o)
kesmit13 commented 1 year ago

It does look like these functions have been in libc.a for quite a while, so I'm guessing it's an updated dependency of wasi-vfs.

kesmit13 commented 1 year ago

Even when I build with wasi-sdk 14, I get those errors, so I'm not sure what the difference is between your builds and mine.

kesmit13 commented 1 year ago

Oh, I bet that the linker was filtering out the symbols if they weren't used. I'm compiling the pandas package of Python which does a lot of numeric computation and probably uses the rintf and rint functions, which then causes the linker to include those symbols. Since they are both defined in two separate places, I get this error.

kateinoigakukun commented 1 year ago

It looks like rustc archives compiler_builtins implementations into .a. The rust people implemented it by themselves https://github.com/rust-lang/compiler-builtins and the alloc library depends on it, so there is no way to avoid including compiler_builtins in .a unfortunately.

If we adopt the component model, this problem will be solved.