Skip to content

Commit

Permalink
Rollup merge of #53180 - cramertj:tls-align, r=alexcrichton
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cramertj authored Aug 8, 2018
2 parents 369642b + 877c469 commit f04b722
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 @@ -351,7 +351,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 @@ -361,6 +361,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 @@ -380,7 +384,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 f04b722

Please sign in to comment.