kripken/emscripten — Issue #132: Problems with __llvm_expect_i64 and allocator exception
Author: rhundt
Created: 2011-12-06 02:22:00+00:00
State: open

Recently I have published implementations of an algorithm in a couple of languages and then compared various properties and shortcomings of the languages, such as compile time, memory footprint, runtime, code complexity. I thought it would have been fun to take the C++ version and compile it to JS via emscripten. Unfortunately, I'm running into problems I can't figure out (quickly).

The code is here (repro instructions are at the bottom):
http://code.google.com/p/multi-language-bench/

1) My first problem is that the generated JS code has two stubs:
llvm_expect_i64, and _ZSt17__throw_bad_allocv. I can manually add those after each compilation, but I'm sure I just have to link with some llvm code... does anybody know which?! Note: Both functions are being called!

2) The code runs into an exception caused by the allocator very early, see stack trace:

Welcome to LoopTesterApp, C++ edition
Constructing cfg...
Constructing lsg...
loops.js:16690: TypeError: Property '__ZSt17__throw_bad_allocv' of
object [object Object] is not a function
ructureGraphC1Ev($lsg) } catch(e) { if (typeof e != "number") throw e;
if (ABO
^
TypeError: Property '__ZSt17__throw_bad_allocv' of object [object
Object] is not a function
at
__ZN9__gnu_cxx13new_allocatorISt10_List_nodeIP10SimpleLoopEE8allocateEmPKv
(loops.js:6075:7)
at __ZNSt10_List_baseIP10SimpleLoopSaIS1_EE11_M_get_nodeEv
(loops.js:5865:13)
at __ZNSt4listIP10SimpleLoopSaIS1_EE14_M_create_nodeERKS1_
(loops.js:5788:17)
at
__ZNSt4listIP10SimpleLoopSaIS1_EE9_M_insertESt14_List_iteratorIS1_ERKS1_
(loops.js:5708:13)
at __ZNSt4listIP10SimpleLoopSaIS1_EE9push_backERKS1_ (loops.js:
5688:3)
at __ZN18LoopStructureGraph7AddLoopEP10SimpleLoop (loops.js:
3433:3)
at loops.js:20377:53
at __ZN18LoopStructureGraphC2Ev (loops.js:20377:282)
at __ZN18LoopStructureGraphC1Ev (loops.js:16963:3)
at loops.js:16690:53

Am I forgetting to link with the C++ stdlin or something? How do I do
that?

To reproduce:
#Download sources:
svn checkout http://multi-language-bench.googlecode.com/svn/trunk/ bench

# find the C++ version of the benchmark
cd bench/trunk/havlak/cpp

# compile to bitcode
clang -m32 -c LoopTesterApp.cc -emit-llvm -o LoopTesterApp.bc
clang -m32 -c mao-loops.cc -emit-llvm -o mao-loops.bc
llvm-link mao-loops.bc LoopTesterApp.bc -o loops.bc

# convert to JS
python kripken-emscripten-ff7d01a/emscripten.py loops.bc >loops.js

# run
~/projects/v8/d8 loops.js