Skip to content

Link mimalloc with --as-needed on Linux - #8211

Merged
dschuff merged 2 commits into
mainfrom
mimalloc-as-needed
Jan 16, 2026
Merged

dschuff merged 2 commits into
mainfrom
mimalloc-as-needed

Conversation

@dschuff

@dschuff dschuff commented Jan 15, 2026 •

Copy link
Copy Markdown
Member

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.

As a drive-by cleanup, also make mimalloc a private dependency of
libbinaryen.

Fixes emscripten-core/emsdk#928

@sbc100 sbc100 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice!

@sbc100

sbc100 commented Jan 15, 2026

Copy link
Copy Markdown
Member

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

@dschuff

dschuff commented Jan 15, 2026

Copy link
Copy Markdown
Member Author

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

@sbc100

sbc100 commented Jan 15, 2026

Copy link
Copy Markdown
Member

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
@dschuff
dschuff enabled auto-merge (squash) January 16, 2026 17:25
@dschuff
dschuff merged commit aa77b42 into main Jan 16, 2026
17 checks passed
@dschuff
dschuff deleted the mimalloc-as-needed branch January 16, 2026 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants