about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-06-30 22:52:48 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-07-05 12:38:42 -0700
commit1007739b20110bf7af654354815e2a1265282ec2 (patch)
treead12a9f1df6e9ddb040e2378e6b3b01a09020d28
parent50ee1ec1b4f107122d8037ac7b0b312afa6eb0ac (diff)
downloadrust-1007739b20110bf7af654354815e2a1265282ec2.tar.gz
rust-1007739b20110bf7af654354815e2a1265282ec2.zip
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
-rw-r--r--src/librustc/back/link.rs8
-rw-r--r--src/librustc/driver/config.rs2
-rw-r--r--src/librustc/driver/driver.rs7
-rw-r--r--src/librustc/driver/mod.rs2
-rw-r--r--src/librustc/driver/session.rs2
5 files changed, 20 insertions, 1 deletions
diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs
index 9cdf0fbb5e8..1145d0595ab 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 1474b4fddce..b35d1be98f3 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<String> = (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 356f56aac63..1512c359bb8 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<String> {
+    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 f368e0ba7c8..dc6b8fa5af3 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 07366f34c4e..50f61f8f06a 100644
--- a/src/librustc/driver/session.rs
+++ b/src/librustc/driver/session.rs
@@ -47,6 +47,7 @@ pub struct Session {
     pub lints: RefCell<NodeMap<Vec<(lint::LintId, codemap::Span, String)>>>,
     pub node_id: Cell<ast::NodeId>,
     pub crate_types: RefCell<Vec<config::CrateType>>,
+    pub crate_metadata: RefCell<Vec<String>>,
     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),
     };