Skip to content

Commit 1729652

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 26511ef + 877c469 commit 1729652

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
@@ -364,7 +364,7 @@ pub fn codegen_static<'a, 'tcx>(
364364
if attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL) {
365365
llvm::set_thread_local_mode(g, cx.tls_model);
366366

367-
// Do not allow LLVM to change the alignment of a TLS on macOS.
367+
// Do not allow LLVM to change the alignment of a TLS on macOS and Fuchsia.
368368
//
369369
// By default a global's alignment can be freely increased.
370370
// This allows LLVM to generate more performant instructions
@@ -374,6 +374,10 @@ pub fn codegen_static<'a, 'tcx>(
374374
// respect any alignment given on the TLS (radar 24221680).
375375
// This will violate the alignment assumption, and causing segfault at runtime.
376376
//
377+
// Fuchsia's libc currently does not support greater than 16-byte alignment
378+
// of TLS segments, so this hack is also enabled temporarily for Fuchsia targets
379+
// until libc is fixed.
380+
//
377381
// This bug is very easy to trigger. In `println!` and `panic!`,
378382
// the `LOCAL_STDOUT`/`LOCAL_STDERR` handles are stored in a TLS,
379383
// which the values would be `mem::replace`d on initialization.
@@ -393,7 +397,9 @@ pub fn codegen_static<'a, 'tcx>(
393397
// will use load-unaligned instructions instead, and thus avoiding the crash.
394398
//
395399
// We could remove this hack whenever we decide to drop macOS 10.10 support.
396-
if cx.tcx.sess.target.target.options.is_like_osx {
400+
if cx.tcx.sess.target.target.options.is_like_osx ||
401+
(cx.tcx.sess.target.target.target_os == "fuchsia")
402+
{
397403
let sect_name = if alloc.bytes.iter().all(|b| *b == 0) {
398404
CStr::from_bytes_with_nul_unchecked(b"__DATA,__thread_bss\0")
399405
} else {

0 commit comments

Comments
 (0)