WebAssembly / binaryen

Optimizer and compiler/toolchain library for WebAssembly
Apache License 2.0
7.52k stars 745 forks source link

Call param number must match on "ios_base::getloc()" call #1847

Closed rickomax closed 5 years ago

rickomax commented 5 years ago

Hi!

I'm testing the Assimp library on WebAssembly and getting a weird "Call param number must match" (I don't get that when targeting asm.js):

WASM-validator output:

[wasm-validator error in function $__ZN10ODDLParser13OpenDDLParser11parseHeaderEPcS1_] unexpected false: call param number must match, on 
[none] (call $__ZNKSt3__28ios_base6getlocEv
 [i32] (i32.add
  [i32] (tee_local $3
   [i32] (call $__ZNSt3__224__put_character_sequenceIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_PKS4_j
    [i32] (i32.const 2055408)
    [i32] (i32.const 997036)
    [i32] (i32.const 37)
   )
  )
  [i32] (i32.load
   [i32] (i32.add
    [i32] (i32.load
     [i32] (get_local $3)
    )
    [i32] (i32.const -12)
   )
  )
 )
)

Disassembled library LLVM code portion:

_ZNSt3__2lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc.exit11: ; preds = %_ZNSt3__2lsIcNS_11char_traitsIcEENS_9allocatorIcEEEERNS_13basic_ostreamIT_T0_EES9_RKNS_12basic_stringIS6_S7_T1_EE.exit
  call void @llvm.dbg.value(metadata %"class.std::__2::basic_ostream"* %88, i64 0, metadata !2965294, metadata !489676), !dbg !2966640
  call void @llvm.dbg.value(metadata %"class.std::__2::basic_ostream"* %88, i64 0, metadata !2965301, metadata !489676), !dbg !2966643
  %89 = bitcast %"class.std::__2::basic_ostream"* %88 to i8**, !dbg !2966645
  %90 = load i8*, i8** %89, align 4, !dbg !2966645
  %91 = getelementptr i8, i8* %90, i32 -12, !dbg !2966645
  %92 = bitcast i8* %91 to i32*, !dbg !2966645
  %93 = load i32, i32* %92, align 4, !dbg !2966645
  %94 = bitcast %"class.std::__2::basic_ostream"* %88 to i8*, !dbg !2966645
  %95 = getelementptr inbounds i8, i8* %94, i32 %93, !dbg !2966645
  call void @llvm.dbg.value(metadata i8 10, i64 0, metadata !2965307, metadata !489676), !dbg !2966646
  %96 = bitcast %"class.std::__2::locale"* %4 to i8*, !dbg !2966648
  call void @llvm.lifetime.start(i64 4, i8* %96) #3, !dbg !2966648
  %97 = bitcast i8* %95 to %"class.std::__2::ios_base"*, !dbg !2966648
  %98 = invoke %"class.std::__2::locale::__imp"* @_ZNKSt3__28ios_base6getlocEv(%"class.std::__2::ios_base"* %97) #24
          to label %.noexc26 unwind label %176, !dbg !2966649

ASM.JS code portion:

