Search code examples
javascriptemscriptenwebassembly

Emscripten - Compile to WASM and keep original callable function names in the glue code


Using Emscripten v 1.38.43, I'm compiling a C code. For optimization reasons, I've stripped down the generated JS glue code and minimize the code size.

While doing so I've spotted that the JS callables are mapped like so:

var asmLibraryArg = {
  "b": ___setErrNo,
  "j": _emscripten_get_heap_size,
  "i": _emscripten_memcpy_big,
  "h": _emscripten_resize_heap,
  "g": myFunctionA,
  "f": myFunctionB,
  "e": myFunctionC,
  "d": myFunctionD,
  "c": abortOnCannotGrowMemory,
  "a": DYNAMICTOP_PTR
};

Making my stripped JS harder to maintain. On an older version (1.38.8) it used to output the function names with a prefixed _ i.e "_myFunctionA" : myFunctionA


Q: Can I give the emcc compiler a flag that will force it to keep my original function names in the generated JS?


Solution

  • There isn't a specific flag to turn that off, but currently the internal flag -s EMITTING_JS=0 will do that (if it thinks it isn't emitting JS, it won't minify stuff that involves JS). However, this flag may change in the future - we are working on better flags to control all this.

    A workaround is to use a lower optimization level, as this is only done in -O3, -Os and above.