Skip to content

Commit 0a31060

Browse files
committed
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.
1 parent 1704ebb commit 0a31060

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/librustc/back/link.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,22 @@ pub mod write {
186186
}
187187
};
188188

189+
let code_model = match sess.opts.cg.code_model.as_slice() {
190+
"default" => llvm::CodeModelDefault,
191+
"small" => llvm::CodeModelSmall,
192+
"kernel" => llvm::CodeModelKernel,
193+
"medium" => llvm::CodeModelMedium,
194+
"large" => llvm::CodeModelLarge,
195+
_ => {
196+
sess.err(format!("{} is not a valid code model",
197+
sess.opts
198+
.cg
199+
.code_model).as_slice());
200+
sess.abort_if_errors();
201+
return;
202+
}
203+
};
204+
189205
let tm = sess.targ_cfg
190206
.target_strs
191207
.target_triple
@@ -195,7 +211,7 @@ pub mod write {
195211
target_feature(sess).with_c_str(|features| {
196212
llvm::LLVMRustCreateTargetMachine(
197213
t, cpu, features,
198-
llvm::CodeModelDefault,
214+
code_model,
199215
reloc_model,
200216
opt_level,
201217
true /* EnableSegstk */,

src/librustc/driver/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@ cgoptions!(
334334
"use an external assembler rather than LLVM's integrated one"),
335335
relocation_model: String = ("pic".to_string(), parse_string,
336336
"choose the relocation model to use (llc -relocation-model for details)"),
337+
code_model: String = ("default".to_string(), parse_string,
338+
"choose the code model to use (llc -code-model for details)"),
337339
metadata: Vec<String> = (Vec::new(), parse_list,
338340
"metadata to mangle symbol names with"),
339341
extra_filename: String = ("".to_string(), parse_string,

0 commit comments

Comments
 (0)