WebAssembly / wabt

The WebAssembly Binary Toolkit
Apache License 2.0
6.74k stars 688 forks source link

wasm2wat needed_dynlibs error #1429

Open syrusakbary opened 4 years ago

syrusakbary commented 4 years ago

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

binji commented 4 years ago

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?

sbc100 commented 4 years ago

Thanks, I'll take a look.

sbc100 commented 4 years ago

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 commented 4 years ago

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

syrusakbary commented 4 years ago

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?

sbc100 commented 4 years ago

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.