This code demonstrates a problem with emlink and static initializers. It implements a basic type registry system but has different runtime semantics after compiling with emscripten following the static linking instructions.
After running make cpp_single
:
cc -std=c++11 -fno-rtti -fno-exceptions main.cpp side.cpp -lc++ -o a.out
./a.out
allocating type id 0
register name int as type id 0
starting tests
all tests passed
rm a.out
After running make cpp_modules
:
cc -std=c++11 -fno-rtti -fno-exceptions -c main.cpp -o main.o
cc -std=c++11 -fno-rtti -fno-exceptions -c side.cpp -o side.o
cc main.o side.o -lc++ -o a.out
./a.out
allocating type id 0
register name int as type id 0
starting tests
all tests passed
rm a.out
After running make js_simple
:
LLVM=~/.emsdk_portable/clang/3.2_64bit/bin python ~/.emsdk_portable/emscripten/1.7.8/emcc -s ASM_JS=1 -O1 -std=c++11 -fno-rtti -fno-exceptions main.cpp side.cpp -o compiled.js
node compiled.js
allocating type id 0
register name int as type id 0
starting tests
all tests passed
rm compiled.js
After running make js_modules
:
LLVM=~/.emsdk_portable/clang/3.2_64bit/bin python ~/.emsdk_portable/emscripten/1.7.8/emcc -s ASM_JS=1 -O1 -std=c++11 -fno-rtti -fno-exceptions main.cpp -s MAIN_MODULE=1 -o main.js
warning: Casting a function pointer type to a potentially incompatible one (use -s VERBOSE=1 to see more)
warning: See https://github.com/kripken/emscripten/wiki/CodeGuidelinesAndLimitations#function-pointer-issues for more information on dangerous function pointer casts
warning: Incompatible function pointer casts are very dangerous with ASM_JS=1, you should investigate and correct these
LLVM=~/.emsdk_portable/clang/3.2_64bit/bin python ~/.emsdk_portable/emscripten/1.7.8/emcc -s ASM_JS=1 -O1 -std=c++11 -fno-rtti -fno-exceptions side.cpp -s SIDE_MODULE=1 -o side.js
LLVM=~/.emsdk_portable/clang/3.2_64bit/bin python ~/.emsdk_portable/emscripten/1.7.8/emlink.py main.js side.js compiled.js
Main module: main.js
Side module: side.js
Output: compiled.js
node compiled.js
allocating type id 0
register name int as type id 0
starting tests
allocating type id 1
could not find name for type with id 1
compiled.js:183832
throw e;
^
Assertion failed: TypeID::toName(TypeID::value<int>()) == std::string("int"), at: side.cpp,6,main at Error
at stackTrace (compiled.js:932:15)
at ___assert_fail (compiled.js:4623:210)
at Object._main (compiled.js:181880:3)
at Object.callMain (compiled.js:183815:30)
at doRun (compiled.js:183855:25)
at run (compiled.js:183868:5)
at Object.<anonymous> (compiled.js:183911:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
make: *** [js_modules] Error 8
Static linking causes warnings about incompatible function pointer casts, but adding -s VERBOSE=1
reveals that the warnings are for functions that are never called as far as I can tell:
warning: Casting potentially incompatible function pointer void (i32, i8*, i32*)* to i32 (i32, i8*, i32*)*, for _verr
warning: See https://github.com/kripken/emscripten/wiki/CodeGuidelinesAndLimitations#function-pointer-issues for more information on dangerous function pointer casts
warning: Incompatible function pointer casts are very dangerous with ASM_JS=1, you should investigate and correct these
warning: Casting potentially incompatible function pointer void (i32, i8*, i32*)* to i32 (i32, i8*, i32*)*, for _verrx