about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-07-17 12:11:19 +0000
committerbors <bors@rust-lang.org>2014-07-17 12:11:19 +0000
commitdd348b3ab0147fda3dedbdc6947c14354971e14a (patch)
tree56b86061e5105f751111f05e9deebb0e853c4b86
parent9fc8394d3bce22ab483f98842434c84c396212ae (diff)
parent0a31060815b63a87729be0178c7fce52d3b88d6f (diff)
downloadrust-dd348b3ab0147fda3dedbdc6947c14354971e14a.tar.gz
rust-dd348b3ab0147fda3dedbdc6947c14354971e14a.zip
auto merge of #15698 : Zoxc/rust/code-model, r=alexcrichton
The default code model is usually unsuitable for kernels,
so we add an option to specify which model we want.

Testing for this would be fragile and very architecture specific and is better left to LLVM.
-rw-r--r--src/librustc/back/link.rs18
-rw-r--r--src/librustc/driver/config.rs2
2 files changed, 19 insertions, 1 deletions
diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs
index 6fa8a153023..9d2ed6adec5 100644
--- a/src/librustc/back/link.rs
+++ b/src/librustc/back/link.rs
@@ -186,6 +186,22 @@ pub mod write {
                 }
             };
 
+            let code_model = match sess.opts.cg.code_model.as_slice() {
+                "default" => llvm::CodeModelDefault,
+                "small" => llvm::CodeModelSmall,
+                "kernel" => llvm::CodeModelKernel,
+                "medium" => llvm::CodeModelMedium,
+                "large" => llvm::CodeModelLarge,
+                _ => {
+                    sess.err(format!("{} is not a valid code model",
+                                     sess.opts
+                                         .cg
+                                         .code_model).as_slice());
+                    sess.abort_if_errors();
+                    return;
+                }
+            };
+
             let tm = sess.targ_cfg
                          .target_strs
                          .target_triple
@@ -195,7 +211,7 @@ pub mod write {
                     target_feature(sess).with_c_str(|features| {
                         llvm::LLVMRustCreateTargetMachine(
                             t, cpu, features,
-                            llvm::CodeModelDefault,
+                            code_model,
                             reloc_model,
                             opt_level,
                             true /* EnableSegstk */,
diff --git a/src/librustc/driver/config.rs b/src/librustc/driver/config.rs
index 3a59c2bbcc3..ee611293475 100644
--- a/src/librustc/driver/config.rs
+++ b/src/librustc/driver/config.rs
@@ -336,6 +336,8 @@ cgoptions!(
         "disable the use of the redzone"),
     relocation_model: String = ("pic".to_string(), parse_string,
          "choose the relocation model to use (llc -relocation-model for details)"),
+    code_model: String = ("default".to_string(), parse_string,
+         "choose the code model to use (llc -code-model for details)"),
     metadata: Vec<String> = (Vec::new(), parse_list,
          "metadata to mangle symbol names with"),
     extra_filename: String = ("".to_string(), parse_string,