Skip to content

Commit c3eb7d0

Browse files
Make drop glue use new symbol naming scheme.
1 parent f3c2a2b commit c3eb7d0

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/librustc_trans/back/symbol_names.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
//! virtually impossible. Thus, symbol hash generation exclusively relies on
9797
//! DefPaths which are much more robust in the face of changes to the code base.
9898
99-
use trans::CrateContext;
99+
use trans::{CrateContext, gensym_name};
100100
use util::sha2::{Digest, Sha256};
101101

102102
use rustc::middle::cstore;
@@ -222,3 +222,15 @@ pub fn exported_name_with_suffix<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
222222
-> String {
223223
exported_name_with_opt_suffix(ccx, def_id, parameters, Some(suffix))
224224
}
225+
226+
/// Only symbols that are invisible outside their compilation unit should use a
227+
/// name generated by this function.
228+
pub fn internal_name_from_type_and_suffix<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
229+
t: ty::Ty<'tcx>,
230+
suffix: &str)
231+
-> String {
232+
let path = [token::intern(&t.to_string()).as_str(),
233+
gensym_name(suffix).as_str()];
234+
let hash = get_symbol_hash(ccx, &Vec::new(), cstore::LOCAL_CRATE, &[t]);
235+
link::mangle(path.iter().cloned(), Some(&hash[..]))
236+
}

src/librustc_trans/trans/glue.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
use std;
1616

17-
use back::link::*;
17+
use back::symbol_names;
1818
use llvm;
1919
use llvm::{ValueRef, get_param};
2020
use middle::lang_items::ExchangeFreeFnLangItem;
@@ -256,7 +256,12 @@ fn get_drop_glue_core<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
256256
return llfn;
257257
};
258258

259-
let fn_nm = mangle_internal_name_by_type_and_seq(ccx, t, "drop");
259+
let suffix = match g {
260+
DropGlueKind::Ty(_) => "drop",
261+
DropGlueKind::TyContents(_) => "drop_contents",
262+
};
263+
264+
let fn_nm = symbol_names::internal_name_from_type_and_suffix(ccx, t, suffix);
260265
let llfn = declare::define_cfn(ccx, &fn_nm, llfnty, ccx.tcx().mk_nil()).unwrap_or_else(||{
261266
ccx.sess().bug(&format!("symbol `{}` already defined", fn_nm));
262267
});

0 commit comments

Comments
 (0)