Skip to content

Conversation

@sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Oct 8, 2025

The main advantage here is that main module no longer requires
relocation entries for symbols defined locally.

To show the benefits of this approach I build binaryan_wasm
with -sMAIN_MODULE=1 both before and after this change.

Before:

Wasm Size: 22.6M
__wasm_apply_data_relocs size: 123k

After:

Wasm Size: 16.6M
__wasm_apply_data_relocs size: 0 (no longer exists)

Fixes: #12682

@sbc100 sbc100 force-pushed the main_module_static_v2 branch 2 times, most recently from cd1b8ce to e8f95c7 Compare October 22, 2025 19:23
sbc100 added a commit to sbc100/emscripten that referenced this pull request Oct 22, 2025
Also, add an assertion to dynCall.

Split out from emscripten-core#25522.
sbc100 added a commit to sbc100/emscripten that referenced this pull request Oct 22, 2025
Also, add an assertion to dynCall.

Split out from emscripten-core#25522.
@sbc100 sbc100 force-pushed the main_module_static_v2 branch 2 times, most recently from 8c32591 to d40087a Compare October 22, 2025 20:17
@sbc100 sbc100 requested review from dschuff and kripken October 22, 2025 20:22
@sbc100
Copy link
Collaborator Author

sbc100 commented Oct 22, 2025

I still need to get some stats on the benefits of this, but that tests are all now passing so I think this should be good to review now.

An open question is: What do we do about -sRELOCTABLE. Once this change lands we will have almost not testing on this flag. We do have plan to remove it: #25262. One option is to remove -sRELOCATABLE before this change lands?

sbc100 added a commit to sbc100/emscripten that referenced this pull request Oct 22, 2025
Also, add an assertion to dynCall.

Split out from emscripten-core#25522.
@sbc100 sbc100 force-pushed the main_module_static_v2 branch from d40087a to 6008112 Compare October 22, 2025 20:49
@kripken
Copy link
Member

kripken commented Oct 22, 2025

Yeah, I see what you mean, removing RELOCATABLE first would simplify this a little. I don't have a preference though.

I do see some tests still fail here though?

sbc100 added a commit that referenced this pull request Oct 22, 2025
Also, add an assertion to dynCall.

Split out from #25522.
@sbc100 sbc100 force-pushed the main_module_static_v2 branch 5 times, most recently from 637ed91 to f56f631 Compare October 24, 2025 21:07
@sbc100 sbc100 force-pushed the main_module_static_v2 branch 2 times, most recently from 0294236 to d499627 Compare October 28, 2025 00:15
@sbc100
Copy link
Collaborator Author

sbc100 commented Oct 28, 2025

Ok, aside from the problem of what to do with -sRELOCATABLE setting, this change is not ready to go I think.

The stats look really promising. See the new PR description for the great improvements measured when building a dylink version of binaryen.

The main advantage here is that main module no longer requires
relocation entries for symbols defined locally.

To show the benefits of this approach I build binaryan_wasm
with `-sMAIN_MODULE=1` both before and after this change.

Before:

Wasm Size: 22.6M
__wasm_apply_data_relocs size: 123k

After:

Wasm Size: 16.6M
__wasm_apply_data_relocs size: 0 (no longer exists)

Fixes: emscripten-core#12682
@sbc100 sbc100 force-pushed the main_module_static_v2 branch from d499627 to 2c6de78 Compare October 28, 2025 00:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stop building MAIN_MODULE with RELOCATABLE (-fPIC)

3 participants