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

Viz.js: wasm-opt: Fatal: error in validating input #10331

Closed
Ghabry opened this issue Jan 31, 2020 · 9 comments
Closed

Viz.js: wasm-opt: Fatal: error in validating input #10331

Ghabry opened this issue Jan 31, 2020 · 9 comments
Labels

Comments

@Ghabry
Copy link
Contributor

Ghabry commented Jan 31, 2020

Emscripten version: 1.39.6

I try to compile this: https://github.com/mdaines/viz.js

Command executed:

make deps-full
make all

deps-full extracts a graphviz archive. You have to manually patch the configure file and get rid of "-ffast-math". (see #9955)

Attached module.wasm that fails to validate and a patch file to make it build against later emscripten versions:
module.zip

Build line:
/usr/bin/wasm-opt --post-emscripten --inline-main --no-exit-runtime -O2 --pass-arg=emscripten-sbrk-ptr@220832 module.wasm -o module.wasm --mvp-features --strip-dwarf

The validation output is gigantic (600000 lines), won't attach it, just run wasm-opt to see it.

The only hint I can give is that it validates when using "deps-lite". This builds Graphviz only with "dot" support. But I need neato and sfdp which is part of "deps-full" :/

@Ghabry
Copy link
Contributor Author

Ghabry commented Jan 31, 2020

wasm2wat gives a better error:

module.wasm:00627b2: error: type mismatch in call, expected [i32, i32, i32, i32, i32, i32, f64, i32, i32] but got [i32, i32, f64, i32, i32, i32, i32, i32, i32]
module.wasm:00627b5: error: type mismatch in block, expected [] but got [i32]
module.wasm:0062d8c: error: type mismatch in call, expected [i32, i32, i32, i32, i32, i32, f64, i32, i32] but got [i32, i32, f64, i32, i32, i32, i32, i32, i32]
module.wasm:0062da5: error: type mismatch in block, expected [] but got [i32]

@kripken
Copy link
Member

kripken commented Feb 1, 2020

I tried to build this but the second command fails,

$ make all
emcc --version | grep 1.39.6
emcc (Emscripten gcc/clang-like replacement) 1.39.6 (commit 9c48a508eacac4506e18cc27a27ac8bff405e025)
emcc -O2 --memory-init-file 0 -s ALLOW_MEMORY_GROWTH=1 -s USE_ZLIB=1 -s MODULARIZE=0 -s NO_DYNAMIC_EXECUTION=1 -s EXPORTED_FUNCTIONS="['_vizRenderFromString', '_vizCreateFile', '_vizSetY_invert', '_vizSetNop', '_vizLastErrorMessage', '_dtextract']" -s EXPORTED_RUNTIME_METHODS="['Pointer_stringify', 'ccall', 'UTF8ToString']" -o build-full/module.js src/viz.c -Iviz.js/prefix-full/include -Iviz.js/prefix-full/include/graphviz -Lviz.js/prefix-full/lib -Lviz.js/prefix-full/lib/graphviz -lgvplugin_core -lgvplugin_dot_layout -lgvplugin_neato_layout -lcdt -lcgraph -lgvc -lgvpr -lpathplan -lexpat -lxdot
src/viz.c:1:10: fatal error: 'gvc.h' file not found
#include <gvc.h>
         ^~~~~~~
1 error generated.
shared:ERROR: '/sdk/upstream/bin/clang -target wasm32-unknown-emscripten -D__EMSCRIPTEN_major__=1 -D__EMSCRIPTEN_minor__=39 -D__EMSCRIPTEN_tiny__=6 -D_LIBCPP_ABI_VERSION=2 -Dunix -D__unix -D__unix__ -Werror=implicit-function-declaration -Xclang -nostdsysteminc -Xclang -isystem/emscripten/system/include/libcxx -Xclang -isystem/emscripten/system/lib/libcxxabi/include -Xclang -isystem/emscripten/system/include/compat -Xclang -isystem/emscripten/system/include -Xclang -isystem/emscripten/system/include/libc -Xclang -isystem/emscripten/system/lib/libc/musl/arch/emscripten -Xclang -isystem/emscripten/system/local/include -Xclang -isystem/.emscripten_cache/wasm-obj/include -O2 -Iviz.js/prefix-full/include -Iviz.js/prefix-full/include/graphviz -DEMSCRIPTEN src/viz.c -Xclang -isystem/emscripten/system/include/SDL -c -o /tmp/emscripten_temp_eaNutw/viz_0.o -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr' failed (1)
make: *** [Makefile:54: build-full/module.js] Error 1

Please run the final link command it with EMCC_DEBUG=1 in the env. Then in /tmp/emscripten_temp/ you will have some emcc-* files, that should be enough to diagnose this. (If the very first one is bad, then it's a clang bug, otherwise it's binaryen's fault.)

@Ghabry
Copy link
Contributor Author

Ghabry commented Feb 2, 2020

emscripten_temp.zip

emcc-0-base.wasm already fails to validate, so guess I have to report this to https://bugs.llvm.org/ again?

EDIT: Replaced the zip with a "-g4" build. Maybe more useful as it has the function names.

@Ghabry
Copy link
Contributor Author

Ghabry commented Feb 3, 2020

An older emscripten (1.38.48) actually tells the concrete issue:
Maybe would be nice to have this error reporting back.

error: asm2wasm seeing an invalid argument type at index 5 (this will not validate) in call from $_multilevel_spring_electrical_embedding to $_remove_overlap (this is likely due to undefined behavior in C, like defining a function one way and calling it in another, which is important to fix)
error: asm2wasm seeing an invalid argument type at index 6 (this will not validate) in call from $_multilevel_spring_electrical_embedding to $_remove_overlap (this is likely due to undefined behavior in C, like defining a function one way and calling it in another, which is important to fix)
error: asm2wasm seeing an invalid argument type at index 5 (this will not validate) in call from $_multilevel_spring_electrical_embedding to $_remove_overlap (this is likely due to undefined behavior in C, like defining a function one way and calling it in another, which is important to fix)
error: asm2wasm seeing an invalid argument type at index 6 (this will not validate) in call from $_multilevel_spring_electrical_embedding to $_remove_overlap (this is likely due to undefined behavior in C, like defining a function one way and calling it in another, which is important to fix)

When libgts is missing the parameters for remove_overlap don't match with the header definition. So this sounds like a library bug, not a clang/binaryen bug.
After fixing this one the code validates...

@kripken
Copy link
Member

kripken commented Feb 3, 2020

Yes, this would be an llvm bug then, please file it there (and link to it here).

That old error reporting is from asm2wasm, while in the new backend the linker is lld which handles mismatches like that differently. @sbc100 does it not error or at least warn? (Or perhaps the data reaching the linker is very different if the newer clang/llvm emit something else, so might not be the linker specifically...)

@sbc100
Copy link
Collaborator

sbc100 commented Feb 3, 2020

Certainly an llvm bug if the output of the compiler and linker doesn't validate.

@Ghabry
Copy link
Contributor Author

Ghabry commented Feb 4, 2020

@mischnic
Copy link

mischnic commented Mar 8, 2020

So this sounds like a library bug, not a clang/binaryen bug.

This is the configure test for drand48 ...

char drand48();
int main (){
	return drand48();
}
asm2wasm trace
Thread 1 Crashed:
0   libsystem_kernel.dylib        	0x00007fff65576b66 __pthread_kill + 10
1   libsystem_pthread.dylib       	0x00007fff65741080 pthread_kill + 333
2   libsystem_c.dylib             	0x00007fff654d21ae abort + 127
3   asm2wasm                      	0x0000000106e7613b wasm::handle_unreachable(char const*, char const*, unsigned int) + 203
4   asm2wasm                      	0x0000000106d29b20 unsigned int wasm::getMaxBits<wasm::LocalScanner>(wasm::Expression*, wasm::LocalScanner*) + 1045
5   asm2wasm                      	0x0000000106d295c1 wasm::LocalScanner::visitLocalSet(wasm::LocalSet*) + 129
6   asm2wasm                      	0x0000000106d27df8 wasm::Walker<wasm::LocalScanner, wasm::Visitor<wasm::LocalScanner, void> >::walk(wasm::Expression*&) + 132
7   asm2wasm                      	0x0000000106d27ace wasm::LocalScanner::doWalkFunction(wasm::Function*) + 184
8   asm2wasm                      	0x0000000106d279bd wasm::OptimizeInstructions::doWalkFunction(wasm::Function*) + 109
9   asm2wasm                      	0x0000000106d1e9ea wasm::WalkerPass<wasm::PostWalker<wasm::OptimizeInstructions, wasm::UnifiedExpressionVisitor<wasm::OptimizeInstructions, void> > >::runOnFunction(wasm::PassRunner*, wasm::Module*, wasm::Function*) + 38
10  asm2wasm                      	0x0000000106c5251d wasm::PassRunner::runPassOnFunction(wasm::Pass*, wasm::Function*) + 137
11  asm2wasm                      	0x0000000106c52458 wasm::PassRunner::runOnFunction(wasm::Function*) + 176
12  asm2wasm                      	0x0000000106c35295 wasm::OptimizingIncrementalModuleBuilder::optimizeFunction(wasm::Function*) + 273
13  asm2wasm                      	0x0000000106c34d6b wasm::OptimizingIncrementalModuleBuilder::workerMain(

@stale
Copy link

stale bot commented Mar 19, 2021

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.

@stale stale bot added the wontfix label Mar 19, 2021
@stale stale bot closed this as completed Jun 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants