Skip to content

Avoid weak-linking gettid on musl - #160114

Open
windsornguyen wants to merge 3 commits into
rust-lang:mainfrom
windsornguyen:fix/musl-lto-weak-gettid
Open

Avoid weak-linking gettid on musl#160114
windsornguyen wants to merge 3 commits into
rust-lang:mainfrom
windsornguyen:fix/musl-lto-weak-gettid

Conversation

@windsornguyen

@windsornguyen windsornguyen commented Jul 29, 2026

Copy link
Copy Markdown

View all comments

Mitigates #154439.

Brief

current_os_id weak-links gettid so older glibc can fall back to a raw syscall.

Details

During fat LTO, LLVM can merge the weak declaration with a strong declaration from another crate and keep the weak linkage. A static linker then does not extract gettid.o from libc.a, leaving the strong call without a definition.

@bjorn3 traced the underlying compiler problem to fat LTO using LLVM’s legacy ModuleLinker. Changing that compiler-level behavior is intentionally out of scope here, so that issue should remain open.

Note that Rust-supported musl versions provide gettid, so musl does not need that probe.

This PR calls gettid directly on musl. It follows the musl-specific branch suggested by @tgross35 in #154439.

r? @tgross35

`current_os_id` uses an extern-weak `gettid` declaration so older glibc
can fall back to a raw syscall. Rust-supported musl versions provide
`gettid`, so musl does not need this probe.

During fat LTO, LLVM can merge the weak declaration with a strong
reference from another crate and keep the weak linkage. The static
linker then does not extract `gettid.o` from `libc.a`, leaving the
strong call without a definition.

Call `gettid` directly on musl and add a regression test for the
returned thread ID. This removes std's contribution to the collision;
the underlying LTO linkage bug remains.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 29, 2026
@rustbot

rustbot commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

tgross35 is currently at their maximum review capacity.
They may take a while to respond.

@rustbot

