diff options
| author | bors <bors@rust-lang.org> | 2017-07-06 02:34:29 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-07-06 02:34:29 +0000 |
| commit | 8cab2c73d47a4b0ec7dc1bf40eb59492139fb707 (patch) | |
| tree | 9c05341fbca4929e1963c8f98271edbebb326a20 /src/librustc_trans | |
| parent | 1685c9298685f73db4fe890c1ed27b22408aaad7 (diff) | |
| parent | 7e6c9f363501c49d3a1f666d85d41891f50890b8 (diff) | |
| download | rust-8cab2c73d47a4b0ec7dc1bf40eb59492139fb707.tar.gz rust-8cab2c73d47a4b0ec7dc1bf40eb59492139fb707.zip | |
Auto merge of #42899 - alexcrichton:compiler-builtins, r=nikomatsakis
Switch to rust-lang-nursery/compiler-builtins This commit migrates the in-tree `libcompiler_builtins` to the upstream version at https://github.com/rust-lang-nursery/compiler-builtins. The upstream version has a number of intrinsics written in Rust and serves as an in-progress rewrite of compiler-rt into Rust. Additionally it also contains all the existing intrinsics defined in `libcompiler_builtins` for 128-bit integers. It's been the intention since the beginning to make this transition but previously it just lacked the manpower to get done. As this PR likely shows it wasn't a trivial integration! Some highlight changes are: * The PR rust-lang-nursery/compiler-builtins#166 contains a number of fixes across platforms and also some refactorings to make the intrinsics easier to read. The additional testing added there also fixed a number of integration issues when pulling the repository into this tree. * LTO with the compiler-builtins crate was fixed to link in the entire crate after the LTO process as these intrinsics are excluded from LTO. * Treatment of hidden symbols was updated as previously the `#![compiler_builtins]` crate would mark all symbol *imports* as hidden whereas it was only intended to mark *exports* as hidden.
Diffstat (limited to 'src/librustc_trans')
| -rw-r--r-- | src/librustc_trans/attributes.rs | 2 | ||||
| -rw-r--r-- | src/librustc_trans/back/link.rs | 27 | ||||
| -rw-r--r-- | src/librustc_trans/back/write.rs | 3 | ||||
| -rw-r--r-- | src/librustc_trans/declare.rs | 11 | ||||
| -rw-r--r-- | src/librustc_trans/trans_item.rs | 12 |
5 files changed, 39 insertions, 16 deletions
diff --git a/src/librustc_trans/attributes.rs b/src/librustc_trans/attributes.rs index 6bef31ccf64..fa93c005dcd 100644 --- a/src/librustc_trans/attributes.rs +++ b/src/librustc_trans/attributes.rs @@ -13,7 +13,7 @@ use std::ffi::{CStr, CString}; use llvm::{self, Attribute, ValueRef}; use llvm::AttributePlace::Function; -pub use syntax::attr::InlineAttr; +pub use syntax::attr::{self, InlineAttr}; use syntax::ast; use context::CrateContext; diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs index 6f235ae5ee0..a4bbdef82f0 100644 --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -370,6 +370,24 @@ pub fn each_linked_rlib(sess: &Session, Ok(()) } +/// Returns a boolean indicating whether the specified crate should be ignored +/// during LTO. +/// +/// Crates ignored during LTO are not lumped together in the "massive object +/// file" that we create and are linked in their normal rlib states. See +/// comments below for what crates do not participate in LTO. +/// +/// It's unusual for a crate to not participate in LTO. Typically only +/// compiler-specific and unstable crates have a reason to not participate in +/// LTO. +pub fn ignored_for_lto(sess: &Session, cnum: CrateNum) -> bool { + // `#![no_builtins]` crates don't participate in LTO because the state + // of builtins gets messed up (our crate isn't tagged with no builtins). + // Similarly `#![compiler_builtins]` doesn't participate because we want + // those builtins! + sess.cstore.is_no_builtins(cnum) || sess.cstore.is_compiler_builtins(cnum) +} + fn out_filename(sess: &Session, crate_type: config::CrateType, outputs: &OutputFilenames, @@ -736,7 +754,10 @@ fn link_staticlib(sess: &Session, let skip_object_files = native_libs.iter().any(|lib| { lib.kind == NativeLibraryKind::NativeStatic && !relevant_lib(sess, lib) }); - ab.add_rlib(path, &name.as_str(), sess.lto(), skip_object_files).unwrap(); + ab.add_rlib(path, + &name.as_str(), + sess.lto() && !ignored_for_lto(sess, cnum), + skip_object_files).unwrap(); all_native_libs.extend(sess.cstore.native_libraries(cnum)); }); @@ -1289,7 +1310,9 @@ fn add_upstream_rust_crates(cmd: &mut Linker, lib.kind == NativeLibraryKind::NativeStatic && !relevant_lib(sess, lib) }); - if !sess.lto() && crate_type != config::CrateTypeDylib && !skip_native { + if (!sess.lto() || ignored_for_lto(sess, cnum)) && + crate_type != config::CrateTypeDylib && + !skip_native { cmd.link_rlib(&fix_windows_verbatim_for_gcc(cratepath)); return } diff --git a/src/librustc_trans/back/write.rs b/src/librustc_trans/back/write.rs index 0c233dfe109..5e227ec467a 100644 --- a/src/librustc_trans/back/write.rs +++ b/src/librustc_trans/back/write.rs @@ -1220,8 +1220,7 @@ fn spawn_work<'a>(sess: &'a Session, let crate_types = sess.crate_types.borrow().clone(); let mut each_linked_rlib_for_lto = Vec::new(); drop(link::each_linked_rlib(sess, &mut |cnum, path| { - // `#![no_builtins]` crates don't participate in LTO. - if sess.cstore.is_no_builtins(cnum) { + if link::ignored_for_lto(sess, cnum) { return } each_linked_rlib_for_lto.push((cnum, path.to_path_buf())); diff --git a/src/librustc_trans/declare.rs b/src/librustc_trans/declare.rs index 2787812f962..8f9146283ef 100644 --- a/src/librustc_trans/declare.rs +++ b/src/librustc_trans/declare.rs @@ -30,7 +30,6 @@ use context::CrateContext; use common; use type_::Type; use value::Value; -use syntax::attr; use std::ffi::CString; @@ -88,16 +87,6 @@ fn declare_raw_fn(ccx: &CrateContext, name: &str, callconv: llvm::CallConv, ty: } } - // If we're compiling the compiler-builtins crate, e.g. the equivalent of - // compiler-rt, then we want to implicitly compile everything with hidden - // visibility as we're going to link this object all over the place but - // don't want the symbols to get exported. - if attr::contains_name(ccx.tcx().hir.krate_attrs(), "compiler_builtins") { - unsafe { - llvm::LLVMRustSetVisibility(llfn, llvm::Visibility::Hidden); - } - } - match ccx.tcx().sess.opts.cg.opt_level.as_ref().map(String::as_ref) { Some("s") => { llvm::Attribute::OptimizeForSize.apply_llfn(Function, llfn); diff --git a/src/librustc_trans/trans_item.rs b/src/librustc_trans/trans_item.rs index 2a6e7c5ace6..200f6dee334 100644 --- a/src/librustc_trans/trans_item.rs +++ b/src/librustc_trans/trans_item.rs @@ -162,6 +162,18 @@ impl<'a, 'tcx> TransItem<'tcx> { llvm::SetUniqueComdat(ccx.llmod(), lldecl); } + // If we're compiling the compiler-builtins crate, e.g. the equivalent of + // compiler-rt, then we want to implicitly compile everything with hidden + // visibility as we're going to link this object all over the place but + // don't want the symbols to get exported. + if linkage != llvm::Linkage::InternalLinkage && + linkage != llvm::Linkage::PrivateLinkage && + attr::contains_name(ccx.tcx().hir.krate_attrs(), "compiler_builtins") { + unsafe { + llvm::LLVMRustSetVisibility(lldecl, llvm::Visibility::Hidden); + } + } + debug!("predefine_fn: mono_ty = {:?} instance = {:?}", mono_ty, instance); if common::is_inline_instance(ccx.tcx(), &instance) { attributes::inline(lldecl, attributes::InlineAttr::Hint); |
