@@ -69,8 +69,7 @@ pub const RELOC_MODEL_ARGS : [(&'static str, llvm::RelocMode); 7] = [
69
69
( "ropi-rwpi" , llvm:: RelocMode :: ROPI_RWPI ) ,
70
70
] ;
71
71
72
- pub const CODE_GEN_MODEL_ARGS : [ ( & ' static str , llvm:: CodeModel ) ; 5 ] = [
73
- ( "default" , llvm:: CodeModel :: Default ) ,
72
+ pub const CODE_GEN_MODEL_ARGS : & [ ( & str , llvm:: CodeModel ) ] = & [
74
73
( "small" , llvm:: CodeModel :: Small ) ,
75
74
( "kernel" , llvm:: CodeModel :: Kernel ) ,
76
75
( "medium" , llvm:: CodeModel :: Medium ) ,
@@ -171,20 +170,23 @@ pub fn target_machine_factory(sess: &Session)
171
170
let ffunction_sections = sess. target . target . options . function_sections ;
172
171
let fdata_sections = ffunction_sections;
173
172
174
- let code_model_arg = match sess. opts . cg . code_model {
175
- Some ( ref s) => & s,
176
- None => & sess. target . target . options . code_model ,
177
- } ;
178
-
179
- let code_model = match CODE_GEN_MODEL_ARGS . iter ( ) . find (
180
- |& & arg| arg. 0 == code_model_arg) {
181
- Some ( x) => x. 1 ,
182
- _ => {
183
- sess. err ( & format ! ( "{:?} is not a valid code model" ,
184
- code_model_arg) ) ;
185
- sess. abort_if_errors ( ) ;
186
- bug ! ( ) ;
173
+ let code_model_arg = sess. opts . cg . code_model . as_ref ( ) . or (
174
+ sess. target . target . options . code_model . as_ref ( ) ,
175
+ ) ;
176
+
177
+ let code_model = match code_model_arg {
178
+ Some ( s) => {
179
+ match CODE_GEN_MODEL_ARGS . iter ( ) . find ( |arg| arg. 0 == s) {
180
+ Some ( x) => x. 1 ,
181
+ _ => {
182
+ sess. err ( & format ! ( "{:?} is not a valid code model" ,
183
+ code_model_arg) ) ;
184
+ sess. abort_if_errors ( ) ;
185
+ bug ! ( ) ;
186
+ }
187
+ }
187
188
}
189
+ None => llvm:: CodeModel :: None ,
188
190
} ;
189
191
190
192
let singlethread = sess. target . target . options . singlethread ;
@@ -746,7 +748,7 @@ unsafe fn codegen(cgcx: &CodegenContext,
746
748
// We can't use the same module for asm and binary output, because that triggers
747
749
// various errors like invalid IR or broken binaries, so we might have to clone the
748
750
// module to produce the asm output
749
- let llmod = if config. emit_obj {
751
+ let llmod = if config. emit_obj && !asm2wasm {
750
752
llvm:: LLVMCloneModule ( llmod)
751
753
} else {
752
754
llmod
@@ -755,7 +757,7 @@ unsafe fn codegen(cgcx: &CodegenContext,
755
757
write_output_file ( diag_handler, tm, cpm, llmod, & path,
756
758
llvm:: FileType :: AssemblyFile )
757
759
} ) ?;
758
- if config. emit_obj {
760
+ if config. emit_obj && !asm2wasm {
759
761
llvm:: LLVMDisposeModule ( llmod) ;
760
762
}
761
763
timeline. record ( "asm" ) ;
0 commit comments