Skip to content

Commit

Permalink
document the implementation a bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Aparicio committed Apr 6, 2017
1 parent ecddad6 commit bbe5411
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/librustc_trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,8 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}
}

// Create llvm.used variable
// Create the llvm.used variable
// This variable has type [N x i8*] and is stored in the llvm.metadata section
if !ccx.used_statics().borrow().is_empty() {
let name = CString::new("llvm.used").unwrap();
let section = CString::new("llvm.metadata").unwrap();
Expand Down
1 change: 1 addition & 0 deletions src/librustc_trans/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ pub fn trans_static<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
base::set_link_section(ccx, g, attrs);

if attr::contains_name(attrs, "used") {
// This static will be stored in the llvm.used variable which is an array of i8*
let cast = llvm::LLVMConstPointerCast(g, Type::i8p(ccx).to_ref());
ccx.used_statics().borrow_mut().push(cast);
}
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_trans/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ pub struct LocalCrateContext<'tcx> {
/// to constants.)
statics_to_rauw: RefCell<Vec<(ValueRef, ValueRef)>>,

/// Statics that will be placed in the llvm.used variable
/// See http://llvm.org/docs/LangRef.html#the-llvm-used-global-variable for details
used_statics: RefCell<Vec<ValueRef>>,

lltypes: RefCell<FxHashMap<Ty<'tcx>, Type>>,
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ declare_features! (
// See rust-lang/rfcs#1414. Allows code like `let x: &'static u32 = &42` to work.
(active, rvalue_static_promotion, "1.15.1", Some(38865)),

// Used to preserve symbols
(active, used, "1.18.0", None),
// Used to preserve symbols (see llvm.used)
(active, used, "1.18.0", Some(40289)),
);

declare_features! (
Expand Down

0 comments on commit bbe5411

Please sign in to comment.