Skip to content

Commit

Permalink
Auto merge of #37714 - alexcrichton:builtins-hidden, r=nikomatsakis
Browse files Browse the repository at this point in the history
rustc: Flag all builtins functions as hidden

When compiling compiler-rt you typically compile with `-fvisibility=hidden`
which to ensure that all symbols are hidden in shared objects and don't show up
in symbol tables. This is important for these intrinsics being linked in every
crate to ensure that we're not unnecessarily bloating the public ABI of Rust
crates.

This should help allow the compiler-builtins project with Rust-defined builtins
start landing in-tree as well.
  • Loading branch information
bors authored Nov 15, 2016
2 parents c8867f8 + 88b4646 commit 30857ae
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/libcompiler_builtins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ version = "0.0.0"
[lib]
name = "compiler_builtins"
path = "lib.rs"
test = false

[dependencies]
core = { path = "../libcore" }
Expand Down
12 changes: 10 additions & 2 deletions src/librustc_llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,14 @@ pub type OperandBundleDefRef = *mut OperandBundleDef_opaque;
pub type DiagnosticHandler = unsafe extern "C" fn(DiagnosticInfoRef, *mut c_void);
pub type InlineAsmDiagHandler = unsafe extern "C" fn(SMDiagnosticRef, *const c_void, c_uint);

/// LLVMVisibility
#[repr(C)]
pub enum Visibility {
Default,
Hidden,
Protected,
}

pub mod debuginfo {
pub use self::DIDescriptorFlags::*;
use super::MetadataRef;
Expand Down Expand Up @@ -746,8 +754,8 @@ extern "C" {
pub fn LLVMRustSetLinkage(Global: ValueRef, RustLinkage: Linkage);
pub fn LLVMGetSection(Global: ValueRef) -> *const c_char;
pub fn LLVMSetSection(Global: ValueRef, Section: *const c_char);
pub fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
pub fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
pub fn LLVMGetVisibility(Global: ValueRef) -> Visibility;
pub fn LLVMSetVisibility(Global: ValueRef, Viz: Visibility);
pub fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
pub fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
pub fn LLVMSetDLLStorageClass(V: ValueRef, C: DLLStorageClass);
Expand Down
12 changes: 12 additions & 0 deletions src/librustc_trans/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
//! interested in defining the ValueRef they return.
//! * Use define_* family of methods when you might be defining the ValueRef.
//! * When in doubt, define.
use llvm::{self, ValueRef};
use llvm::AttributePlace::Function;
use rustc::ty;
Expand All @@ -28,6 +29,7 @@ use context::CrateContext;
use common;
use type_::Type;
use value::Value;
use syntax::attr;

use std::ffi::CString;

Expand Down Expand Up @@ -70,6 +72,16 @@ fn declare_raw_fn(ccx: &CrateContext, name: &str, callconv: llvm::CallConv, ty:
llvm::Attribute::NoRedZone.apply_llfn(Function, llfn);
}

// 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().map.krate_attrs(), "compiler_builtins") {
unsafe {
llvm::LLVMSetVisibility(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);
Expand Down

0 comments on commit 30857ae

Please sign in to comment.