From 1007739b20110bf7af654354815e2a1265282ec2 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 30 Jun 2014 22:52:48 -0700 Subject: [PATCH] rustc: Add a new codegen flag, -C metadata=foo This metadata is used to drive the hash of all symbols in a crate. The flag can be specified a multiple number of times RFC: 0035-remove-crate-id --- src/librustc/back/link.rs | 8 +++++++- src/librustc/driver/config.rs | 2 ++ src/librustc/driver/driver.rs | 7 +++++++ src/librustc/driver/mod.rs | 2 ++ src/librustc/driver/session.rs | 2 ++ 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index 9cdf0fbb5e8f..1145d0595ab3 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -593,7 +593,10 @@ pub fn crate_name_hash(sess: &Session, crate_name: &str) -> String { // the crate id in the hash because lookups are only done by (name/vers), // not by path. let mut s = Sha256::new(); - s.input_str(crate_id.short_name_with_version().as_slice()); + s.input_str(crate_name); + for meta in sess.crate_metadata.borrow().iter() { + s.input_str(meta.as_slice()); + } truncated_hash_result(&mut s).as_slice().slice_to(8).to_string() } @@ -626,6 +629,9 @@ fn symbol_hash(tcx: &ty::ctxt, symbol_hasher.input_str(link_meta.crate_name.as_slice()); symbol_hasher.input_str("-"); symbol_hasher.input_str(link_meta.crate_hash.as_str()); + for meta in tcx.sess.crate_metadata.borrow().iter() { + symbol_hasher.input_str(meta.as_slice()); + } symbol_hasher.input_str("-"); symbol_hasher.input_str(encoder::encoded_ty(tcx, t).as_slice()); // Prefix with 'h' so that it never blends into adjacent digits diff --git a/src/librustc/driver/config.rs b/src/librustc/driver/config.rs index 1474b4fddce4..b35d1be98f30 100644 --- a/src/librustc/driver/config.rs +++ b/src/librustc/driver/config.rs @@ -318,6 +318,8 @@ cgoptions!( "use an external assembler rather than LLVM's integrated one"), relocation_model: String = ("pic".to_string(), parse_string, "choose the relocation model to use (llc -relocation-model for details)"), + metadata: Vec = (Vec::new(), parse_list, + "metadata to mangle symbol names with"), ) pub fn build_codegen_options(matches: &getopts::Matches) -> CodegenOptions diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 356f56aac638..1512c359bb8e 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -186,6 +186,8 @@ pub fn phase_2_configure_and_expand(sess: &Session, *sess.crate_types.borrow_mut() = collect_crate_types(sess, krate.attrs.as_slice()); + *sess.crate_metadata.borrow_mut() = + collect_crate_metadata(sess, krate.attrs.as_slice()); time(time_passes, "gated feature checking", (), |_| front::feature_gate::check_crate(sess, &krate)); @@ -848,6 +850,11 @@ pub fn collect_crate_types(session: &Session, }).collect() } +pub fn collect_crate_metadata(session: &Session, + _attrs: &[ast::Attribute]) -> Vec { + session.opts.cg.metadata.clone() +} + pub struct OutputFilenames { pub out_directory: Path, pub out_filestem: String, diff --git a/src/librustc/driver/mod.rs b/src/librustc/driver/mod.rs index f368e0ba7c8a..dc6b8fa5af3d 100644 --- a/src/librustc/driver/mod.rs +++ b/src/librustc/driver/mod.rs @@ -311,6 +311,8 @@ fn print_crate_info(sess: &Session, } if crate_file_name { let crate_types = driver::collect_crate_types(sess, attrs.as_slice()); + let metadata = driver::collect_crate_metadata(sess, attrs.as_slice()); + *sess.crate_metadata.borrow_mut() = metadata; for &style in crate_types.iter() { let fname = link::filename_for_input(sess, style, id.as_slice(), &t_outputs.with_extension("")); diff --git a/src/librustc/driver/session.rs b/src/librustc/driver/session.rs index 07366f34c4e0..50f61f8f06a5 100644 --- a/src/librustc/driver/session.rs +++ b/src/librustc/driver/session.rs @@ -47,6 +47,7 @@ pub struct Session { pub lints: RefCell>>, pub node_id: Cell, pub crate_types: RefCell>, + pub crate_metadata: RefCell>, pub features: front::feature_gate::Features, /// The maximum recursion limit for potentially infinitely recursive @@ -243,6 +244,7 @@ pub fn build_session_(sopts: config::Options, lints: RefCell::new(NodeMap::new()), node_id: Cell::new(1), crate_types: RefCell::new(Vec::new()), + crate_metadata: RefCell::new(Vec::new()), features: front::feature_gate::Features::new(), recursion_limit: Cell::new(64), };