Skip to content

fix(linux): link libpthread alongside mimalloc.o#6435

Merged
FeodorFitsner merged 2 commits intorelease/v0.85.0from
diag/mimalloc-ld
Apr 23, 2026
Merged

fix(linux): link libpthread alongside mimalloc.o#6435
FeodorFitsner merged 2 commits intorelease/v0.85.0from
diag/mimalloc-ld

Conversation

@FeodorFitsner
Copy link
Copy Markdown
Contributor

@FeodorFitsner FeodorFitsner commented Apr 23, 2026

Summary

  • The Linux client has been failing to link on every distro in the CI matrix since mimalloc was actually wired up in fix: reduce Linux video memory retention with mimalloc linking #6416. mimalloc.o uses pthread_setspecific; with ld --as-needed (default on Ubuntu 20.04+), libpthread won't be pulled in transitively and the final link aborts with undefined reference to symbol 'pthread_setspecific@@GLIBC_2.2.5' / libpthread.so.0: error adding symbols: DSO missing from command line.
  • Pair the mimalloc link with Threads::Threads in both client/linux/CMakeLists.txt and the flet build linux template so libpthread is explicitly on the link line.
  • Ubuntu 20.04 was the only distro that surfaced in logs because fail-fast cancelled the rest of the matrix — all Linux distros would hit the same failure.

Investigation

Flutter's build UI swallows ld stderr, leaving only a bare clang: error: linker command failed with exit code 1 in CI. I pushed a temporary diagnostic commit (reverted in this branch) that added flutter build linux --verbose, LINKER:--verbose, and message(NOTICE ...) dumps for MIMALLOC_LIB. The diagnostic run (https://github.com/flet-dev/flet/actions/runs/24813135717) confirmed the undefined-symbol failure.

Test plan

  • CI passes on Ubuntu 20.04 AMD64.
  • CI passes on all other Linux matrix entries (Debian 10/12, Ubuntu 22.04/24.04, both AMD64 + ARM64).

Summary by Sourcery

Ensure Linux client binaries explicitly link pthread when mimalloc is enabled to fix linker failures on modern distributions.

Build:

  • Update Linux client CMake configuration to link Threads::Threads alongside mimalloc when MIMALLOC_LIB is present.
  • Update Python SDK Linux build template to mirror the explicit pthread linkage for mimalloc-enabled builds.

Flutter's build UI swallows the actual ld stderr, leaving only a bare
"clang: error: linker command failed with exit code 1" in CI logs.
Temporary instrumentation to reveal what's failing:

- flutter build linux --verbose to propagate cmake/ld output.
- message(NOTICE ...) to dump MIMALLOC_LIB value and existence check.
- LINKER:--verbose to emit ld's full invocation and error detail.

To be reverted once the root cause is pinned down.
The Linux client has been failing to link on every distro since mimalloc
was actually wired up (#6416): `mimalloc.o` references `pthread_setspecific`
but `ld --as-needed` (default on Ubuntu 20.04+) won't pull `libpthread` in
transitively through other DSOs, so the final link aborts with:

  undefined reference to symbol 'pthread_setspecific@@GLIBC_2.2.5'
  libpthread.so.0: error adding symbols: DSO missing from command line

Pair the mimalloc link with `Threads::Threads` so libpthread is explicitly
on the link line. Applied to both the client `CMakeLists.txt` and the
`flet build linux` build template so end users don't hit this.

Also revert the temporary diagnostic instrumentation added to surface the
real linker error.
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying flet-examples with  Cloudflare Pages  Cloudflare Pages

Latest commit: 84d6433
Status: ✅  Deploy successful!
Preview URL: https://df6fbe50.flet-examples.pages.dev
Branch Preview URL: https://diag-mimalloc-ld.flet-examples.pages.dev

View logs

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying flet-website-v2 with  Cloudflare Pages  Cloudflare Pages

Latest commit: 84d6433
Status:🚫  Build failed.

View logs

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

We've reviewed this pull request using the Sourcery rules engine

@FeodorFitsner FeodorFitsner merged commit 1c2e856 into release/v0.85.0 Apr 23, 2026
49 of 105 checks passed
@FeodorFitsner FeodorFitsner deleted the diag/mimalloc-ld branch April 23, 2026 14:10
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.

1 participant