Avoid weak-linking gettid on musl - #160114
Open
windsornguyen wants to merge 1 commit into
Open
Conversation
`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.
Collaborator
|
|
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 (
|
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mitigates #154439.
Summary
current_os_idweak-linksgettidso older glibc can fall back to a raw syscall. Rust-supported musl versions providegettid, so musl does not need that probe.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.ofromlibc.a, leaving the strong call without a definition.This calls
gettiddirectly on musl. It follows the musl-specific branch suggested by @tgross35 in #154439. @bjorn3 traced the underlying compiler problem to fat LTO using LLVM’s legacyModuleLinker; changing that compiler-level behavior is intentionally out of scope here, so the issue should remain open.Test
The new run-pass test builds a strong
gettiddeclaration in an auxiliary rlib that sorts afterstd, links it statically under fat LTO, and verifies that the main thread ID equals the process ID. It exits with SIGSEGV against the unpatched x86_64 musl standard library and passes with this change. The value assertion also catches targets where the bad call returns an incorrect thread ID instead of trapping.Validated with:
x86_64-unknown-linux-muslx.py fmt --checkx.py test tidyr? @tgross35