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

Unable to decompile executables from emscripten tot #2

Closed
nemequ opened this issue Mar 24, 2021 · 2 comments
Closed

Unable to decompile executables from emscripten tot #2

nemequ opened this issue Mar 24, 2021 · 2 comments

Comments

@nemequ
Copy link
Owner

nemequ commented Mar 24, 2021

I'd like to update wav to match the recent changes in llvm, but I'm having some trouble and I'm not experienced enough with the WebAssembly tooling to even know where the problem is. @ngzhian, sorry to bug you, but maybe you could point me in the right direction?

In the tests branch of this repo, we have a bunch of files which are supposed to be compiled to WASM, then disassembled to WAT and compared to the expected result to make sure functions aren't generating any extra cruft (mostly each function should generate one instruction).

I had been using wasm-dis from emscripten to do the disassembly, but it stopped working quite recently (probably after tlively's updates).

/opt/emscripten/upstream/emscripten/emcc -Weverything -Wno-missing-prototypes -Werror -O1 -msimd128  --no-entry -c -o ceil.wasm ceil.c
/opt/emscripten/upstream/bin/wasm-dis -o ceil.wat ceil.wasm
[parse exception: Illegal lane index (at 0:75)]
Fatal: error in parsing wasm binary
make: *** [Makefile:99: ceil.wat] Error 1

Most of the files work, though they do all trip a "warning: linking section is present, so this is not a standard wasm file - binaryen cannot handle this properly!".

I figured I'd switch to wasm2wat, but that doesn't work either and according to WebAssembly/wabt/1650 it should. Tweaking test/Makefile:

diff --git a/test/Makefile b/test/Makefile
index 756a84b..6bb24ad 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -2,7 +2,7 @@ EMSDK = /opt/emscripten
 
 CC := $(EMSDK)/upstream/emscripten/emcc
 CXX := $(EMSDK)/upstream/emscripten/em++
-WASM_DIS := $(EMSDK)/upstream/bin/wasm-dis
+WASM2WAT := /home/nemequ/local/src/wabt/build/wasm2wat
 CFLAGS := -Weverything -Wno-missing-prototypes -Werror -O1 -msimd128 # -munimplemented-simd128
 CXXFLAGS := $(CFLAGS)
 
@@ -96,4 +96,4 @@ clean:
        $(CC) $(CFLAGS) --no-entry -c -o $@ $<
 
 %.wat: %.wasm
-       $(WASM_DIS) -o $@ $<
+       $(WASM2WAT) -o $@ $<

Obviously some paths will need to be adjusted on other machines…

While compilation works, wasm2wat fails (for every file I've tried):

$ make load.wat
/opt/emscripten/upstream/emscripten/emcc -Weverything -Wno-missing-prototypes -Werror -O1 -msimd128  --no-entry -c -o load.wasm load.c
/home/nemequ/local/src/wabt/build/wasm2wat -o load.wat load.wasm
0000014: error: expected valid result type (got -0x5)
make: *** [Makefile:99: load.wat] Error 1

IDK if this is related to the warning from wasm-dis, if I'm compiling the wasm wrong (← most likely scenario), if wasm2wat is buggy, etc.

FWIW, I don't really care if I use wasm-dis or wasm2wat or something else.

@ngzhian
Copy link

ngzhian commented Mar 24, 2021

error: expected valid result type (got -0x5) means you need to pass the --enable-simd flag to wasm2wat, like wasm2wat --enable-simd load.wasm, that's because simd is still not merged into the spec yet, all proposals are behind a flag. (I will send a patch upstream to improve the error message in this case...)

@nemequ
Copy link
Owner Author

nemequ commented Mar 24, 2021

Awesome, thank you!

I'm getting a new error now, but i think that's due to the any_true built-ins not having been updated yet (which Thomas already knows about), so at least I'm not blocked anymore :)

@nemequ nemequ closed this as completed Mar 24, 2021
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

2 participants