@@ -69,8 +69,7 @@ pub const RELOC_MODEL_ARGS : [(&'static str, llvm::RelocMode); 7] = [
6969 ( "ropi-rwpi" , llvm:: RelocMode :: ROPI_RWPI ) ,
7070] ;
7171
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 ) ] = & [
7473 ( "small" , llvm:: CodeModel :: Small ) ,
7574 ( "kernel" , llvm:: CodeModel :: Kernel ) ,
7675 ( "medium" , llvm:: CodeModel :: Medium ) ,
@@ -171,20 +170,23 @@ pub fn target_machine_factory(sess: &Session)
171170 let ffunction_sections = sess. target . target . options . function_sections ;
172171 let fdata_sections = ffunction_sections;
173172
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+ }
187188 }
189+ None => llvm:: CodeModel :: None ,
188190 } ;
189191
190192 let singlethread = sess. target . target . options . singlethread ;
@@ -746,7 +748,7 @@ unsafe fn codegen(cgcx: &CodegenContext,
746748 // We can't use the same module for asm and binary output, because that triggers
747749 // various errors like invalid IR or broken binaries, so we might have to clone the
748750 // module to produce the asm output
749- let llmod = if config. emit_obj {
751+ let llmod = if config. emit_obj && !asm2wasm {
750752 llvm:: LLVMCloneModule ( llmod)
751753 } else {
752754 llmod
@@ -755,7 +757,7 @@ unsafe fn codegen(cgcx: &CodegenContext,
755757 write_output_file ( diag_handler, tm, cpm, llmod, & path,
756758 llvm:: FileType :: AssemblyFile )
757759 } ) ?;
758- if config. emit_obj {
760+ if config. emit_obj && !asm2wasm {
759761 llvm:: LLVMDisposeModule ( llmod) ;
760762 }
761763 timeline. record ( "asm" ) ;
0 commit comments