rustbot commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @tgross35 (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@windsornguyen

Copy link
Copy Markdown
Author

@bjorn3, since you identified the ModuleLinker root cause in #154439, would you be willing to give the LTO scope here a second look?

@tgross35

tgross35 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

@bors try jobs=test-various

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 4, 2026
Avoid weak-linking `gettid` on musl


try-job: test-various

@tgross35 tgross35 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Two small requests than r=me if the try job passes.

No need for the Test section in the PR description, we can pretty much see all of that from the test itself. (Please handwrite things like commit messages and PR descriptions)

View changes since this review

Comment thread tests/ui/linking/lto-weak-gettid-issue-154439.rs Outdated
Comment thread library/std/src/sys/thread/unix.rs
@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 4, 2026
@rust-bors

rust-bors Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

💔 Test for a5ba248 failed: CI. Failed job:

@tgross35

tgross35 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Looks like a download failure, @bors retry

@rust-bors

rust-bors Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

❗ You can only retry pull requests that are approved and have a previously failed auto build.

@tgross35

tgross35 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

@bors try jobs=test-various

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 4, 2026
Avoid weak-linking `gettid` on musl


try-job: test-various
@rust-bors

rust-bors Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

💔 Test for de974aa failed: CI. Failed job:

The regression test also works on glibc. Change its target gate from musl to Linux so both libc environments exercise it.

Signed-off-by: windsornguyen <win@dedaluslabs.ai>
Comments outside cfg_select arms describe multiple targets. Move the musl-specific explanation into its arm so it cannot be read as applying to the neighboring Linux/Android path.

Signed-off-by: windsornguyen <win@dedaluslabs.ai>
@tgross35

tgross35 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

If this fails again, will hold off for a while longer

@bors try jobs=test-various

Please squash as well

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 4, 2026
Avoid weak-linking `gettid` on musl


try-job: test-various
@rust-bors

rust-bors Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

💔 Test for 1868143 failed: CI. Failed job:

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

A job failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
#15 134.2 gcc-9.4.0.tar.xz: OK
#15 134.2 mv sources/gcc-9.4.0.tar.xz.tmp/gcc-9.4.0.tar.xz sources/gcc-9.4.0.tar.xz
#15 134.2 rm -rf sources/gcc-9.4.0.tar.xz.tmp
#15 134.2 failed: Connection timed out.
#15 134.2 Connecting to musl.libc.org (musl.libc.org)|2001:19f0:4009:4061:5400:ff:fe11:6da2|:443... failed: Network is unreachable.
#15 134.2 make: *** [Makefile:87: sources/musl-1.2.5.tar.gz] Error 4
#15 ERROR: process "/bin/sh -c bash musl-toolchain.sh x86_64 && rm -rf build" did not complete successfully: exit code: 1
------
 > [ 9/14] RUN bash musl-toolchain.sh x86_64 && rm -rf build:
134.2 2026-08-04 10:05:52 (33.0 MB/s) - 'gcc-9.4.0.tar.xz' saved [72411232/72411232]
134.2 
134.2 cd sources/gcc-9.4.0.tar.xz.tmp && touch gcc-9.4.0.tar.xz
134.2 cd sources/gcc-9.4.0.tar.xz.tmp && sha1sum -c /build/musl-cross-make/hashes/gcc-9.4.0.tar.xz.sha1
134.2 gcc-9.4.0.tar.xz: OK
134.2 mv sources/gcc-9.4.0.tar.xz.tmp/gcc-9.4.0.tar.xz sources/gcc-9.4.0.tar.xz
134.2 rm -rf sources/gcc-9.4.0.tar.xz.tmp
134.2 failed: Connection timed out.
134.2 Connecting to musl.libc.org (musl.libc.org)|2001:19f0:4009:4061:5400:ff:fe11:6da2|:443... failed: Network is unreachable.
134.2 make: *** [Makefile:87: sources/musl-1.2.5.tar.gz] Error 4
------
Dockerfile:40
--------------------
  38 |     COPY scripts/musl-cve-2026-6042.diff /build/
  39 |     COPY scripts/musl-cve-2026-40200.diff /build/

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job x86_64-gnu-next-trait-solver-polonius failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
test [ui] tests/ui/lint/must_not_suspend/allocator.rs ... ok
test [ui] tests/ui/lint/must_not_suspend/boxed.rs ... ok
test [ui] tests/ui/lint/must_not_suspend/feature-gate-must_not_suspend.rs ... ok
test [ui] tests/ui/lint/must_not_suspend/dedup.rs ... ok
test [ui] tests/ui/linking/lto-weak-gettid-issue-154439.rs ... FAILED
test [ui] tests/ui/lint/must_not_suspend/gated.rs ... ok
test [ui] tests/ui/lint/must_not_suspend/generic.rs ... ok
test [ui] tests/ui/lint/must_not_suspend/mutex.rs ... ok
test [ui] tests/ui/lint/must_not_suspend/handled.rs ... ok
test [ui] tests/ui/lint/must_not_suspend/other_items.rs ... ok
---
test [ui] tests/ui/zero-sized/zero-sized-btreemap-insert.rs ... ok

failures:

---- [ui] tests/ui/linking/lto-weak-gettid-issue-154439.rs stdout ----

error: test did not exit with success! code=None so test would pass with `run-crash`
status: signal: 11 (SIGSEGV) (core dumped)
command: cd "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/linking/lto-weak-gettid-issue-154439" && RUSTC="/checkout/obj/build/x86_64-unknown-linux-gnu/stage1/bin/rustc" RUST_TEST_THREADS="4" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/linking/lto-weak-gettid-issue-154439/a"
stdout: none
stderr: none

---- [ui] tests/ui/linking/lto-weak-gettid-issue-154439.rs stdout end ----

failures:
    [ui] tests/ui/linking/lto-weak-gettid-issue-154439.rs

test result: FAILED. 21648 passed; 1 failed; 238 ignored; 0 measured; 0 filtered out; finished in 608.55s

Some tests failed in compiletest suite=ui mode=ui host=x86_64-unknown-linux-gnu target=x86_64-unknown-linux-gnu
Bootstrap failed while executing `test tests/ui --compare-mode polonius --stage 1`

Important

For more information how to resolve CI failures of this job, visit this link.

@windsornguyen

Copy link
Copy Markdown
Author

It looks like the glibc path still weak-links gettid. Investigating.

@tgross35

tgross35 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Huh - I wasn't able to reproduce the failure locally with glibc before. Wonder why it shows up here

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

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants