wabt icon indicating copy to clipboard operation
wabt copied to clipboard

wasm2wat needed_dynlibs error

Open syrusakbary opened this issue 5 years ago • 6 comments

While working on an issue in Wasmer, we realized that wabt was unable to parse/validate a valid Wasm file, failing with a needed_dynlibs error (my local wabt was installed via homebrew).

$ wasm2wat lib/c-api/tests/assets/hello_wasm.wasm
0000018: error: unable to read u32 leb128: needed_dynlibs
$ wasm-validate lib/c-api/tests/assets/hello_wasm.wasm
0000018: error: unable to read u32 leb128: needed_dynlibs

The hello_wasm.wasm file seem to be valid according to other validators, so we have no insight of what might be causing the parsing/validating error.

For debugging: the wasm file was generated using rustc with wasm32-unknown-unknown target for this source: https://github.com/wasmerio/wasmer/blob/master/lib/runtime-c-api/tests/assets/return_hello.rs

syrusakbary avatar May 16 '20 07:05 syrusakbary

Looks like it is trying to read the dylink custom section, and erroring out because it's missing that field. @sbc100 looks like you added this, do you know what may be happening?

binji avatar May 18 '20 18:05 binji

Thanks, I'll take a look.

sbc100 avatar May 18 '20 19:05 sbc100

Hmm, what version of llvm was used to compile that file? It looks like that I added the extrea leb to that section back in https://reviews.llvm.org/D55613, which I think means it was in llvm 8 and above.

My guess is that other validators ignore this section completely, and I guess maybe(?) wasm-validate should too?

sbc100 avatar May 18 '20 19:05 sbc100

Also, I don't think wasm32-unknown-unknown should be producing dynamic libraries should it? Does it even support the -shared flag?

sbc100 avatar May 18 '20 19:05 sbc100

Hmm, what version of llvm was used to compile that file?

Unfortunately we don't have the script that we used to generate the file, so we can't know for sure. It could be that was the rustc version we were using was using llvm-7?

syrusakbary avatar May 19 '20 03:05 syrusakbary

Yes I think wasm-ld from llvm 7 would produce such a dylink section, but even then only if linked as a shared library with -shared or -pie I believe.

Either way we should re-visit how we validate this custom section.

sbc100 avatar May 19 '20 05:05 sbc100