From c93000a76498d0baf51752de713f03d2dcb0c52d Mon Sep 17 00:00:00 2001 From: Andy Russell Date: Mon, 2 Jul 2018 13:47:51 -0400 Subject: [PATCH 1/5] add entry for cargo-metadata feature to RELEASES --- RELEASES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RELEASES.md b/RELEASES.md index fba68ce043e26..9d922f493d08b 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -65,6 +65,7 @@ Cargo ----- - [`cargo-metadata` now includes `authors`, `categories`, `keywords`, `readme`, and `repository` fields.][cargo/5386] +- [`cargo-metadata` now includes a package's `metadata` table.][cargo/5360] - [Added the `--target-dir` optional argument.][cargo/5393] This allows you to specify a different directory than `target` for placing compilation artifacts. - [Cargo will be adding automatic target inference for binaries, benchmarks, @@ -114,6 +115,7 @@ Compatibility Notes [cargo/5203]: https://github.com/rust-lang/cargo/pull/5203/ [cargo/5335]: https://github.com/rust-lang/cargo/pull/5335/ [cargo/5359]: https://github.com/rust-lang/cargo/pull/5359/ +[cargo/5360]: https://github.com/rust-lang/cargo/pull/5360/ [cargo/5386]: https://github.com/rust-lang/cargo/pull/5386/ [cargo/5393]: https://github.com/rust-lang/cargo/pull/5393/ [`DoubleEndedIterator::rfind`]: https://doc.rust-lang.org/std/iter/trait.DoubleEndedIterator.html#method.rfind From 4ab383767ffb28288ceae33cfab89e0858a619ff Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 16 Jun 2018 14:14:18 +0200 Subject: [PATCH 2/5] Fix macro missing from doc search --- src/librustdoc/html/static/main.js | 5 ++++- src/test/rustdoc-js/macro-check.js | 20 ++++++++++++++++++++ src/tools/rustdoc-js/tester.js | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/test/rustdoc-js/macro-check.js diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index bb996e00d352a..d0db6806c82f3 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -160,6 +160,7 @@ // used for special search precedence var TY_PRIMITIVE = itemTypes.indexOf("primitive"); var TY_KEYWORD = itemTypes.indexOf("keyword"); + var TY_MACRO = itemTypes.indexOf("macro"); onEach(document.getElementsByClassName('js-only'), function(e) { removeClass(e, 'js-only'); @@ -465,9 +466,11 @@ var res = buildHrefAndPath(obj); obj.displayPath = pathSplitter(res[0]); obj.fullPath = obj.displayPath + obj.name; + // To be sure than it some items aren't considered as duplicate. if (obj.ty === TY_KEYWORD) { - // To be sure than it isn't considered as duplicate with items. obj.fullPath += '|k'; + } else if (obj.ty === TY_MACRO) { + obj.fullPath += '|m'; } obj.href = res[1]; out.push(obj); diff --git a/src/test/rustdoc-js/macro-check.js b/src/test/rustdoc-js/macro-check.js new file mode 100644 index 0000000000000..fb6168843334e --- /dev/null +++ b/src/test/rustdoc-js/macro-check.js @@ -0,0 +1,20 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// ignore-order + +const QUERY = 'panic'; + +const EXPECTED = { + 'others': [ + { 'path': 'std', 'name': 'panic', ty: 14 }, // 15 is for macros + { 'path': 'std', 'name': 'panic', ty: 0 }, // 0 is for modules + ], +}; diff --git a/src/tools/rustdoc-js/tester.js b/src/tools/rustdoc-js/tester.js index 3c1fceaf8faa8..9567c46600482 100644 --- a/src/tools/rustdoc-js/tester.js +++ b/src/tools/rustdoc-js/tester.js @@ -233,7 +233,7 @@ function main(argv) { var arraysToLoad = ["itemTypes"]; var variablesToLoad = ["MAX_LEV_DISTANCE", "MAX_RESULTS", - "TY_PRIMITIVE", "TY_KEYWORD", + "TY_PRIMITIVE", "TY_KEYWORD", "TY_MACRO", "levenshtein_row2"]; // execQuery first parameter is built in getQuery (which takes in the search input). // execQuery last parameter is built in buildIndex. From 84457a477fbc9abb4c1a1f0d842a8a78e6d87eba Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 18 Jun 2018 21:39:46 +0200 Subject: [PATCH 3/5] Extend collision prevention to every type --- src/librustdoc/html/static/main.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index d0db6806c82f3..27fb6d1a2a29e 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -467,11 +467,7 @@ obj.displayPath = pathSplitter(res[0]); obj.fullPath = obj.displayPath + obj.name; // To be sure than it some items aren't considered as duplicate. - if (obj.ty === TY_KEYWORD) { - obj.fullPath += '|k'; - } else if (obj.ty === TY_MACRO) { - obj.fullPath += '|m'; - } + obj.fullPath += '|' + obj.ty; obj.href = res[1]; out.push(obj); if (out.length >= MAX_RESULTS) { From 84607c868b883fc8d7a9324542593dff77aa8b3c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 25 Jun 2018 21:47:44 +0200 Subject: [PATCH 4/5] Remove unused variable --- src/librustdoc/html/static/main.js | 1 - src/tools/rustdoc-js/tester.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 27fb6d1a2a29e..01eb1ce7407be 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -160,7 +160,6 @@ // used for special search precedence var TY_PRIMITIVE = itemTypes.indexOf("primitive"); var TY_KEYWORD = itemTypes.indexOf("keyword"); - var TY_MACRO = itemTypes.indexOf("macro"); onEach(document.getElementsByClassName('js-only'), function(e) { removeClass(e, 'js-only'); diff --git a/src/tools/rustdoc-js/tester.js b/src/tools/rustdoc-js/tester.js index 9567c46600482..3c1fceaf8faa8 100644 --- a/src/tools/rustdoc-js/tester.js +++ b/src/tools/rustdoc-js/tester.js @@ -233,7 +233,7 @@ function main(argv) { var arraysToLoad = ["itemTypes"]; var variablesToLoad = ["MAX_LEV_DISTANCE", "MAX_RESULTS", - "TY_PRIMITIVE", "TY_KEYWORD", "TY_MACRO", + "TY_PRIMITIVE", "TY_KEYWORD", "levenshtein_row2"]; // execQuery first parameter is built in getQuery (which takes in the search input). // execQuery last parameter is built in buildIndex. From 272e4f08437b875933941cccf0f341d52a85937f Mon Sep 17 00:00:00 2001 From: kennytm Date: Thu, 28 Jun 2018 06:24:09 +0800 Subject: [PATCH 5/5] Do not allow LLVM to increase a TLS's alignment on macOS. --- src/librustc_codegen_llvm/consts.rs | 40 ++++++++++++++++++- src/librustc_codegen_llvm/mir/constant.rs | 4 +- .../codegen/issue-44056-macos-tls-align.rs | 40 +++++++++++++++++++ src/test/run-pass/issue-44056.rs | 15 +++++++ 4 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 src/test/codegen/issue-44056-macos-tls-align.rs create mode 100644 src/test/run-pass/issue-44056.rs diff --git a/src/librustc_codegen_llvm/consts.rs b/src/librustc_codegen_llvm/consts.rs index afa81465ea2d1..199c40bb704ea 100644 --- a/src/librustc_codegen_llvm/consts.rs +++ b/src/librustc_codegen_llvm/consts.rs @@ -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); diff --git a/src/librustc_codegen_llvm/mir/constant.rs b/src/librustc_codegen_llvm/mir/constant.rs index 7c1035e2fcb88..a640a02ece2fc 100644 --- a/src/librustc_codegen_llvm/mir/constant.rs +++ b/src/librustc_codegen_llvm/mir/constant.rs @@ -117,7 +117,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> + -> Result<(ValueRef, &'tcx Allocation), ConstEvalErr<'tcx>> { let instance = ty::Instance::mono(cx.tcx, def_id); let cid = GlobalId { @@ -131,7 +131,7 @@ pub fn codegen_static_initializer<'a, 'tcx>( ConstVal::Value(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> { diff --git a/src/test/codegen/issue-44056-macos-tls-align.rs b/src/test/codegen/issue-44056-macos-tls-align.rs new file mode 100644 index 0000000000000..3235ef0bb3335 --- /dev/null +++ b/src/test/codegen/issue-44056-macos-tls-align.rs @@ -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 or the MIT license +// , 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 4 +#[no_mangle] +#[allow(private_no_mangle_statics)] +#[thread_local] +static mut STATIC_VAR_1: [u32; 8] = [0; 8]; + +// CHECK: @STATIC_VAR_2 = internal thread_local unnamed_addr global <{ [32 x i8] }> <{{[^>]*}}>, section "__DATA,__thread_data", align 4 +#[no_mangle] +#[allow(private_no_mangle_statics)] +#[thread_local] +static mut STATIC_VAR_2: [u32; 8] = [4; 8]; + +#[no_mangle] +pub unsafe fn f(x: &mut [u32; 8]) { + std::mem::swap(x, &mut STATIC_VAR_1) +} + +#[no_mangle] +pub unsafe fn g(x: &mut [u32; 8]) { + std::mem::swap(x, &mut STATIC_VAR_2) +} diff --git a/src/test/run-pass/issue-44056.rs b/src/test/run-pass/issue-44056.rs new file mode 100644 index 0000000000000..dcaa0bf86294a --- /dev/null +++ b/src/test/run-pass/issue-44056.rs @@ -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 or the MIT license +// , 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() {}