Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 11 pull requests #51930

Closed
wants to merge 36 commits into from
Closed
Changes from 2 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
30d825c
Fix doc links
MajorBreakfast Jun 27, 2018
64f8e3b
Update liblibc
est31 Jun 28, 2018
fb58db4
Require type is sized in wfcheck.check_item_type for externed DSTs, c…
krk Jun 28, 2018
cd8ca26
Point at lifetimes instead of def span for E0195
estebank Jun 27, 2018
5436a5c
Point to lifetime in fn definition on lifetime error note
estebank Jun 27, 2018
3005162
Extend support to `get_generics` for all `NodeItem`s
estebank Jun 27, 2018
03bcebb
Also point to free named region on lifetime errors
estebank Jun 28, 2018
9a9b747
review comments: unify duplicated code
estebank Jun 28, 2018
8449c5a
Fix rebase
estebank Jun 28, 2018
23d59d0
Suggest correct comparison against negative literal
estebank Jun 28, 2018
d6cf182
Fix inconsequential typo in GlobalAlloc doc example
Ixrec Jun 29, 2018
52b7eb9
Do not allow LLVM to increase a TLS's alignment on macOS.
kennytm Jun 27, 2018
0250302
Implement PartialEq between &str and OsString
GabrielMajeri May 29, 2018
fdcee4d
Fix stability attributes
GabrielMajeri May 30, 2018
fbd3c92
Add run-pass test
GabrielMajeri Jun 5, 2018
28c4813
use literal span for concrete type suggestion
euclio Jun 29, 2018
faaf250
improve the error message when `#[panic_implementation]` is missing
japaric Jun 29, 2018
ee52862
update another cfail test
japaric Jun 29, 2018
1328bde
resolve: Cleanup `resolve_crate_root`
petrochenkov Jun 24, 2018
09856c8
expansion: Give names to some fields of `SyntaxExtension`
petrochenkov Jun 24, 2018
99ecdb3
hygiene: Implement transparent marks
petrochenkov Jun 24, 2018
297109e
proc-macro: Use transparent marks for call-site hygiene
petrochenkov Jun 24, 2018
9f92fce
Fortify dummy span checking
petrochenkov Jun 24, 2018
b69d511
Restore the old behavior of `$crate` in nested `macro_rules`
petrochenkov Jun 29, 2018
84f1bc8
Address comments
petrochenkov Jun 29, 2018
12247fd
Rollup merge of #51178 - GabrielMajeri:os-str-compare, r=SimonSapin
Mark-Simulacrum Jun 30, 2018
d562bff
Rollup merge of #51762 - petrochenkov:oh-hi-mark, r=oli-obk
Mark-Simulacrum Jun 30, 2018
8c30769
Rollup merge of #51828 - kennytm:no-simd-swap-for-mac, r=alexcrichton
Mark-Simulacrum Jun 30, 2018
4b6d98d
Rollup merge of #51853 - MajorBreakfast:fix-doc-links, r=cramertj
Mark-Simulacrum Jun 30, 2018
b3f8989
Rollup merge of #51862 - estebank:lifetime-spans, r=nikomatsakis
Mark-Simulacrum Jun 30, 2018
bea664b
Rollup merge of #51864 - est31:libc_update, r=alexcrichton
Mark-Simulacrum Jun 30, 2018
de85644
Rollup merge of #51867 - krk:issue-36122, r=petrochenkov
Mark-Simulacrum Jun 30, 2018
2223cc8
Rollup merge of #51883 - estebank:placement-suggestion, r=varkor
Mark-Simulacrum Jun 30, 2018
cf957c8
Rollup merge of #51890 - Ixrec:patch-3, r=alexcrichton
Mark-Simulacrum Jun 30, 2018
b50a6ba
Rollup merge of #51920 - euclio:concrete-type-suggestion, r=estebank
Mark-Simulacrum Jun 30, 2018
b7bd4aa
Rollup merge of #51921 - japaric:panic-impl-error, r=nagisa
Mark-Simulacrum Jun 30, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion src/librustc_codegen_llvm/consts.rs
Original file line number Diff line number Diff line change
@@ -250,7 +250,7 @@ pub fn codegen_static<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
unsafe {
let g = get_static(cx, def_id);

let v = match ::mir::codegen_static_initializer(cx, def_id) {
let (v, alloc) = match ::mir::codegen_static_initializer(cx, def_id) {
Ok(v) => v,
// Error has already been reported
Err(_) => return,
@@ -309,6 +309,44 @@ pub fn codegen_static<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,

if attr::contains_name(attrs, "thread_local") {
llvm::set_thread_local_mode(g, cx.tls_model);

// Do not allow LLVM to change the alignment of a TLS on macOS.
//
// By default a global's alignment can be freely increased.
// This allows LLVM to generate more performant instructions
// e.g. using load-aligned into a SIMD register.
//
// However, on macOS 10.10 or below, the dynamic linker does not
// respect any alignment given on the TLS (radar 24221680).
// This will violate the alignment assumption, and causing segfault at runtime.
//
// 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.
// The implementation of `mem::replace` will use SIMD
// whenever the size is 32 bytes or higher. LLVM notices SIMD is used
// and tries to align `LOCAL_STDOUT`/`LOCAL_STDERR` to a 32-byte boundary,
// which macOS's dyld disregarded and causing crashes
// (see issues #51794, #51758, #50867, #48866 and #44056).
//
// To workaround the bug, we trick LLVM into not increasing
// the global's alignment by explicitly assigning a section to it
// (equivalent to automatically generating a `#[link_section]` attribute).
// See the comment in the `GlobalValue::canIncreaseAlignment()` function
// of `lib/IR/Globals.cpp` for why this works.
//
// When the alignment is not increased, the optimized `mem::replace`
// 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 {
let sect_name = if alloc.bytes.iter().all(|b| *b == 0) {
CStr::from_bytes_with_nul_unchecked(b"__DATA,__thread_bss\0")
} else {
CStr::from_bytes_with_nul_unchecked(b"__DATA,__thread_data\0")
};
llvm::LLVMSetSection(g, sect_name.as_ptr());
}
}

base::set_link_section(cx, g, attrs);
4 changes: 2 additions & 2 deletions src/librustc_codegen_llvm/mir/constant.rs
Original file line number Diff line number Diff line change
@@ -118,7 +118,7 @@ pub fn const_alloc_to_llvm(cx: &CodegenCx, alloc: &Allocation) -> ValueRef {
pub fn codegen_static_initializer<'a, 'tcx>(
cx: &CodegenCx<'a, 'tcx>,
def_id: DefId)
-> Result<ValueRef, Lrc<ConstEvalErr<'tcx>>>
-> Result<(ValueRef, &'tcx Allocation), Lrc<ConstEvalErr<'tcx>>>
{
let instance = ty::Instance::mono(cx.tcx, def_id);
let cid = GlobalId {
@@ -132,7 +132,7 @@ pub fn codegen_static_initializer<'a, 'tcx>(
ConstValue::ByRef(alloc, n) if n.bytes() == 0 => alloc,
_ => bug!("static const eval returned {:#?}", static_),
};
Ok(const_alloc_to_llvm(cx, alloc))
Ok((const_alloc_to_llvm(cx, alloc), alloc))
}

impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
40 changes: 40 additions & 0 deletions src/test/codegen/issue-44056-macos-tls-align.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-tidy-linelength
// only-macos
// no-system-llvm
// min-llvm-version 6.0
// compile-flags: -O

#![crate_type = "rlib"]
#![feature(thread_local)]

// CHECK: @STATIC_VAR_1 = internal thread_local unnamed_addr global <{ [32 x i8] }> zeroinitializer, section "__DATA,__thread_bss", align 8
#[no_mangle]
#[allow(private_no_mangle_statics)]
#[thread_local]
static mut STATIC_VAR_1: [u64; 4] = [0; 4];

// CHECK: @STATIC_VAR_2 = internal thread_local unnamed_addr global <{ [32 x i8] }> <{{[^>]*}}>, section "__DATA,__thread_data", align 8
#[no_mangle]
#[allow(private_no_mangle_statics)]
#[thread_local]
static mut STATIC_VAR_2: [u64; 4] = [4; 4];

#[no_mangle]
pub unsafe fn f(x: &mut [u64; 4]) {
std::mem::swap(x, &mut STATIC_VAR_1)
}

#[no_mangle]
pub unsafe fn g(x: &mut [u64; 4]) {
std::mem::swap(x, &mut STATIC_VAR_2)
}
15 changes: 15 additions & 0 deletions src/test/run-pass/issue-44056.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// only-x86_64
// no-prefer-dynamic
// compile-flags: -Ctarget-feature=+avx -Clto

fn main() {}