]> git.lizzy.rs Git - rust.git/commitdiff
Make drop glue use new symbol naming scheme.
authorMichael Woerister <michaelwoerister@posteo.net>
Sun, 14 Feb 2016 22:38:49 +0000 (17:38 -0500)
committerNiko Matsakis <niko@alum.mit.edu>
Fri, 25 Mar 2016 18:07:18 +0000 (14:07 -0400)
src/librustc_trans/back/symbol_names.rs
src/librustc_trans/trans/glue.rs

index de188ec9960ee5b5325bdd085852061329eb62e8..f9bed0019dfd29de1baa966acfce88e5667674ad 100644 (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[..]))
+}
index de4b1ba858a6c21b8e67c37a29bf935a84570657..aa205898114d636cd6e489998b1277f560ae66b4 100644 (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);