Hmm, the --llvm-lto 2 option should do basically what you describe here - run LLVM opts on the combined bitcode. Does that also cause this problem?
My guess is you're hitting an LLVM optimizer bug or undefined behavior of some sort, when it has all the bitcode to optimize it is capable of doing a lot more and that has uncovered LLVM bugs in the past. If you can reduce this to a testcase you can file I can take a look at that. On Mon, Mar 26, 2018 at 1:49 AM, caiiiycuk <[email protected]> wrote: > Good day! I am playing with llvm optimizer and I trying to setup build > process that allows me to run custom optimizations over bc. I want to: > 1. Build resulting .bc of game (using llvm-link) > 2. Transform this .bc with custom optimizations > 3. Produce .js with emcc > > For (1) I compile all source files into shared library (instead of js): > add_library(bin-lib SHARED ${SOURCES}) > set_target_properties(bin-lib PROPERTIES SUFFIX .bc) > > As I understand this step works perfect, because as a result I have one > libbin-lib.bc file. > > For (2) I use this command: > ~/emscripten/sdk/emscripten-fastcomp/bin/opt -O3 libbin-lib.bc -o > libbin-lib-opt.bc > > > For (3) I use this command: > ~/emscripten/sdk/emscripten/emcc -O3 \ > -s USE_ZLIB=1 -s USE_LIBPNG=1 -s USE_FREETYPE=1 -s USE_GLFW=3 -s > FULL_ES2=1 \ > --emit-symbol-map \ > -s ASSERTIONS=0 \ > -s SAFE_HEAP=0 \ > -s TOTAL_MEMORY=134217728 \ > -s INVOKE_RUN=0 \ > -s EXTRA_EXPORTED_RUNTIME_METHODS="['getMemory', 'addRunDependency', > 'removeRunDependency', 'FS_createPath', 'FS_createPreloadedFile', \ > 'FS_createDataFile', 'lengthBytesUTF8', 'stringToUTF8']" \ > -s NO_EXIT_RUNTIME=1 \ > libbin-lib-opt.bc -o bin.js > > If I build my game with this steps: > (1) -> (3) (skip 2) > > Then I have working bin.js. I can play game exactly the same as when I > compile just .js file with emcc. > > BUT, if I build my game with this steps: > (1) -> (2) -> (3) > > Then I have bin.js that produce errors in browser: > > Invalid function pointer called with signature 'vi'. Perhaps this is an > invalid value (e.g. caused by calling a virtual method on a NULL pointer)? > Or calling a function with an incorrect type, which will fail? (it is worth > building your source files with -Werror (warnings are errors), as warnings > can indicate undefined behavior which can cause this) > > This pointer might make sense in another type signature: v: 0 vid: 0 vii: > 0 vidd: 0 vidi: 0 viid: 0 viii: 0 viddi: 0 viidi: 0 viiii: 0 vidddd: 0 > viiiii: 0 viddddd: 0 viiiiii: 0 vidddddi: 0 viiiiiii: 0 vidddddii: 0 > viiddiidii: 0 viiiiiiiii: 0 i: 0 di: 0 ii: 0 dii: 0 iid: 0 iii: 0 diid: 0 > iidi: 0 iiii: 0 iiiid: 0 iiiii: 0 iiiiid: 0 iiiiii: 0 iiiiddd: 0 iiiiiid: 0 > iiiiiii: 0 iiiiiiii: 0 iiiiiiiii: 0 iiiiiiiiii: 0 > > uncaught exception: abort(20) at jsStackTrace@http://localhost/ > gamepix-loader.js line 168 > Function:3:40923 > stackTrace@http://localhost/gamepix-loader.js line 168 > Function:3:41094 > abort@http://localhost/gamepix-loader.js line 168 > Function:26:243921 > nullFunc_vi@http://localhost/gamepix-loader.js line 168 > > Function:3:326758 > b20@http://localhost/gamepix-loader.js line 168 > Function:19:112979 > __ZNSt3__214__shared_count16__release_sharedEv@http:// > localhost/gamepix-loader.js line 168 > Function:19:45045 > __ZNSt3__26localeD2Ev@http://localhost/gamepix-loader.js line 168 > > Function:16:660576 > __ZNSt3__210__stdinbufIcEC2EP8_IO_FILEP11__mbstate_t@http://localhost/ > gamepix-loader.js line 168 > Function:16:635917 > __ZNSt3__28ios_base4InitC2Ev@http://localhost/gamepix-loader.js line 168 > > Function:16:633585 > ___cxx_global_var_init@http://localhost/gamepix-loader.js line 168 > > Function:16:633478 > __GLOBAL__I_000101@http://localhost/gamepix-loader.js line 168 > > Function:16:633365 > > Error exists if i use any level of optimizations on opt step (O1, O2, O3) > If I set --llvm-opts 0, on emcc step error still exists > > Can you help me? > Thank you > > -- > You received this message because you are subscribed to the Google Groups > "emscripten-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "emscripten-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