function __ZN10ODDLParser13OpenDDLParser11parseHeaderEPcS1_($0,$1,$2) {
 $0 = $0|0;
 $1 = $1|0;
 $2 = $2|0;
 var $$ = 0, $$$sroa$0104$0 = 0, $$0$i$i = 0, $$0$i118 = 0, $$0$lcssa$i = 0, $$0$lcssa$i67 = 0, $$0$lcssa$i72 = 0, $$014$i = 0, $$015$i = 0, $$046 = 0, $$049 = 0, $$057$lcssa = 0, $$057144 = 0, $$09$i = 0, $$09$i64 = 0, $$09$i69 = 0, $$1 = 0, $$147 = 0, $$150 = 0, $$158 = 0;
 var $$2 = 0, $$2161 = 0, $$248163 = 0, $$251162 = 0, $$3124 = 0, $$3125 = 0, $$352122 = 0, $$352123 = 0, $$360160 = 0, $$461 = 0, $$5 = 0, $$6 = 0, $$sroa$0$0$lcssa = 0, $$sroa$0$0132 = 0, $$sroa$0$0143 = 0, $$sroa$0$1$ph = 0, $$sroa$0104$0$lcssa = 0, $$sroa$0104$0138 = 0, $$sroa$0104$0141 = 0, $$sroa$0104$2$ph = 0;
 var $$sroa$096$0$lcssa = 0, $$sroa$096$0142 = 0, $$sroa$096$3$ph = 0, $$sroa$096$4 = 0, $$sroa$096$5 = 0, $10 = 0, $100 = 0, $101 = 0, $102 = 0, $103 = 0, $104 = 0, $105 = 0, $106 = 0, $107 = 0, $108 = 0, $109 = 0, $11 = 0, $110 = 0, $111 = 0, $112 = 0;
 var $113 = 0, $114 = 0, $115 = 0, $116 = 0, $117 = 0, $118 = 0, $119 = 0, $12 = 0, $120 = 0, $121 = 0, $122 = 0, $123 = 0, $124 = 0, $125 = 0, $126 = 0, $127 = 0, $128 = 0, $129 = 0, $13 = 0, $130 = 0;
 var $131 = 0, $132 = 0, $133 = 0, $134 = 0, $135 = 0, $136 = 0, $137 = 0, $138 = 0, $139 = 0, $14 = 0, $140 = 0, $141 = 0, $142 = 0, $15 = 0, $16 = 0, $17 = 0, $18 = 0, $19 = 0, $20 = 0, $21 = 0;
 var $22 = 0, $23 = 0, $24 = 0, $25 = 0, $26 = 0, $27 = 0, $28 = 0, $29 = 0, $3 = 0, $30 = 0, $31 = 0, $32 = 0, $33 = 0, $34 = 0, $35 = 0, $36 = 0, $37 = 0, $38 = 0, $39 = 0, $4 = 0;
 var $40 = 0, $41 = 0, $42 = 0, $43 = 0, $44 = 0, $45 = 0, $46 = 0, $47 = 0, $48 = 0, $49 = 0, $5 = 0, $50 = 0, $51 = 0, $52 = 0, $53 = 0, $54 = 0, $55 = 0, $56 = 0, $57 = 0, $58 = 0;
 var $59 = 0, $6 = 0, $60 = 0, $61 = 0, $62 = 0, $63 = 0, $64 = 0, $65 = 0, $66 = 0, $67 = 0, $68 = 0, $69 = 0, $7 = 0, $70 = 0, $71 = 0, $72 = 0, $73 = 0, $74 = 0, $75 = 0, $76 = 0;
 var $77 = 0, $78 = 0, $79 = 0, $8 = 0, $80 = 0, $81 = 0, $82 = 0, $83 = 0, $84 = 0, $85 = 0, $86 = 0, $87 = 0, $88 = 0, $89 = 0, $9 = 0, $90 = 0, $91 = 0, $92 = 0, $93 = 0, $94 = 0;
 var $95 = 0, $96 = 0, $97 = 0, $98 = 0, $99 = 0, $cond = 0, $cond1 = 0, $or$cond = 0, $or$cond5 = 0, $or$cond62 = 0, $or$cond63 = 0, $or$cond63140 = 0, label = 0, sp = 0;
 sp = STACKTOP;
 STACKTOP = STACKTOP + 48|0;
 $3 = sp + 28|0;
 $4 = sp + 16|0;
 $5 = sp + 12|0;
 $6 = sp;
 $7 = ($1|0)==(0|0);
 $8 = ($1|0)==($2|0);
 $or$cond62 = $7 | $8;
 if ($or$cond62) {
  $$6 = $1;
 } else {
  store4($5,0);
  $9 = (__ZN10ODDLParser13OpenDDLParser15parseIdentifierEPcS1_PPNS_4TextE($1,$2,$5)|0);
  $10 = ($9|0)==($2|0);
  L3: do {
   if ($10) {
    $$0$lcssa$i = $2;
   } else {
    $$09$i = $9;
    while(1) {
     $11 = load1($$09$i);
     switch ($11<<24>>24) {
     case 44: case 10: case 13: case 9: case 32:  {
      break;
     }
     default: {
      $$0$lcssa$i = $$09$i;
      break L3;
     }
     }
     $12 = ((($$09$i)) + 1|0);
     $13 = ($12|0)==($2|0);
     if ($13) {
      $$0$lcssa$i = $2;
      break L3;
     } else {
      $$09$i = $12;
     }
    }
   }
  } while(0);
  $14 = load4($5);
  $15 = ($14|0)==(0|0);
  L8: do {
   if ($15) {
    $$461 = $$0$lcssa$i;
    label = 75;
   } else {
    $16 = ($0|0)==(0|0);
    L10: do {
     if ($16) {
      label = 17;
     } else {
      $17 = ((($14)) + 8|0);
      $18 = load4($17);
      $19 = ($18|0)==(0|0);
      if ($19) {
       label = 17;
      } else {
       ; store8($3,i64_const(0,0),4); store4($3+8|0,0,4);
       $20 = (_strlen($18)|0);
       __ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initEPKcj($3,$18,$20);
       $21 = ((($0)) + 16|0);
       $22 = load4($21);
       $23 = ((($0)) + 20|0);
       $24 = load4($23);
       $25 = ($22|0)==($24|0);
       if ($25) {
        $$0$i$i = 0;
       } else {
        $26 = ((($24)) + -4|0);
        $27 = load4($26);
        $$0$i$i = $27;
       }
       ; store8($4,i64_const(0,0),4); store4($4+8|0,0,4);
       __THREW__ = 0;
       invoke_viii(3357,($4|0),(2073879|0),0);
       $28 = __THREW__; __THREW__ = 0;
       $29 = $28&1;
       do {
        if ($29) {
         $33 = ___cxa_find_matching_catch_2()|0;
         $34 = tempRet0;
         $$014$i = $34;$$015$i = $33;
        } else {
         __THREW__ = 0;
         $30 = (invoke_iiii(3126,($3|0),($4|0),($$0$i$i|0))|0);
         $31 = __THREW__; __THREW__ = 0;
         $32 = $31&1;
         if ($32) {
          $35 = ___cxa_find_matching_catch_2()|0;
          $36 = tempRet0;
          __ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEED2Ev($4);
          $$014$i = $36;$$015$i = $35;
          break;
         }
         __ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEED2Ev($4);
         __ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEED2Ev($3);
         $37 = ($30|0)==(0|0);
         if ($37) {
          label = 17;
          break L10;
         }
         __ZN10ODDLParser13OpenDDLParser8pushNodeEPNS_7DDLNodeE($0,$30);
         $$0$i118 = $30;$58 = 1;
         break L10;
        }
       } while(0);
       __ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEED2Ev($3);
       ___resumeException($$015$i|0);
       // unreachable;
      }
     }
    } while(0);
    do {
     if ((label|0) == 17) {
      $38 = (__ZNSt3__224__put_character_sequenceIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_PKS4_j(2055408,997036,37)|0);
      $39 = load4($38);
      $40 = ((($39)) + -12|0);
      $41 = load4($40);
      $42 = (($38) + ($41)|0);
      __ZNKSt3__28ios_base6getlocEv($42);
      store4($3,$43);
      __THREW__ = 0;
      $44 = (invoke_iii(4438,($3|0),(2056112|0))|0);
      $45 = __THREW__; __THREW__ = 0;
      $46 = $45&1;
      if (!($46)) {
       $47 = load4($44);
       $48 = ((($47)) + 28|0);
       $49 = load4($48);
       __THREW__ = 0;
       $50 = (invoke_iii($49|0,($44|0),10)|0);
       $51 = __THREW__; __THREW__ = 0;
       $52 = $51&1;
       if (!($52)) {
        __ZNSt3__26localeD2Ev($3);
        (__ZNSt3__213basic_ostreamIcNS_11char_traitsIcEEE3putEc($38,$50)|0);
        (__ZNSt3__213basic_ostreamIcNS_11char_traitsIcEEE5flushEv($38)|0);
        $$0$i118 = 0;$58 = 0;
        break;
       }
      }
      $53 = ___cxa_find_matching_catch_2()|0;
      $54 = tempRet0;
      __ZNSt3__26localeD2Ev($3);
      ___resumeException($53|0);
      // unreachable;
     }
    }

The problematic line:

_ZNKSt3__28ios_base6getlocEv($42);

Original C++ code portion: OpenDDLParser.cpp#L262

I can't find where the disassembled code is passing the false value into the method call, but "getLoc" definitely doesn't expect that: http://www.cplusplus.com/reference/ios/ios_base/getloc/

I'm using EMSDK version 1.37.33 that comes with Unity 2018.2.12f1.

Something related to the Assimp code itself? Any advice?

kripken commented 5 years ago

I don't see a false value there - it's just mentioned in the validator message in the sense of "assertion failed, this was false but should not have been false"? Unless I'm missing something.

Seems like the called function, __ZNKSt3__28ios_base6getlocEv, has a single parameter, a this pointer, in the LLVM IR, asm.js, and wasm. So that all looks consistent. How is that function declared in all of those?

One possibility is that this is a bug that was fixed since 1.37.33, which is quite old at this point (Feb 2, almost a year). We did have some bugs in that area in the past.

rickomax commented 5 years ago

On asm.js (EMSDK 1.37.33):

function __ZNKSt3__28ios_base6getlocEv($0,$1) {
 $0 = $0|0;
 $1 = $1|0;
 var $2 = 0, label = 0, sp = 0;
 sp = STACKTOP;
 $2 = ((($1)) + 28|0);
 __ZNSt3__26localeC2ERKS0_($0,$2);
 return;
}

Seems one parameter is being omitted.

I cannot find the "getLoc" method declaration on the LLVM bitcode (libassimp.bc disasm). The only places referencing it which aren't method calls on the LLVM bitcode I found are:

!558578 = distinct !DISubprogram(name: "getloc", linkageName: "_ZNKSt3__215basic_streambufIcNS_11char_traitsIcEEE6getlocEv", scope: !16241, file: !16242, line: 144, type: !558579, isLocal: false, isDefinition: true, scopeLine: 144, flags: DIFlagPrototyped, isOptimized: true, unit: !354313, declaration: !558581, variables: !558582)
; Function Attrs: optsize
declare %"class.std::__2::locale::__imp"* @_ZNKSt3__28ios_base6getlocEv(%"class.std::__2::ios_base"*) local_unnamed_addr #8

On an older EMSDK version (1.37.3) which is working, the asm.js function is declared as:

function __ZNKSt3__28ios_base6getlocEv(i1) {
 i1 = i1 | 0;
 var i2 = 0, i3 = 0;
 i2 = STACKTOP;
 STACKTOP = STACKTOP + 16 | 0;
 if ((STACKTOP | 0) >= (STACK_MAX | 0)) abortStackOverflow(16);
 i3 = i2;
 __ZNSt3__26localeC2ERKS0_(i3, i1 + 28 | 0);
 STACKTOP = i2;
 return HEAP32[i3 >> 2] | 0;
}

Since I'm using the code on Unity, I have to use the bundled EMSDK of the specific Unity version, so I'm afraid I won't be able to fix that if that requires updating EMSDK/Binaryen.

kripken commented 5 years ago

Thanks for the extra info. I think that's what we fixed in https://github.com/WebAssembly/binaryen/pull/1439 , which indeed landed after 1.37.33.

There might be some way to work around this in the source code, but updating binaryen is the best thing. If it's hard to update the entire emsdk+binaryen, all you need is to build binaryen master from the time of that PR landing, and replace the asm2wasm and wasm-opt binaries.

rickomax commented 5 years ago

Any way to skip the asm2wasm validation process?

kripken commented 5 years ago

Not really. You can tell asm2wasm not to validate with --no-validation, but that won't help - the wasm VM will throw a validation error on loading the wasm file.

rickomax commented 5 years ago

Building on a newer EMSDK version (1.38.11) doesn't give the above errors, but give some errors regarding missing symbols:

warning: unexpected number of arguments 2 in call to '_ZNKSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE13get_allocatorEv', should be 1
warning: unexpected number of arguments 2 in call to '_ZNKSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE13get_allocatorEv', should be 1
warning: unexpected number of arguments 2 in call to '_ZNKSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE13get_allocatorEv', should be 1
warning: unexpected number of arguments 2 in call to '_ZNKSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE13get_allocatorEv', should be 1
warning: unexpected number of arguments 1 in call to '_ZNKSt3__215basic_streambufIcNS_11char_traitsIcEEE6getlocEv', should be 2
warning: unexpected return type %"class.std::__2::locale::__imp"* in call to '_ZNKSt3__215basic_streambufIcNS_11char_traitsIcEEE6getlocEv', should be void
warning: unexpected number of arguments 1 in call to '_ZNKSt3__215basic_streambufIcNS_11char_traitsIcEEE6getlocEv', should be 2
warning: unexpected return type %"class.std::__2::locale::__imp"* in call to '_ZNKSt3__215basic_streambufIcNS_11char_traitsIcEEE6getlocEv', should be void
warning: unexpected number of arguments 2 in call to '_ZNKSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE13get_allocatorEv', should be 1
warning: unexpected number of arguments 2 in call to '_ZNKSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE13get_allocatorEv', should be 1
warning: unexpected number of arguments 1 in call to '_ZNKSt3__28ios_base6getlocEv', should be 2
warning: unexpected return type %"class.std::__2::locale::__imp"* in call to '_ZNKSt3__28ios_base6getlocEv', should be void
warning: unexpected number of arguments 2 in call to '_ZNKSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE13get_allocatorEv', should be 1
warning: unexpected return type i32 in call to 'aiSetImportPropertyInteger', should be void
warning: unexpected return type i32 in call to 'aiSetImportPropertyFloat', should be void
warning: unexpected return type i32 in call to 'aiSetImportPropertyString', should be void
warning: unexpected return type i32 in call to 'aiSetImportPropertyMatrix', should be void
warning: unexpected number of arguments 2 in call to '_ZN6il2cpp6icalls8mscorlib6System6String22RedirectToCreateStringEv', should be 0
warning: unexpected number of arguments 4 in call to '_ZN6il2cpp6icalls8mscorlib6System6String22RedirectToCreateStringEv', should be 0
warning: unexpected number of arguments 5 in call to '_ZN6il2cpp6icalls8mscorlib6System6String22RedirectToCreateStringEv', should be 0
warning: unexpected number of arguments 4 in call to '_ZN6il2cpp6icalls8mscorlib6System6String22RedirectToCreateStringEv', should be 0
warning: unexpected number of arguments 2 in call to '_ZN6il2cpp6icalls8mscorlib6System6String22RedirectToCreateStringEv', should be 0
warning: unexpected number of arguments 3 in call to '_ZN6il2cpp6icalls8mscorlib6System6String22RedirectToCreateStringEv', should be 0
warning: unexpected number of arguments 0 in call to '_ZNSt3__216forward_as_tupleIJEEENS_5tupleIJDpOT_EEES4_', should be 1
warning: unexpected number of arguments 0 in call to '_ZNSt3__216forward_as_tupleIJEEENS_5tupleIJDpOT_EEES4_', should be 1
warning: unexpected number of arguments 0 in call to '_ZNSt3__216forward_as_tupleIJEEENS_5tupleIJDpOT_EEES4_', should be 1
warning: unexpected number of arguments 1 in call to '__cxa_pure_virtual', should be 0
warning: unexpected number of arguments 0 in call to '_ZNSt3__216forward_as_tupleIJEEENS_5tupleIJDpOT_EEES4_', should be 1
error: unresolved symbol: _ZNKSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE2atEj
error: unresolved symbol: _ZNKSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE4findEcj
error: unresolved symbol: _ZNKSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE5rfindEcj
error: unresolved symbol: _ZNKSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE7compareEjjPKcj
error: unresolved symbol: _ZNSt3__212__next_primeEj
error: unresolved symbol: _ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE5eraseEjj
error: unresolved symbol: _ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6appendEPKcj
error: unresolved symbol: _ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6insertEjPKc
error: unresolved symbol: _ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6insertEjPKcj
error: unresolved symbol: _ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6resizeEjc
error: unresolved symbol: _ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE7replaceEjjPKc
error: unresolved symbol: _ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE7reserveEj
error: unresolved symbol: _ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEC1ERKS5_jjRKS4_
error: unresolved symbol: _ZNSt3__213basic_istreamIcNS_11char_traitsIcEEE4readEPci
error: unresolved symbol: _ZNSt3__215basic_streambufIcNS_11char_traitsIcEEE6setbufEPci
error: unresolved symbol: _ZNSt3__215basic_streambufIcNS_11char_traitsIcEEE6xsgetnEPci
error: unresolved symbol: _ZNSt3__215basic_streambufIcNS_11char_traitsIcEEE6xsputnEPKci
error: unresolved symbol: _Znaj
error: unresolved symbol: _Znwj
error: unresolved symbol: _ZnwjRKSt9nothrow_t
kripken commented 5 years ago

Hmm, it's possible you need to rebuild system libraries for that version. ./emcc --clear-cache should make it rebuild them automatically next time.

kripken commented 5 years ago

Oh, also it's possible Unity has some bundled system libraries that need to be linked with the old versions, which is the opposite problem.

rickomax commented 5 years ago

The newer bitcode file has been compiled with the same EMSDK version as Unity 2019 (EMSDK 1.38.11) The libcxx versions LLVM is linking (libcxx.a and libcxxabi.bc) don't have any of the missing methods indeed:

DEBUG:root:PYTHON not defined in C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\emscripten.config, using "C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten_Win\python\2.7.5.3_64bit\python.exe"
DEBUG:root:EMCC_WASM_BACKEND tells us to use asm.js backend
warning:root:invocation: C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emcc.py @C:\Repos\trilib\2019\New Unity Project\Assets\..\Temp\emcc_arguments.resp  (in C:\Repos\trilib\2019\New Unity Project\Temp\StagingArea\Data)
warning:root:Read response file C:\Repos\trilib\2019\New Unity Project\Assets\..\Temp\emcc_arguments.resp: ['-O3', '-g2', '-DUNITY_WEBGL=1', '-s', 'PRECISE_F32=2', '-s', 'USE_WEBGL2=1', '-s', 'FULL_ES3=1', '-s', "EXTRA_EXPORTED_RUNTIME_METHODS=['addRunDependency','removeRunDependency','FS_createPath','FS_createDataFile','ccall','cwrap','stackTrace']", '-s', 'DISABLE_EXCEPTION_CATCHING=0', '-s', 'TOTAL_MEMORY=32MB', '-s', 'ASSERTIONS=1', '-s', 'DEMANGLE_SUPPORT=1', '-s', 'ERROR_ON_UNDEFINED_SYMBOLS=1', '-s', 'WASM=1', '-s', "BINARYEN_TRAP_MODE='allow'", '-s', 'ALLOW_MEMORY_GROWTH=1', '-s', 'MODULARIZE=1', '-s', 'EXPORT_NAME=UnityModule', '--memory-init-file', '1', '--emit-symbol-map', '--output_eol', 'linux', '-o', 'C:\\Repos\\trilib\\2019\\New Unity Project\\Temp\\StagingArea\\Data\\linkresult_wasm\\build.js', '--pre-js', 'C:\\Program Files\\Unity 2019.1.0a12\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\prejs\\CachedXMLHttpRequest.js', '--pre-js', 'C:\\Program Files\\Unity 2019.1.0a12\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\prejs\\FileSystem.js', '--pre-js', 'C:\\Program Files\\Unity 2019.1.0a12\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\prejs\\FullScreen.js', '--pre-js', 'C:\\Program Files\\Unity 2019.1.0a12\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\prejs\\LoaderSetup.js', '--pre-js', 'C:\\Program Files\\Unity 2019.1.0a12\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\prejs\\MediaDevices.js', '--pre-js', 'C:\\Program Files\\Unity 2019.1.0a12\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\prejs\\SendMessage.js', '--js-library', 'C:\\Program Files\\Unity 2019.1.0a12\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\lib\\Audio.js', '--js-library', 'C:\\Program Files\\Unity 2019.1.0a12\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\lib\\Cursor.js', '--js-library', 'C:\\Program Files\\Unity 2019.1.0a12\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\lib\\Eval.js', '--js-library', 'C:\\Program Files\\Unity 2019.1.0a12\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\lib\\FileSystem.js', '--js-library', 'C:\\Program Files\\Unity 2019.1.0a12\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\lib\\Logging.js', '--js-library', 'C:\\Program Files\\Unity 2019.1.0a12\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\lib\\Profiler.js', '--js-library', 'C:\\Program Files\\Unity 2019.1.0a12\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\lib\\SystemInfo.js', '--js-library', 'C:\\Program Files\\Unity 2019.1.0a12\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\lib\\UnetWebSocket.js', '--js-library', 'C:\\Program Files\\Unity 2019.1.0a12\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\lib\\Video.js', '--js-library', 'C:\\Program Files\\Unity 2019.1.0a12\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\lib\\WebCam.js', '--js-library', 'C:\\Program Files\\Unity 2019.1.0a12\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\lib\\WebRequest.js', 'C:\\Repos\\trilib\\2019\\New Unity Project\\Assets\\TriLib\\TriLib\\Plugins\\WebGL\\libz.bc', 'C:\\Repos\\trilib\\2019\\New Unity Project\\Assets\\TriLib\\TriLib\\Plugins\\WebGL\\libstb_image.bc', 'C:\\Repos\\trilib\\2019\\New Unity Project\\Assets\\TriLib\\TriLib\\Plugins\\WebGL\\libassimp.bc', 'C:\\Repos\\trilib\\2019\\New Unity Project\\Temp\\StagingArea\\Data\\Native\\build.bc']
DEBUG:root:asm.js opts not forced by user or an option that depends them, and we do not intend to run the asm.js, so disabling and leaving opts to the binaryen optimizer
DEBUG:root:compiling to bitcode
DEBUG:root:emcc step "parse arguments and setup" took 0.01 seconds
DEBUG:root:using bitcode file: C:\Repos\trilib\2019\New Unity Project\Assets\TriLib\TriLib\Plugins\WebGL\libz.bc
DEBUG:root:using bitcode file: C:\Repos\trilib\2019\New Unity Project\Assets\TriLib\TriLib\Plugins\WebGL\libstb_image.bc
DEBUG:root:using bitcode file: C:\Repos\trilib\2019\New Unity Project\Assets\TriLib\TriLib\Plugins\WebGL\libassimp.bc
DEBUG:root:using bitcode file: C:\Repos\trilib\2019\New Unity Project\Temp\StagingArea\Data\Native\build.bc
DEBUG:root:emcc step "bitcodeize inputs" took 0.00 seconds
DEBUG:root:emcc step "process inputs" took 0.00 seconds
DEBUG:root:will generate JavaScript
DEBUG:root:binaryen root already set to C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten_FastComp_Win\binaryen
DEBUG:root:forcing stdlibs: set(['libcxxabi'])
DEBUG:root:PYTHON not defined in C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\emscripten.config, using "C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten_Win\python\2.7.5.3_64bit\python.exe"
DEBUG:root:EMCC_WASM_BACKEND tells us to use asm.js backend
DEBUG:root:PYTHON not defined in C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\emscripten.config, using "C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten_Win\python\2.7.5.3_64bit\python.exe"
DEBUG:root:EMCC_WASM_BACKEND tells us to use asm.js backend
DEBUG:root:PYTHON not defined in C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\emscripten.config, using "C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten_Win\python\2.7.5.3_64bit\python.exe"
DEBUG:root:EMCC_WASM_BACKEND tells us to use asm.js backend
DEBUG:root:PYTHON not defined in C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\emscripten.config, using "C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten_Win\python\2.7.5.3_64bit\python.exe"
DEBUG:root:EMCC_WASM_BACKEND tells us to use asm.js backend
DEBUG:root:including libcxx.a
DEBUG:root:including libcxxabi.bc
DEBUG:root:including dlmalloc.bc
DEBUG:root:including libc.bc
DEBUG:root:including gl.bc
DEBUG:root:including wasm-libc.bc
DEBUG:root:including libc-extras.bc
DEBUG:root:emcc step "calculate system libraries" took 3.73 seconds
DEBUG:root:linking: ['C:\\Repos\\trilib\\2019\\New Unity Project\\Assets\\TriLib\\TriLib\\Plugins\\WebGL\\libz.bc', 'C:\\Repos\\trilib\\2019\\New Unity Project\\Assets\\TriLib\\TriLib\\Plugins\\WebGL\\libstb_image.bc', 'C:\\Repos\\trilib\\2019\\New Unity Project\\Assets\\TriLib\\TriLib\\Plugins\\WebGL\\libassimp.bc', 'C:\\Repos\\trilib\\2019\\New Unity Project\\Temp\\StagingArea\\Data\\Native\\build.bc', 'C:\\Program Files\\Unity 2019.1.0a12\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\Emscripten_FastComp_Win\\cache\\asmjs\\dlmalloc.bc', 'C:\\Program Files\\Unity 2019.1.0a12\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\Emscripten_FastComp_Win\\cache\\asmjs\\libc.bc', 'C:\\Program Files\\Unity 2019.1.0a12\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\Emscripten_FastComp_Win\\cache\\asmjs\\gl.bc', 'C:\\Program Files\\Unity 2019.1.0a12\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\Emscripten_FastComp_Win\\cache\\asmjs\\wasm-libc.bc', 'C:\\Program Files\\Unity 2019.1.0a12\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\Emscripten_FastComp_Win\\cache\\asmjs\\libc-extras.bc', 'C:\\Program Files\\Unity 2019.1.0a12\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\Emscripten_FastComp_Win\\cache\\asmjs\\libcxx.a', 'C:\\Program Files\\Unity 2019.1.0a12\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\Emscripten_FastComp_Win\\cache\\asmjs\\libcxxabi.bc']
DEBUG:root:adding object C:\Repos\trilib\2019\New Unity Project\Assets\TriLib\TriLib\Plugins\WebGL\libz.bc to link
DEBUG:root:adding object C:\Repos\trilib\2019\New Unity Project\Assets\TriLib\TriLib\Plugins\WebGL\libstb_image.bc to link
DEBUG:root:adding object C:\Repos\trilib\2019\New Unity Project\Assets\TriLib\TriLib\Plugins\WebGL\libassimp.bc to link
DEBUG:root:adding object C:\Repos\trilib\2019\New Unity Project\Temp\StagingArea\Data\Native\build.bc to link
DEBUG:root:adding object C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten_FastComp_Win\cache\asmjs\dlmalloc.bc to link
DEBUG:root:adding object C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten_FastComp_Win\cache\asmjs\libc.bc to link
DEBUG:root:adding object C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten_FastComp_Win\cache\asmjs\gl.bc to link
DEBUG:root:adding object C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten_FastComp_Win\cache\asmjs\wasm-libc.bc to link
DEBUG:root:adding object C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten_FastComp_Win\cache\asmjs\libc-extras.bc to link
DEBUG:root:considering archive C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten_FastComp_Win\cache\asmjs\libcxx.a
DEBUG:root:adding object c:\users\ricko\appdata\local\temp\emscripten_temp_zxkcra_archive_contents\algorithm_9e9ed988.cpp.o to link
DEBUG:root:adding object c:\users\ricko\appdata\local\temp\emscripten_temp_zxkcra_archive_contents\chrono_c0cc8b00.cpp.o to link
DEBUG:root:adding object c:\users\ricko\appdata\local\temp\emscripten_temp_zxkcra_archive_contents\condition_variable_8db83e31.cpp.o to link
DEBUG:root:adding object c:\users\ricko\appdata\local\temp\emscripten_temp_zxkcra_archive_contents\ios_087e100a.cpp.o to link
DEBUG:root:adding object c:\users\ricko\appdata\local\temp\emscripten_temp_zxkcra_archive_contents\iostream_989a09ed.cpp.o to link
DEBUG:root:adding object c:\users\ricko\appdata\local\temp\emscripten_temp_zxkcra_archive_contents\locale_f36e0233.cpp.o to link
DEBUG:root:adding object c:\users\ricko\appdata\local\temp\emscripten_temp_zxkcra_archive_contents\memory_226c3f41.cpp.o to link
DEBUG:root:adding object c:\users\ricko\appdata\local\temp\emscripten_temp_zxkcra_archive_contents\mutex_cdd4d261.cpp.o to link
DEBUG:root:adding object c:\users\ricko\appdata\local\temp\emscripten_temp_zxkcra_archive_contents\new_8b186b3f.cpp.o to link
DEBUG:root:adding object c:\users\ricko\appdata\local\temp\emscripten_temp_zxkcra_archive_contents\stdexcept_ca45be18.cpp.o to link
DEBUG:root:adding object c:\users\ricko\appdata\local\temp\emscripten_temp_zxkcra_archive_contents\string_a29b194f.cpp.o to link
DEBUG:root:adding object c:\users\ricko\appdata\local\temp\emscripten_temp_zxkcra_archive_contents\system_error_41fbcb95.cpp.o to link
DEBUG:root:adding object c:\users\ricko\appdata\local\temp\emscripten_temp_zxkcra_archive_contents\thread_f9c2e2ef.cpp.o to link
DEBUG:root:adding object c:\users\ricko\appdata\local\temp\emscripten_temp_zxkcra_archive_contents\vector_472937d5.cpp.o to link
DEBUG:root:adding object c:\users\ricko\appdata\local\temp\emscripten_temp_zxkcra_archive_contents\exception_02e912fc.cpp.o to link
DEBUG:root:adding object c:\users\ricko\appdata\local\temp\emscripten_temp_zxkcra_archive_contents\future_902e36fd.cpp.o to link
DEBUG:root:done running loop of archive C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten_FastComp_Win\cache\asmjs\libcxx.a
DEBUG:root:adding object C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten_FastComp_Win\cache\asmjs\libcxxabi.bc to link
DEBUG:root:emcc step "link" took 1.36 seconds
DEBUG:root:saving intermediate processing steps to C:\Users\ricko\AppData\Local\Temp\emscripten_temp
DEBUG:root:(not saving intermediate C:\Users\ricko\AppData\Local\Temp\emscripten_temp\emcc-0-basebc.bc because deferring linking)
DEBUG:root:emcc: LLVM opts: -strip-debug -disable-debug-info-type-map -internalize -internalize-public-api-list=main,__cxa_demangle,malloc,free,__errno_location,fflush,malloc,malloc,free,malloc,__cxa_can_catch,__cxa_is_pointer_type,malloc,htonl,htons,ntohs,htonl,htons,ntohs,malloc,free,htonl,htons,ntohs,malloc,_get_tzname,_get_daylight,_get_timezone,memalign,htons,_get_environ,free,free,_get_tzname,_get_daylight,_get_timezone,_get_environ,malloc,malloc,free,_get_environ,malloc,htons,malloc,htons,htonl,htons,ntohs,realloc,malloc,strlen,_get_environ -globaldce -disable-loop-vectorization -disable-slp-vectorization -vectorize-loops=false -vectorize-slp=false  [num inputs: 26]
DEBUG:root:emcc step "post-link" took 123.97 seconds
DEBUG:root:LLVM => JSINFO:root:Executing emscripten.py compiler with cmdline "C:\Users\ricko\AppData\Local\Temp\tmpuqmqyp\build.bc -o C:\Users\ricko\AppData\Local\Temp\tmpuqmqyp\build.bc.o.js --libraries C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\lib\Audio.js,C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\lib\Cursor.js,C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\lib\Eval.js,C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\lib\FileSystem.js,C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\lib\Logging.js,C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\lib\Profiler.js,C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\lib\SystemInfo.js,C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\lib\UnetWebSocket.js,C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\lib\Video.js,C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\lib\WebCam.js,C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\lib\WebRequest.js,C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\src\library_pthread_stub.js"
DEBUG:root:TEMP_DIR not defined in C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\emscripten.config, using C:\Users\ricko\AppData\Local\Temp
DEBUG:root:emscript: llvm backend: C:\Program Files\Unity 2019.1.0a12\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten_FastComp_Win\llc.exe C:\Users\ricko\AppData\Local\Temp\tmpuqmqyp\build.bc -march=js -filetype=asm -o C:\Users\ricko\AppData\Local\Temp\emscripten_temp\tmpfkwawx.4.js -emscripten-stack-size=5242880 -O3 -emscripten-precise-f32 -emscripten-assertions=1 -emscripten-global-base=1024 -enable-emscripten-cpp-exceptions -emscripten-no-exit-runtime -emscripten-wasm -emscripten-only-wasm

Now I wonder how using the same EMSDK version to build the bitcode library and the final WASM build gives these inconsistencies.

rickomax commented 5 years ago

Looks like the "libcxx.a" contains only 64-bits counterparts of the missing symbols:

operator new[](unsigned int) (_Znaj) (missing)
operator new[](unsigned long) (_Znam) (on libcxx.a)

std::__2::__next_prime(unsigned int) (_ZNSt3__212__next_primeEj) (missing)
std::__2::__next_prime(unsigned long) (_ZNSt3__212__next_primeEm) (on libcxx.a)

operator new(unsigned int) (_Znwj) (missing)
operator new(unsigned long) (_Znwm) (on libcxx.a)

operator new(unsigned int, std::nothrow_t const&) (_ZnwjRKSt9nothrow_t) (missing)
operator new(unsigned long, std::nothrow_t const&) (_ZnwmRKSt9nothrow_t) (on libcxx.a)
kripken commented 5 years ago

Emscripten changed the signature of size_t from int to long (or vice versa, I forget), so bitcode needs to be rebuilt with the new types. I think that's the cause of that issue. (They are all 32-bit ints, but get mangled differently.)

rickomax commented 5 years ago

Turns out I had the .emscripten file cache pointing to a wrong Clang version. Gonna test the new BC file.

rickomax commented 5 years ago

@kripken The issue was caused by the .emscripten cache file indeed, it was pointing to wrong LLVM/Clang versions and generating a broken BC library. Thank you for your support!