Skip to content

Commit 4dbe966

Browse files
authored
Rollup merge of #92042 - ChrisDenton:msvc-static-tls, r=nagisa
Enable `#[thread_local]` for all windows-msvc targets As it stands, `#[thread_local]` is enabled haphazardly for msvc. It seems all 64-bit targets have it enabled, but not 32-bit targets unless they're also UWP targets (perhaps because UWP was added more recently?). So this PR simply enables it for 32-bit targets as well. I can't think of a reason not to and I've confirmed by running tests locally which pass. See also #91659
2 parents a2db900 + 391332c commit 4dbe966

21 files changed

+21
-27
lines changed

Diff for: compiler/rustc_session/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ fn default_configuration(sess: &Session) -> CrateConfig {
880880
ret.insert((sym::target_env, Some(Symbol::intern(env))));
881881
ret.insert((sym::target_abi, Some(Symbol::intern(abi))));
882882
ret.insert((sym::target_vendor, Some(Symbol::intern(vendor))));
883-
if sess.target.has_elf_tls {
883+
if sess.target.has_thread_local {
884884
ret.insert((sym::target_thread_local, None));
885885
}
886886
for (i, align) in [

Diff for: compiler/rustc_target/src/spec/aarch64_pc_windows_msvc.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::spec::Target;
33
pub fn target() -> Target {
44
let mut base = super::windows_msvc_base::opts();
55
base.max_atomic_width = Some(64);
6-
base.has_elf_tls = true;
76
base.features = "+neon,+fp-armv8".to_string();
87

98
Target {

Diff for: compiler/rustc_target/src/spec/aarch64_uwp_windows_msvc.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::spec::Target;
33
pub fn target() -> Target {
44
let mut base = super::windows_uwp_msvc_base::opts();
55
base.max_atomic_width = Some(64);
6-
base.has_elf_tls = true;
76

87
Target {
98
llvm_target: "aarch64-pc-windows-msvc".to_string(),

Diff for: compiler/rustc_target/src/spec/android_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub fn opts() -> TargetOptions {
1111
.push("-Wl,--allow-multiple-definition".to_string());
1212
base.dwarf_version = Some(2);
1313
base.position_independent_executables = true;
14-
base.has_elf_tls = false;
14+
base.has_thread_local = false;
1515
// This is for backward compatibility, see https://github.com/rust-lang/rust/issues/49867
1616
// for context. (At that time, there was no `-C force-unwind-tables`, so the only solution
1717
// was to always emit `uwtable`).

Diff for: compiler/rustc_target/src/spec/apple_base.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn opts(os: &str) -> TargetOptions {
1616
// TLS is flagged as enabled if it looks to be supported. The architecture
1717
// only matters for default deployment target which is 11.0 for ARM64 and
1818
// 10.7 for everything else.
19-
let has_elf_tls = macos_deployment_target("x86_64") >= (10, 7);
19+
let has_thread_local = macos_deployment_target("x86_64") >= (10, 7);
2020

2121
TargetOptions {
2222
os: os.to_string(),
@@ -33,7 +33,7 @@ pub fn opts(os: &str) -> TargetOptions {
3333
has_rpath: true,
3434
dll_suffix: ".dylib".to_string(),
3535
archive_format: "darwin".to_string(),
36-
has_elf_tls,
36+
has_thread_local,
3737
abi_return_struct_as_int: true,
3838
emit_debug_gdb_scripts: false,
3939
eh_frame_header: false,

Diff for: compiler/rustc_target/src/spec/apple_sdk_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn opts(os: &str, arch: Arch) -> TargetOptions {
5353
dynamic_linking: false,
5454
executables: true,
5555
link_env_remove: link_env_remove(arch),
56-
has_elf_tls: false,
56+
has_thread_local: false,
5757
..super::apple_base::opts(os)
5858
}
5959
}

Diff for: compiler/rustc_target/src/spec/fuchsia_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn opts() -> TargetOptions {
3535
(LinkOutputKind::StaticPicExe, &["Scrt1.o"]),
3636
]),
3737
position_independent_executables: true,
38-
has_elf_tls: true,
38+
has_thread_local: true,
3939
..Default::default()
4040
}
4141
}

Diff for: compiler/rustc_target/src/spec/hermit_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub fn opts() -> TargetOptions {
1212
linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
1313
linker: Some("rust-lld".to_owned()),
1414
executables: true,
15-
has_elf_tls: true,
15+
has_thread_local: true,
1616
pre_link_args,
1717
panic_strategy: PanicStrategy::Abort,
1818
position_independent_executables: true,

Diff for: compiler/rustc_target/src/spec/i686_uwp_windows_msvc.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ pub fn target() -> Target {
44
let mut base = super::windows_uwp_msvc_base::opts();
55
base.cpu = "pentium4".to_string();
66
base.max_atomic_width = Some(64);
7-
base.has_elf_tls = true;
87

98
Target {
109
llvm_target: "i686-pc-windows-msvc".to_string(),

Diff for: compiler/rustc_target/src/spec/illumos_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub fn opts() -> TargetOptions {
4545
// (see src/libstd/sys/unix/fast_thread_local.rs) that is currently
4646
// missing in illumos. For now at least, we must fallback to using
4747
// pthread_{get,set}specific.
48-
//has_elf_tls: true,
48+
//has_thread_local: true,
4949

5050
// FIXME: Currently, rust is invoking cc to link, which ends up
5151
// causing these to get included twice. We should eventually transition

Diff for: compiler/rustc_target/src/spec/linux_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub fn opts() -> TargetOptions {
99
has_rpath: true,
1010
position_independent_executables: true,
1111
relro_level: RelroLevel::Full,
12-
has_elf_tls: true,
12+
has_thread_local: true,
1313
crt_static_respected: true,
1414
..Default::default()
1515
}

Diff for: compiler/rustc_target/src/spec/mod.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1279,9 +1279,8 @@ pub struct TargetOptions {
12791279
/// `argc` and `argv` values.
12801280
pub main_needs_argc_argv: bool,
12811281

1282-
/// Flag indicating whether ELF TLS (e.g., #[thread_local]) is available for
1283-
/// this target.
1284-
pub has_elf_tls: bool,
1282+
/// Flag indicating whether #[thread_local] is available for this target.
1283+
pub has_thread_local: bool,
12851284
// This is mainly for easy compatibility with emscripten.
12861285
// If we give emcc .o files that are actually .bc files it
12871286
// will 'just work'.
@@ -1487,7 +1486,7 @@ impl Default for TargetOptions {
14871486
archive_format: "gnu".to_string(),
14881487
main_needs_argc_argv: true,
14891488
allow_asm: true,
1490-
has_elf_tls: false,
1489+
has_thread_local: false,
14911490
obj_is_bitcode: false,
14921491
forces_embed_bitcode: false,
14931492
bitcode_llvm_cmdline: String::new(),
@@ -2074,7 +2073,7 @@ impl Target {
20742073
key!(archive_format);
20752074
key!(allow_asm, bool);
20762075
key!(main_needs_argc_argv, bool);
2077-
key!(has_elf_tls, bool);
2076+
key!(has_thread_local, bool);
20782077
key!(obj_is_bitcode, bool);
20792078
key!(forces_embed_bitcode, bool);
20802079
key!(bitcode_llvm_cmdline);
@@ -2315,7 +2314,7 @@ impl ToJson for Target {
23152314
target_option_val!(archive_format);
23162315
target_option_val!(allow_asm);
23172316
target_option_val!(main_needs_argc_argv);
2318-
target_option_val!(has_elf_tls);
2317+
target_option_val!(has_thread_local);
23192318
target_option_val!(obj_is_bitcode);
23202319
target_option_val!(forces_embed_bitcode);
23212320
target_option_val!(bitcode_llvm_cmdline);

Diff for: compiler/rustc_target/src/spec/redox_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub fn opts() -> TargetOptions {
1010
has_rpath: true,
1111
position_independent_executables: true,
1212
relro_level: RelroLevel::Full,
13-
has_elf_tls: true,
13+
has_thread_local: true,
1414
crt_static_default: true,
1515
crt_static_respected: true,
1616
..Default::default()

Diff for: compiler/rustc_target/src/spec/solid_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub fn opts(kernel: &str) -> TargetOptions {
66
os: format!("solid_{}", kernel),
77
vendor: "kmc".to_string(),
88
frame_pointer: FramePointer::NonLeaf,
9-
has_elf_tls: true,
9+
has_thread_local: true,
1010
..Default::default()
1111
}
1212
}

Diff for: compiler/rustc_target/src/spec/thumbv7a_uwp_windows_msvc.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ pub fn target() -> Target {
99
options: TargetOptions {
1010
features: "+vfp3,+neon".to_string(),
1111
max_atomic_width: Some(64),
12-
has_elf_tls: true,
1312
// FIXME(jordanrh): use PanicStrategy::Unwind when SEH is
1413
// implemented for windows/arm in LLVM
1514
panic_strategy: PanicStrategy::Abort,

Diff for: compiler/rustc_target/src/spec/vxworks_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub fn opts() -> TargetOptions {
1111
executables: true,
1212
families: vec!["unix".to_string()],
1313
has_rpath: true,
14-
has_elf_tls: true,
14+
has_thread_local: true,
1515
crt_static_default: true,
1616
crt_static_respected: true,
1717
crt_static_allows_dylibs: true,

Diff for: compiler/rustc_target/src/spec/wasm_base.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ pub fn options() -> TargetOptions {
120120
// When the atomics feature is activated then these two keys matter,
121121
// otherwise they're basically ignored by the standard library. In this
122122
// mode, however, the `#[thread_local]` attribute works (i.e.
123-
// `has_elf_tls`) and we need to get it to work by specifying
123+
// `has_thread_local`) and we need to get it to work by specifying
124124
// `local-exec` as that's all that's implemented in LLVM today for wasm.
125-
has_elf_tls: true,
125+
has_thread_local: true,
126126
tls_model: TlsModel::LocalExec,
127127

128128
// gdb scripts don't work on wasm blobs

Diff for: compiler/rustc_target/src/spec/windows_msvc_base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub fn opts() -> TargetOptions {
2727
// linking some libraries which require a specific agreement, so it may
2828
// not ever be possible for us to pass this flag.
2929
no_default_libraries: false,
30+
has_thread_local: true,
3031

3132
..base
3233
}

Diff for: compiler/rustc_target/src/spec/x86_64_pc_windows_msvc.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ pub fn target() -> Target {
44
let mut base = super::windows_msvc_base::opts();
55
base.cpu = "x86-64".to_string();
66
base.max_atomic_width = Some(64);
7-
base.has_elf_tls = true;
87

98
Target {
109
llvm_target: "x86_64-pc-windows-msvc".to_string(),

Diff for: compiler/rustc_target/src/spec/x86_64_unknown_linux_gnux32.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub fn target() -> Target {
88
base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-mx32".to_string());
99
// don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved
1010
base.stack_probes = StackProbeType::Call;
11-
base.has_elf_tls = false;
11+
base.has_thread_local = false;
1212
// BUG(GabrielMajeri): disabling the PLT on x86_64 Linux with x32 ABI
1313
// breaks code gen. See LLVM bug 36743
1414
base.needs_plt = true;

Diff for: compiler/rustc_target/src/spec/x86_64_uwp_windows_msvc.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ pub fn target() -> Target {
44
let mut base = super::windows_uwp_msvc_base::opts();
55
base.cpu = "x86-64".to_string();
66
base.max_atomic_width = Some(64);
7-
base.has_elf_tls = true;
87

98
Target {
109
llvm_target: "x86_64-pc-windows-msvc".to_string(),

0 commit comments

Comments
 (0)