Skip to content

Commit dd348b3

Browse files
committed
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.
2 parents 9fc8394 + 0a31060 commit dd348b3

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/librustc/back/link.rs

+17-1
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

+2
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ cgoptions!(
336336
"disable the use of the redzone"),
337337
relocation_model: String = ("pic".to_string(), parse_string,
338338
"choose the relocation model to use (llc -relocation-model for details)"),
339+
code_model: String = ("default".to_string(), parse_string,
340+
"choose the code model to use (llc -code-model for details)"),
339341
metadata: Vec<String> = (Vec::new(), parse_list,
340342
"metadata to mangle symbol names with"),
341343
extra_filename: String = ("".to_string(), parse_string,

0 commit comments

Comments
 (0)