Skip to content

Enable real dynamic linking with -shared by default#25930

Open
sbc100 wants to merge 1 commit into
emscripten-core:mainfrom
sbc100:shared_flag_part2
Open

Enable real dynamic linking with -shared by default#25930
sbc100 wants to merge 1 commit into
emscripten-core:mainfrom
sbc100:shared_flag_part2

Conversation

@sbc100
Copy link
Copy Markdown
Collaborator

@sbc100 sbc100 commented Dec 11, 2025

This change essentially disables FAKE_DYLIBS by default, which in
turn means -shared will now produce dynamic libraries by default.

If you want the old behaviour you now need -sFAKE_DYLIBS.

For cmake builds we still don't set TARGET_SUPPORTS_SHARED_LIBS.
That will likely be a followup once we deal with https://gitlab.kitware.com/cmake/cmake/-/work_items/27240

Comment thread cmake/Modules/Platform/Emscripten.cmake Outdated
@sbc100 sbc100 force-pushed the shared_flag_part2 branch 2 times, most recently from 6e4f78f to 3b0addc Compare December 11, 2025 00:49
@sbc100 sbc100 requested review from dschuff and kripken December 11, 2025 00:50
Comment thread site/source/docs/tools_reference/settings_reference.rst Outdated
Comment thread tools/building.py
Copy link
Copy Markdown
Member

@dschuff dschuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder what would happen if we tested this with Binaryen. it doesn't seem prepared to force the Emscripten build to be static (assuming that's the behavior we actually want).

Comment thread test/test_core.py Outdated
@sbc100 sbc100 force-pushed the shared_flag_part2 branch from 3b0addc to 2a98976 Compare May 12, 2026 01:15
@sbc100 sbc100 changed the title Disable FAKE_DYLIBS by default Enable real dynamic linking by default May 12, 2026
@sbc100 sbc100 force-pushed the shared_flag_part2 branch 3 times, most recently from 3b9f050 to d2bc4e4 Compare May 12, 2026 04:13
Comment thread cmake/Modules/Platform/Emscripten.cmake
@sbc100 sbc100 force-pushed the shared_flag_part2 branch 2 times, most recently from dbf81cc to 2a061bd Compare May 14, 2026 01:07
sbc100 added a commit that referenced this pull request May 14, 2026
This test was first added in c735bb6. Hopefully these changes make it
more obvious what is being tested, and also test more commonly used
flags (`-shared` vs `-r`).

Split out from #25930.
@sbc100 sbc100 force-pushed the shared_flag_part2 branch 4 times, most recently from d43b884 to 19b4b57 Compare May 15, 2026 19:07
@sbc100
Copy link
Copy Markdown
Collaborator Author

sbc100 commented May 15, 2026

I wonder what would happen if we tested this with Binaryen. it doesn't seem prepared to force the Emscripten build to be static (assuming that's the behavior we actually want).

I actually ended up leaving the cmake TARGET_SUPPORTS_SHARED_LIBS setting as False until we resolve https://gitlab.kitware.com/cmake/cmake/-/work_items/27240

@sbc100
Copy link
Copy Markdown
Collaborator Author

sbc100 commented May 15, 2026

OK, I think this change is in pretty good shape now

@sbc100 sbc100 force-pushed the shared_flag_part2 branch from 19b4b57 to 28ec96d Compare May 15, 2026 19:31
@sbc100 sbc100 changed the title Enable real dynamic linking by default Enable real dynamic linking with -shared by default May 15, 2026
@sbc100 sbc100 force-pushed the shared_flag_part2 branch from 28ec96d to 6b35408 Compare May 15, 2026 21:40
@sbc100
Copy link
Copy Markdown
Collaborator Author

sbc100 commented May 16, 2026

@kripken @dschuff this change is pretty small now. No codesize changes anymore.

@sbc100 sbc100 requested review from dschuff and kripken May 16, 2026 00:48
Copy link
Copy Markdown
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain the motivation more? It doesn't look like this removes a bunch of code or simplifies anything significantly. Do you just think this is a more sensible default? (If so, I wonder how we measure that against the annoyance of a breaking change for our users.)

Comment thread ChangeLog.md Outdated
This change essentially disables `FAKE_DYLIBS` by default, which in
turn means `-shared` will now produce dynamic libraries by default.

If you want the old behaviour you now need `-sFAKE_DYLIBS`.
@sbc100 sbc100 force-pushed the shared_flag_part2 branch from 6b35408 to 2901ff3 Compare May 18, 2026 17:01
@sbc100
Copy link
Copy Markdown
Collaborator Author

sbc100 commented May 18, 2026

Can you explain the motivation more? It doesn't look like this removes a bunch of code or simplifies anything significantly. Do you just think this is a more sensible default? (If so, I wonder how we measure that against the annoyance of a breaking change for our users.)

You would right that this change intentionally doesn't really simplify the code internally or remove much complexity. All it does it change a default, but we are continuing to support the old way for some period of time.

The hope is that is if -sFAKE_DYLIBS is not actually used/useful for real users we can then remove that feature. Switching it off by default is, I hope, just the first step to removing it completely.

The motivation is indeed to have more sensible default and mimic native toolchains more. i.e. we should be able to use -shared rather then having a our own special -sSIDE_MODULE these days.

My guess is that very very few folks rely on these fake side modules. We have, after all, had a warning in place for any users of this feature for a long time now:

$ emcc -fPIC -shared hello.c -o libfoo.so
emcc: warning: linking a library with `-shared` will emit a static object file (FAKE_DYLIBS defaults to true).  If you want to build a runtime shared library use the SIDE_MODULE or FAKE_DYLIBS=0. [-Wemcc]

The main reason these fake side modules were invented was to allow folks to build projects that included shared libraries and had no option to disable them. i.e. no -DBUILD_STATIC to similar. I believe those cases a few and far between and those are the ones where it would make sense to explicitly use the -sFAKE_DYLIBS setting (i.e. opt into it).

@sbc100
Copy link
Copy Markdown
Collaborator Author

sbc100 commented May 18, 2026

(I actually worked very hard to make sure this change was as small as possible.. i.e. mostly just flipping a boolean setting, and not really changing anything else. In fact this change is the whole reason I introduced the new -sFAKE_DYLIBS settings, so that we could one day disable it by default).

@dschuff
Copy link
Copy Markdown
Member

dschuff commented May 18, 2026

Given that we have a sensible behavior for dynamic linking, I think that having the -shared flag enable that behavior is a more sensible default than having the -shared flag do nothing. (Note that we are not enabling dynamic linking itself by default the way it is on Linux).
Speaking of what the behavior is, before we ship this in a release, we should update our documentation with a description of the expected way to use and enable dynamic linking.

sbc100 added a commit to sbc100/emscripten that referenced this pull request May 18, 2026
In particular, mention the `FAKE_DYLIBS` setting.

This is important especially since we are about the change the default
behavior.  See emscripten-core#25930
@sbc100
Copy link
Copy Markdown
Collaborator Author

sbc100 commented May 18, 2026

Given that we have a sensible behavior for dynamic linking, I think that having the -shared flag enable that behavior is a more sensible default than having the -shared flag do nothing. (Note that we are not enabling dynamic linking itself by default the way it is on Linux). Speaking of what the behavior is, before we ship this in a release, we should update our documentation with a description of the expected way to use and enable dynamic linking.

Good idea. I started by updated the docs here: #26976.

I can then include another update with this PR when it lands.

sbc100 added a commit to sbc100/emscripten that referenced this pull request May 18, 2026
In particular, mention the `FAKE_DYLIBS` setting.

This is important especially since we are about the change the default
behavior.  See emscripten-core#25930
sbc100 added a commit to sbc100/emscripten that referenced this pull request May 19, 2026
In particular, mention the `FAKE_DYLIBS` setting.

This is important especially since we are about the change the default
behavior.  See emscripten-core#25930
sbc100 added a commit that referenced this pull request May 19, 2026
In particular, mention the `FAKE_DYLIBS` setting.

This is important especially since we are about the change the default
behavior. See #25930
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.

5 participants