Skip to content

Commit 80690b0

Browse files
authored
Rollup merge of #70720 - ecstatic-morse:issue-70637, r=oli-obk
Place TLS initializers with relocations in .tdata Should fix #70673, although I'm not sure how to test this. Perhaps @joshlf could find a MCVE? Also adds more context to the FIXME. r? @oli-obk
2 parents aa42d12 + f030635 commit 80690b0

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

src/librustc_codegen_llvm/consts.rs

+13-16
Original file line numberDiff line numberDiff line change
@@ -436,24 +436,21 @@ impl StaticMethods for CodegenCx<'ll, 'tcx> {
436436
//
437437
// We could remove this hack whenever we decide to drop macOS 10.10 support.
438438
if self.tcx.sess.target.target.options.is_like_osx {
439-
assert_eq!(alloc.relocations().len(), 0);
440-
441-
let is_zeroed = {
442-
// Treats undefined bytes as if they were defined with the byte value that
443-
// happens to be currently assigned in mir. This is valid since reading
444-
// undef bytes may yield arbitrary values.
445-
//
446-
// FIXME: ignore undef bytes even with representation `!= 0`.
447-
//
448-
// The `inspect` method is okay here because we checked relocations, and
449-
// because we are doing this access to inspect the final interpreter state
450-
// (not as part of the interpreter execution).
451-
alloc
439+
// The `inspect` method is okay here because we checked relocations, and
440+
// because we are doing this access to inspect the final interpreter state
441+
// (not as part of the interpreter execution).
442+
//
443+
// FIXME: This check requires that the (arbitrary) value of undefined bytes
444+
// happens to be zero. Instead, we should only check the value of defined bytes
445+
// and set all undefined bytes to zero if this allocation is headed for the
446+
// BSS.
447+
let all_bytes_are_zero = alloc.relocations().is_empty()
448+
&& alloc
452449
.inspect_with_undef_and_ptr_outside_interpreter(0..alloc.len())
453450
.iter()
454-
.all(|b| *b == 0)
455-
};
456-
let sect_name = if is_zeroed {
451+
.all(|&byte| byte == 0);
452+
453+
let sect_name = if all_bytes_are_zero {
457454
CStr::from_bytes_with_nul_unchecked(b"__DATA,__thread_bss\0")
458455
} else {
459456
CStr::from_bytes_with_nul_unchecked(b"__DATA,__thread_data\0")

src/test/ui/issues/issue-70673.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Regression test for https://github.com/rust-lang/rust/issues/70673.
2+
3+
// run-pass
4+
5+
#![feature(thread_local)]
6+
7+
#[thread_local]
8+
static A: &u8 = &42;
9+
10+
fn main() {
11+
dbg!(*A);
12+
}

0 commit comments

Comments
 (0)