Open
Description
I tried this code:
#![feature(thread_local)]
#[repr(align(256))]
struct HighAlignment(u8);
#[thread_local]
static EXAMPLE1: HighAlignment = const { HighAlignment(0) };
#[thread_local]
static EXAMPLE2: HighAlignment = const { HighAlignment(0) };
#[thread_local]
static EXAMPLE3: HighAlignment = const { HighAlignment(0) };
fn main() {
println!(
"{:?}, {:?}, {:?}",
&EXAMPLE1 as *const HighAlignment,
&EXAMPLE2 as *const HighAlignment,
&EXAMPLE3 as *const HighAlignment
);
}
I expected to see this happen: three 0x100
-aligned pointers.
Instead, this happened: metal pipe falling
- x86_64, GNU ABI, real Windows:
0x1f39e953850, 0x1f39e953950, 0x1f39e953a50
(unaligned) - x86_64, MSVC ABI, real Windows:
0x1c287893900, 0x1c287893a00, 0x1c287893b00
(aligned) - i686, GNU ABI, real Windows:
0xf9a5f8, 0xf9a6f8, 0xf9a7f8
(unaligned) - i686, MSVC ABI, real Windows:
0x6d2f00, 0x6d3000, 0x6d3100
(aligned) - x86_64, GNU ABI, Wine:
0x232c80, 0x232d80, 0x232e80
(unaligned) - x86_64, MSVC ABI, Wine:
0x1320e0, 0x1321e0, 0x1322e0
(unaligned) - i686, GNU ABI, Wine:
0x341f28, 0x342028, 0x342128
(unaligned) - i686, MSVC ABI, Wine:
0x34f010, 0x34f110, 0x34f210
(unaligned)
So either this affects all of Windows and I just got lucky twice, or this is two bugs in a trenchcoat, one affecting GNU ABI and another one in Wine. Not sure which.
Notably, checking mixed-alignment thread locals, like u8, u8, u128, u128, u128
, shows that the variables are correctly aligned with respect to each other within TLS, but the TLS base itself seems to be unaligned.
Tentatively marking as I-unsound
because of unaligned references bad, feel free to retag.
Meta
rustc --version --verbose
:
rustc 1.86.0-nightly (419b3e2d3 2025-01-15)
binary: rustc
commit-hash: 419b3e2d3e350822550eee0e82eeded4d324d584
commit-date: 2025-01-15
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.6
wine --version
: wine-9.22 (Staging)
Tracking issue for visibility: #29594
Metadata
Metadata
Assignees
Labels
Area: Thread local storage (TLS)Category: This is a bug.`#![feature(thread_local)]`Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessToolchain: GNU, Operating system: WindowsRelevant to the compiler team, which will review and decide on the PR/issue.This issue requires a nightly compiler in some way.