Skip to content

Commit 8d49a53

Browse files
authored
Rollup merge of rust-lang#53180 - cramertj:tls-align, r=alexcrichton
Avoid increased alignment of TLS segments on Fuchsia This is a temporary workaround for Fuchsia's libc not supporting TLS segments with alignments greater than 32 bytes. It should be reverted ASAP following the fix to libc. cc @petrhosek r? @alexcrichton
2 parents 5cebf8c + 877c469 commit 8d49a53

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/librustc_codegen_llvm/consts.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ pub fn codegen_static<'a, 'tcx>(
351351
if attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL) {
352352
llvm::set_thread_local_mode(g, cx.tls_model);
353353

354-
// Do not allow LLVM to change the alignment of a TLS on macOS.
354+
// Do not allow LLVM to change the alignment of a TLS on macOS and Fuchsia.
355355
//
356356
// By default a global's alignment can be freely increased.
357357
// This allows LLVM to generate more performant instructions
@@ -361,6 +361,10 @@ pub fn codegen_static<'a, 'tcx>(
361361
// respect any alignment given on the TLS (radar 24221680).
362362
// This will violate the alignment assumption, and causing segfault at runtime.
363363
//
364+
// Fuchsia's libc currently does not support greater than 16-byte alignment
365+
// of TLS segments, so this hack is also enabled temporarily for Fuchsia targets
366+
// until libc is fixed.
367+
//
364368
// This bug is very easy to trigger. In `println!` and `panic!`,
365369
// the `LOCAL_STDOUT`/`LOCAL_STDERR` handles are stored in a TLS,
366370
// which the values would be `mem::replace`d on initialization.
@@ -380,7 +384,9 @@ pub fn codegen_static<'a, 'tcx>(
380384
// will use load-unaligned instructions instead, and thus avoiding the crash.
381385
//
382386
// We could remove this hack whenever we decide to drop macOS 10.10 support.
383-
if cx.tcx.sess.target.target.options.is_like_osx {
387+
if cx.tcx.sess.target.target.options.is_like_osx ||
388+
(cx.tcx.sess.target.target.target_os == "fuchsia")
389+
{
384390
let sect_name = if alloc.bytes.iter().all(|b| *b == 0) {
385391
CStr::from_bytes_with_nul_unchecked(b"__DATA,__thread_bss\0")
386392
} else {

0 commit comments

Comments
 (0)