-
Notifications
You must be signed in to change notification settings - Fork 13.4k
fix pthread-based tls on apple targets #137897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#![feature(cfg_target_thread_local)] | ||
|
||
#[cfg(not(any(target_os = "emscripten", target_os = "wasi")))] | ||
mod tests; | ||
|
||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//! Test if compilation with has-thread-local=false works, and if the output | ||
//! has indeed no fast TLS variables. | ||
|
||
//@ only-apple | ||
|
||
use run_make_support::serde_json::{self, Value}; | ||
use run_make_support::{cargo, llvm_nm, rfs, rustc}; | ||
|
||
fn main() { | ||
let output = | ||
rustc().print("target-spec-json").args(["-Z", "unstable-options"]).run().stdout_utf8(); | ||
|
||
let mut target_json: Value = serde_json::from_str(&output).unwrap(); | ||
let has_thread_local = &mut target_json["has-thread-local"]; | ||
assert!(matches!(has_thread_local, Value::Bool(true)), "{:?}", has_thread_local); | ||
*has_thread_local = Value::Bool(false); | ||
|
||
let out_path = "t.json"; | ||
rfs::write(out_path, serde_json::to_string(&target_json).unwrap()); | ||
|
||
cargo() | ||
.args([ | ||
"b", | ||
"--manifest-path", | ||
"tls_test/Cargo.toml", | ||
"--target", | ||
"t.json", | ||
"-Zbuild-std=std,core,panic_abort", | ||
]) | ||
.run(); | ||
|
||
// If a binary has any fast TLS variables, it should also contain the symbols | ||
// __tlv_bootstrap and __tlv_atexit. We don't want them. | ||
let output = llvm_nm().arg("tls_test/target/t/debug/tls_test").run().stdout_utf8(); | ||
assert!(!output.contains("_tlv_bootstrap")); | ||
assert!(!output.contains("_tlv_atexit")); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[package] | ||
name = "tls_test" | ||
version = "0.1.0" | ||
edition = "2024" | ||
|
||
[dependencies] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use std::cell::RefCell; | ||
|
||
fn main() { | ||
thread_local! { | ||
static S: RefCell<String> = RefCell::default(); | ||
} | ||
|
||
S.with(|x| *x.borrow_mut() = "pika pika".to_string()); | ||
S.with(|x| println!("{}", x.borrow())); | ||
} |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.