Feature request: suppress `undefined symbol` warning for specific symbols
There are some symbols that I manually add to wasmImports in the instantiateWasm hook. I would like to be able to suppress warnings about these being missing specifically, without turning off all missing symbol warnings.
Isn't that the one we talked about recently, the one you can use Stub Libraries for?
Do you mean you want some kind of flag like -sALLOW_UNDEFINED=foo,bar,baz and then a way to inject those symbols at runtime? With and an error at runtime if they are missing then?
I think stub libraries is a feature of wasm-ld that Emscripten can use but we can't directly access as Emscripten users. But I could be wrong. One way to deal with this for now is to define an empty EM_JS function:
EM_JS(int, some_import, (sig), {});
and then we can assign over it in Module.instantiateWasm.
You could also add a dummy JS library:
$ cat libfoo.js
addToLibrary({
foo: () => {}
bar: () => {}
}
$ emcc --js-library=libfoo.js ....
Then you would need to somehow overwrite the empty definitions of foo and bar` in the generated JS code.
Regarding the stub library feature of wasm-ld, I think can pass you own stuff libraries which will make wasm-ld happy, and it won't report errors.
$ cat libextern.so
#STUB
foo
bar
$ cat test.c
extern void foo();
int main() {
foo();
}
$ ./emcc test.c libextern.so
error: undefined symbol: foo (referenced by root reference (e.g. compiled C/C++ code))
warning: To disable errors for undefined symbols use `-sERROR_ON_UNDEFINED_SYMBOLS=0`
warning: _foo may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
Error: Aborting compilation due to previous errors
at finalCombiner (file:///usr/local/google/home/sbc/dev/wasm/emscripten/src/jsifier.mjs:886:13)
at Module.runJSify (file:///usr/local/google/home/sbc/dev/wasm/emscripten/src/jsifier.mjs:921:5)
at file:///usr/local/google/home/sbc/dev/wasm/emscripten/tools/compiler.mjs:97:17
emcc: error: '/usr/local/google/home/sbc/dev/wasm/emsdk/node/22.16.0_64bit/bin/node /usr/local/google/home/sbc/dev/wasm/emscripten/tools/compiler.mjs -' failed (returned 1)
However, as you can see, while wasm-ld no longer complains about these symbols, the JS compiler still does.. so the stub library on its own is not enough here.
Could you explain a little more about your use case? Where are these unknown symbols coming from? What is stopping you creating a JS library file for contains all the symbols?