Error converting c++ file to wasm using emscripten

1.3k views Asked by At

This is a follow up question from this post Converting .cpp file to .wasm file

I'm trying to convert my c++ file into .wasm using emscripten on linux. I'm running into this error:

/home/maria/emsdk/upstream/lib/clang/10.0.0/include/ia32intrin.h:188:10: error: use of undeclared identifier '__builtin_ia32_readeflags_u32'
  return __builtin_ia32_readeflags_u32();
         ^
/home/maria/emsdk/upstream/lib/clang/10.0.0/include/ia32intrin.h:194:3: error: use of undeclared identifier '__builtin_ia32_writeeflags_u32'
  __builtin_ia32_writeeflags_u32(__f);
  ^
/home/maria/emsdk/upstream/lib/clang/10.0.0/include/ia32intrin.h:284:10: error: use of undeclared identifier '__builtin_ia32_crc32qi'
  return __builtin_ia32_crc32qi(__C, __D);
         ^
/home/maria/emsdk/upstream/lib/clang/10.0.0/include/ia32intrin.h:305:10: error: use of undeclared identifier '__builtin_ia32_crc32hi'
  return __builtin_ia32_crc32hi(__C, __D);
         ^
/home/maria/emsdk/upstream/lib/clang/10.0.0/include/ia32intrin.h:326:10: error: use of undeclared identifier '__builtin_ia32_crc32si'
  return __builtin_ia32_crc32si(__C, __D);
         ^
/home/maria/emsdk/upstream/lib/clang/10.0.0/include/ia32intrin.h:354:10: error: use of undeclared identifier '__builtin_ia32_rdpmc'
  return __builtin_ia32_rdpmc(__A);
         ^
/home/maria/emsdk/upstream/lib/clang/10.0.0/include/ia32intrin.h:360:10: error: use of undeclared identifier '__builtin_ia32_rdtscp'
  return __builtin_ia32_rdtscp(__A);
         ^
/home/maria/emsdk/upstream/lib/clang/10.0.0/include/ia32intrin.h:369:3: error: use of undeclared identifier '__builtin_ia32_wbinvd'
  __builtin_ia32_wbinvd();
  ^
In file included from sealdemo.cpp:1:
In file included from SEAL/native/src/seal/seal.h:6:
In file included from SEAL/native/src/seal/biguint.h:9:
In file included from SEAL/native/src/seal/memorymanager.h:10:
In file included from SEAL/native/src/seal/util/defines.h:62:
In file included from SEAL/native/src/seal/util/clang.h:18:
In file included from /home/maria/emsdk/upstream/lib/clang/10.0.0/include/x86intrin.h:15:
In file included from /home/maria/emsdk/upstream/lib/clang/10.0.0/include/immintrin.h:14:
/home/maria/emsdk/upstream/lib/clang/10.0.0/include/mmintrin.h:33:5: error: use of undeclared identifier '__builtin_ia32_emms'; did you mean '__builtin_isless'?
    __builtin_ia32_emms();
    ^
/home/maria/emsdk/upstream/lib/clang/10.0.0/include/mmintrin.h:33:5: note: '__builtin_isless' declared here
/home/maria/emsdk/upstream/lib/clang/10.0.0/include/mmintrin.h:33:25: error: too few arguments to function call, expected 2, have 0
    __builtin_ia32_emms();
                        ^
/home/maria/emsdk/upstream/lib/clang/10.0.0/include/mmintrin.h:50:19: error: use of undeclared identifier '__builtin_ia32_vec_init_v2si'
    return (__m64)__builtin_ia32_vec_init_v2si(__i, 0);
                  ^
/home/maria/emsdk/upstream/lib/clang/10.0.0/include/mmintrin.h:67:12: error: use of undeclared identifier '__builtin_ia32_vec_ext_v2si'
    return __builtin_ia32_vec_ext_v2si((__v2si)__m, 0);
           ^
/home/maria/emsdk/upstream/lib/clang/10.0.0/include/mmintrin.h:129:19: error: use of undeclared identifier '__builtin_ia32_packsswb'
    return (__m64)__builtin_ia32_packsswb((__v4hi)__m1, (__v4hi)__m2);
                  ^
/home/maria/emsdk/upstream/lib/clang/10.0.0/include/mmintrin.h:159:19: error: use of undeclared identifier '__builtin_ia32_packssdw'
    return (__m64)__builtin_ia32_packssdw((__v2si)__m1, (__v2si)__m2);
                  ^
/home/maria/emsdk/upstream/lib/clang/10.0.0/include/mmintrin.h:189:19: error: use of undeclared identifier '__builtin_ia32_packuswb'
    return (__m64)__builtin_ia32_packuswb((__v4hi)__m1, (__v4hi)__m2);
                  ^
/home/maria/emsdk/upstream/lib/clang/10.0.0/include/mmintrin.h:216:19: error: use of undeclared identifier '__builtin_ia32_punpckhbw'
    return (__m64)__builtin_ia32_punpckhbw((__v8qi)__m1, (__v8qi)__m2);
                  ^
/home/maria/emsdk/upstream/lib/clang/10.0.0/include/mmintrin.h:239:19: error: use of undeclared identifier '__builtin_ia32_punpckhwd'
    return (__m64)__builtin_ia32_punpckhwd((__v4hi)__m1, (__v4hi)__m2);
                  ^
/home/maria/emsdk/upstream/lib/clang/10.0.0/include/mmintrin.h:260:19: error: use of undeclared identifier '__builtin_ia32_punpckhdq'
    return (__m64)__builtin_ia32_punpckhdq((__v2si)__m1, (__v2si)__m2);
                  ^
/home/maria/emsdk/upstream/lib/clang/10.0.0/include/mmintrin.h:287:19: error: use of undeclared identifier '__builtin_ia32_punpcklbw'
    return (__m64)__builtin_ia32_punpcklbw((__v8qi)__m1, (__v8qi)__m2);
                  ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
shared:ERROR: '/home/maria/emsdk/upstream/bin/clang++ -target wasm32-unknown-emscrip

Can someone help

2

There are 2 answers

0
sbc100 On

You can't/shouldn't include x86intrin.h when building for WebAssembly. It looks like you need to build without SEAL_USE_INTRIN: https://github.com/microsoft/SEAL/blob/master/native/src/seal/util/clang.h#L18

0
s0l0ist On

I've been able to compile the Microsoft SEAL library to WebAssembly using emscripten with intrinsics (#include <wasm_simd128.h>), but this is optional.

By itself, the toolchain never gave me this specific error as the emcmake step always wasn't able to find the necessary headers and compiled without the optimizations.

It sounds like you may not be using the appropriate emcmake or em++ arguments. In addition, if you want to use intrinsics you will need some conditionals inside gcc.h and clang.h (located in SEAL/native/src/seal/util/) to use the wasm_simd128.h over x86intrin.h

Feel free to checkout my implementation and/or build scripts that compile on Mac and Linux (Ubuntu): https://github.com/morfix-io/node-seal

Or download the npm package if you just want a working library: https://www.npmjs.com/package/node-seal