Skip to content

Commit 877c469

Browse files
committed
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.
1 parent 4b8089d commit 877c469

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

348-
// Do not allow LLVM to change the alignment of a TLS on macOS.
348+
// Do not allow LLVM to change the alignment of a TLS on macOS and Fuchsia.
349349
//
350350
// By default a global's alignment can be freely increased.
351351
// This allows LLVM to generate more performant instructions
@@ -355,6 +355,10 @@ pub fn codegen_static<'a, 'tcx>(
355355
// respect any alignment given on the TLS (radar 24221680).
356356
// This will violate the alignment assumption, and causing segfault at runtime.
357357
//
358+
// Fuchsia's libc currently does not support greater than 16-byte alignment
359+
// of TLS segments, so this hack is also enabled temporarily for Fuchsia targets
360+
// until libc is fixed.
361+
//
358362
// This bug is very easy to trigger. In `println!` and `panic!`,
359363
// the `LOCAL_STDOUT`/`LOCAL_STDERR` handles are stored in a TLS,
360364
// which the values would be `mem::replace`d on initialization.
@@ -374,7 +378,9 @@ pub fn codegen_static<'a, 'tcx>(
374378
// will use load-unaligned instructions instead, and thus avoiding the crash.
375379
//
376380
// We could remove this hack whenever we decide to drop macOS 10.10 support.
377-
if cx.tcx.sess.target.target.options.is_like_osx {
381+
if cx.tcx.sess.target.target.options.is_like_osx ||
382+
(cx.tcx.sess.target.target.target_os == "fuchsia")
383+
{
378384
let sect_name = if alloc.bytes.iter().all(|b| *b == 0) {
379385
CStr::from_bytes_with_nul_unchecked(b"__DATA,__thread_bss\0")
380386
} else {

0 commit comments

Comments
 (0)