Skip to content

Conversation

@dschuff
Copy link
Member

@dschuff dschuff commented Jan 15, 2026

The mimalloc CMake code unconditionally adds libatomic to its link
dependencies, but it's not actually needed on the modern systems
that we're building for. Adding the --as-needed flag causes the
linker to only link against the following libraries if they
provide symbols that are actually needed.

For static linking, we wrap mimalloc's injected dependencies in
-Wl,--as-needed since they surface all the way up to the final
link line for each tool (I don't think it would hurt to just
link all the tools with --as-needed but this seemed cleaner).
For dynamic linking, it's sufficient to just make the libmimalloc.so
link with --as-needed.

Fixes emscripten-core/emsdk#928

Copy link
Member

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

Nice!

@sbc100
Copy link
Member

sbc100 commented Jan 15, 2026

I wonder if its worth filing a mimalloc bug to let them know about this issue?

@dschuff
Copy link
Member Author

dschuff commented Jan 15, 2026

I dunno. I'm still very surprised there are any systems that don't have libatomic.so. libgcc is ubiquitous.

@sbc100
Copy link
Member

sbc100 commented Jan 15, 2026

I dunno. I'm still very surprised there are any systems that don't have libatomic.so. libgcc is ubiquitous.

I guess its always available in the package repo, but not installed on very minimal images? i.e. you can install a base linux setup without needing this particular package (libatomic1)

@dschuff dschuff changed the base branch from fix-lld to main January 16, 2026 00:26
The mimalloc CMake code unconditionally adds libatomic to its link
dependencies, but it's not actually needed on the modern systems
that we're building for. Adding the --as-needed flag causes the
linker to only link against the following libraries if they
provide symbols that are actually needed.

For static linking, we wrap mimalloc's injected dependencies in
-Wl,--as-needed since they surface all the way up to the final
link line for each tool (I don't think it would hurt to just
link all the tools with --as-needed but this seemed cleaner).
For dynamic linking, it's sufficient to just make the libmimalloc.so
link with --as-needed.
@dschuff dschuff force-pushed the mimalloc-as-needed branch from 00f1de1 to c71d2df Compare January 16, 2026 00:38
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.

3 participants