Skip to content

Emscripten CMake toolchain disables shared libraries #20340

Open

Description

@jspanchu

This is a bit confusing when there are ways to build shared libraries using -sSIDE_MODULE. Should the toolchain permit shared libs?

Activity

  1. jspanchu commented on Sep 26, 2023

    @jspanchu
    ContributorAuthor
  2. mathstuf commented on Sep 26, 2023

    @mathstuf

    For easy reference for interested bystanders (like myself), the shared library docs: https://emscripten.org/docs/compiling/Dynamic-Linking.html#practical-details

  3. mathstuf commented on Sep 26, 2023

    @mathstuf

    See also: #16281 #17804

  4. sbc100 commented on Sep 26, 2023

    @sbc100
    Collaborator

    For now I think this best to disable shared libraries where possible. SIDE_MODULE semantics and shared library semantics don't quite match up and the places where folks would normally want to use shared libraries probably don't make sense in emscripten in many cases. Emscripten users should always prefer static linking where possible.

  5. mathstuf commented on Sep 26, 2023

    @mathstuf

    FWIW, the issue we have is that we have a global object that gets copied into multiple targets and then different call stacks get different copies of the global. So an object might get some index A in its own TU and then gets passed to some code in another TU where the index A references something else in the other object. Since there are no shared libraries, I think we may be OK for now (though testing is needed).

  6. sbc100 commented on Sep 26, 2023

    @sbc100
    Collaborator

    Can you explain what you mean by "global object" and "get some index A"? Index into what?

  7. mathstuf commented on Sep 26, 2023

    @mathstuf

    There is a static InternedStringStorage interned;-like object used for string interning. Objects intern strings and pass around handles/indices to the table when these handles are passed between code that each linked the static library containing interned, the tables may not agree with what has been interned to that point and the string returned from the table may differ (assuming it was even in-bounds). The proposed solution is to move it to a shared library so that it doesn't get copied into other libraries. This ran into problems with the Emscripten build because of this situation. But I think we can just ignore it since there will never be a shared library (until it is supported) and symbols won't get duplicated like they do in the standard builds.

    FWIW, the duplicate symbols come through the Python module (which is shared so that it can be loaded by python) and an executable that also links to the code and then loads the Python support.

  8. sbc100 commented on Sep 26, 2023

    @sbc100
    Collaborator

    Yes, if you use static linking, and the object file containing interned is part of several different static libraries then the linker will just pick the first one and ignore all the rest (assuming they all define the same set of global symbols).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions