Skip to content

Commit

Permalink
Support for specifying the code model
Browse files Browse the repository at this point in the history
The default code model is usually unsuitable for kernels,
so we add an option to specify which model we want.
  • Loading branch information
Zoxc committed Jul 15, 2014
1 parent 1704ebb commit 0a31060
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/librustc/back/link.rs
Expand Up @@ -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
Expand All @@ -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 */,
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/driver/config.rs
Expand Up @@ -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,
Expand Down

5 comments on commit 0a31060

@bors
Copy link
Contributor

@bors bors commented on 0a31060 Jul 17, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at Zoxc@0a31060

@bors
Copy link
Contributor

@bors bors commented on 0a31060 Jul 17, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging Zoxc/rust/code-model = 0a31060 into auto

@bors
Copy link
Contributor

@bors bors commented on 0a31060 Jul 17, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zoxc/rust/code-model = 0a31060 merged ok, testing candidate = dd348b3

@bors
Copy link
Contributor

@bors bors commented on 0a31060 Jul 17, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = dd348b3

Please sign in to comment.