Make drop glue use new symbol naming scheme.

This commit is contained in:
Michael Woerister 2016-02-14 17:38:49 -05:00 committed by Niko Matsakis
parent 6f60c9e1fd
commit 7a5a988579
2 changed files with 20 additions and 3 deletions

View File

@ -96,7 +96,7 @@
//! virtually impossible. Thus, symbol hash generation exclusively relies on
//! DefPaths which are much more robust in the face of changes to the code base.
use trans::{CrateContext, Instance};
use trans::{CrateContext, Instance, gensym_name};
use util::sha2::{Digest, Sha256};
use rustc::middle::cstore;
@ -221,3 +221,15 @@ pub fn exported_name_with_suffix<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
-> String {
exported_name_with_opt_suffix(ccx, instance, Some(suffix))
}
/// Only symbols that are invisible outside their compilation unit should use a
/// name generated by this function.
pub fn internal_name_from_type_and_suffix<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
t: ty::Ty<'tcx>,
suffix: &str)
-> String {
let path = [token::intern(&t.to_string()).as_str(),
gensym_name(suffix).as_str()];
let hash = get_symbol_hash(ccx, &Vec::new(), cstore::LOCAL_CRATE, &[t]);
link::mangle(path.iter().cloned(), Some(&hash[..]))
}

View File

@ -14,7 +14,7 @@
use std;
use back::link;
use back::symbol_names;
use llvm;
use llvm::{ValueRef, get_param};
use middle::lang_items::ExchangeFreeFnLangItem;
@ -259,7 +259,12 @@ fn get_drop_glue_core<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
return llfn;
};
let fn_nm = link::mangle_internal_name_by_type_and_seq(ccx, t, "drop");
let suffix = match g {
DropGlueKind::Ty(_) => "drop",
DropGlueKind::TyContents(_) => "drop_contents",
};
let fn_nm = symbol_names::internal_name_from_type_and_suffix(ccx, t, suffix);
assert!(declare::get_defined_value(ccx, &fn_nm).is_none());
let llfn = declare::declare_cfn(ccx, &fn_nm, llfnty);
ccx.available_drop_glues().borrow_mut().insert(g, fn_nm);