about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2014-07-15 23:14:02 +0000
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2014-07-15 23:21:22 +0000
commit0a31060815b63a87729be0178c7fce52d3b88d6f (patch)
tree552d7be2b6d2dd58b7ca4e06e20d28a88a82b4a5
parent1704ebb798bd55a782b80ae6741c5d11403aaf13 (diff)
downloadrust-0a31060815b63a87729be0178c7fce52d3b88d6f.tar.gz
rust-0a31060815b63a87729be0178c7fce52d3b88d6f.zip
Support for specifying the code model
The default code model is usually unsuitable for kernels,
so we add an option to specify which model we want.
-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 cad164c9e20..a7a95965165 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 345877d9ab6..ddb95f12f15 100644
--- a/src/librustc/driver/config.rs
+++ b/src/librustc/driver/config.rs
@@ -334,6 +334,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)"),
+    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,