Skip to content

Commit

Permalink
Make drop glue use new symbol naming scheme.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwoerister authored and nikomatsakis committed Mar 25, 2016
1 parent 6f60c9e commit 7a5a988
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/librustc_trans/back/symbol_names.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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[..]))
}
9 changes: 7 additions & 2 deletions src/librustc_trans/trans/glue.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7a5a988

Please sign in to comment.