Skip to content

Commit bbe5411

Browse files
author
Jorge Aparicio
committed
document the implementation a bit more
1 parent ecddad6 commit bbe5411

File tree

4 files changed

+7
-3
lines changed

4 files changed

+7
-3
lines changed

src/librustc_trans/base.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,8 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
11871187
}
11881188
}
11891189

1190-
// Create llvm.used variable
1190+
// Create the llvm.used variable
1191+
// This variable has type [N x i8*] and is stored in the llvm.metadata section
11911192
if !ccx.used_statics().borrow().is_empty() {
11921193
let name = CString::new("llvm.used").unwrap();
11931194
let section = CString::new("llvm.metadata").unwrap();

src/librustc_trans/consts.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ pub fn trans_static<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
277277
base::set_link_section(ccx, g, attrs);
278278

279279
if attr::contains_name(attrs, "used") {
280+
// This static will be stored in the llvm.used variable which is an array of i8*
280281
let cast = llvm::LLVMConstPointerCast(g, Type::i8p(ccx).to_ref());
281282
ccx.used_statics().borrow_mut().push(cast);
282283
}

src/librustc_trans/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ pub struct LocalCrateContext<'tcx> {
132132
/// to constants.)
133133
statics_to_rauw: RefCell<Vec<(ValueRef, ValueRef)>>,
134134

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

137139
lltypes: RefCell<FxHashMap<Ty<'tcx>, Type>>,

src/libsyntax/feature_gate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,8 @@ declare_features! (
344344
// See rust-lang/rfcs#1414. Allows code like `let x: &'static u32 = &42` to work.
345345
(active, rvalue_static_promotion, "1.15.1", Some(38865)),
346346

347-
// Used to preserve symbols
348-
(active, used, "1.18.0", None),
347+
// Used to preserve symbols (see llvm.used)
348+
(active, used, "1.18.0", Some(40289)),
349349
);
350350

351351
declare_features! (

0 commit comments

Comments
 (0)