Skip to content

Commit

Permalink
Avoid increased alignment of TLS segments on Fuchsia
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cramertj committed Aug 8, 2018
1 parent 4b8089d commit 877c469
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/librustc_codegen_llvm/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ pub fn codegen_static<'a, 'tcx>(
if attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL) {
llvm::set_thread_local_mode(g, cx.tls_model);

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

0 comments on commit 877c469

Please sign in to comment.