Skip to content

ASM_CONSTS mismatch when building two wasm modules: one with -msimd128 and one without #25631

@andyb1979

Description

@andyb1979

Hi all,

I'm attempting to build a wasm module with Emscripten once with -msimd128 -msse2 and have a fallback without. This uses the makeflags

ifeq ($(P_SIMD),1)
LINKFLAGS += -msimd128 -msse2 // later passed to emcc
COMPILEFLAGS += -msimd128 -msse2 // later passed to emcc 
endif

Here are our complete emcc flags sent to the compiler:

// SIMD version
emcc   -s WASM=1 --bind -s STACK_SIZE=8388608 -s GL_WORKAROUND_SAFARI_GETCONTEXT_BUG=0 -s NO_DYNAMIC_EXECUTION=1 --lembind --closure 0 --no-heap-copy -s USE_SDL=2 -s FETCH=1 -s ALLOW_MEMORY_GROWTH=1 -s MAX_WEBGL_VERSION=2 -Oz -msimd128 -msse2 -s MODULARIZE=1 -s NODEJS_CATCH_REJECTION=0 -s ENVIRONMENT=web -s EXPORTED_FUNCTIONS="['_main', '_setThrew', '_malloc', '_free']" -s EXPORTED_RUNTIME_METHODS="['ccall', 'cwrap','lengthBytesUTF8','stringToUTF8','UTF8ToString','callMain']" @allobjfiles2d.list obj/GL2_SIMD/Release/Core.Cpp/src/module.o   -o module.js --post-js postJsOverrides.js
// Non-SIMD version
emcc   -s WASM=1 --bind -s STACK_SIZE=8388608 -s GL_WORKAROUND_SAFARI_GETCONTEXT_BUG=0 -s NO_DYNAMIC_EXECUTION=1 --lembind --closure 0 --no-heap-copy -s USE_SDL=2 -s FETCH=1 -s ALLOW_MEMORY_GROWTH=1 -s MAX_WEBGL_VERSION=2 -Oz -s MODULA
RIZE=1 -s NODEJS_CATCH_REJECTION=0 -s ENVIRONMENT=web -s EXPORTED_FUNCTIONS="['_main', '_setThrew', '_malloc', '_free']" -s EXPORTED_RUNTIME_
METHODS="['ccall', 'cwrap','lengthBytesUTF8','stringToUTF8','UTF8ToString','callMain']" @allobjfiles2d.list obj/GL2_NOSIMD/Release/Core.Cpp/src/module.o   -o module-nosimd.js --post-js postJsOverrides.js

This outputs two modules: module.wasm and module-nosimd.wasm

Two JS glue codes are generated: module.js and module-nosimd.js

One problem, I only want to include one set of glue code as it will bloat the final bundle size. However there are minor differences in ASM_CONSTS between the two versions:

Image

This is causing the runtime initialization to fail when loading one wasm or another with the error

   at runEmAsmFunction (module.js:9:141722)
   at _emscripten_asm_const_int (module.js:9:141756)
   at module-nosimd.wasm:0xb24e2 ...

Question: Is there a way to unify the ASM_CONSTS generated in the two builds to ensure that I can use one module glue code for the two separate wasms (-nosimd and simd variants)?

Thank you in advance,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions