emscripten-core / emscripten-core/emscripten

How to control the exported symbols of a side module?

Open
#23,107 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

I used the -fvisibility=hidden option, but it doesn't seem to work completely.

side.cpp
```
#include
#ifdef __EMSCRIPTEN__
#include
#endif

extern "C"
{

EMSCRIPTEN_KEEPALIVE int Test()
{
std::stringbuf buf;
return buf.str().size();
}

}
em++ side.cpp -s SIDE_MODULE=2 -o side.wasm -fvisibility=hidden -v
version:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.73 (ac676d5e437525d15df5fd46bc2c208ec6d376a3)
clang version 20.0.0git (https:/github.com/llvm/llvm-project 1d810ece2b2c8fab77720493864257f0ea3336a9)
```
check the exported symbol in wat format

```
(export "__wasm_call_ctors" (func $0))
(export "Test" (func $1))
(export "_ZNSt3__215basic_stringbufIcNS_11char_traitsIcEENS_9allocatorIcEEED2Ev" (func $4))
```
It's strange, is `_ZNSt3__215basic_stringbufIcNS_11char_traitsIcEENS_9allocatorIcEEED2Ev` a system library symbol? Why is it being exported in the side module?
```
em++ main.cpp -s MAIN_MODULE=2 -o main.js -s AUTOLOAD_DYLIBS=0 side.wasm -fvisibility=hidden
If I link it to a main module, I got
(import "GOT.func" "_ZNSt3__215basic_stringbufIcNS_11char_traitsIcEENS_9allocatorIcEEED2Ev" (global $gimport$4 (mut i32)))
```
If I instantiate main module without side.wasm, I got an undefined symbol error of `_ZNSt3__215basic_stringbufIcNS_11char_traitsIcEENS_9allocatorIcEEED2Ev`

If there is a way to control the exported symbols of a side module? I want my side module to export only the symbols I need so that the initialization of the main module does not depend on any side module. This way, I can load the side modules on demand later.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.