Skip to content

rustc: Flag all builtins functions as hidden #37714

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

Merged
merged 1 commit into from
Nov 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 @@ -27,6 +28,7 @@ use attributes;
use context::CrateContext;
use type_::Type;
use value::Value;
use syntax::attr;

use std::ffi::CString;

Expand Down Expand Up @@ -69,6 +71,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