@@ -51,11 +51,31 @@ use std::thread;
5151
5252const PRE_LTO_BC_EXT : & str = "pre-lto.bc" ;
5353
54- /// The kind of bitcode to embed in object files.
55- #[ derive( PartialEq ) ]
56- pub enum EmbedBitcode {
54+ /// What kind of object file to emit.
55+ #[ derive( Clone , Copy , PartialEq ) ]
56+ pub enum EmitObj {
57+ // No object file.
5758 None ,
59+
60+ // Just uncompressed llvm bitcode. Provides easy compatibility with
61+ // emscripten's ecc compiler, when used as the linker.
62+ Bitcode ,
63+
64+ // Object code, possibly augmented with a bitcode section.
65+ ObjectCode ( BitcodeSection ) ,
66+ }
67+
68+ /// What kind of llvm bitcode section to embed in an object file.
69+ #[ derive( Clone , Copy , PartialEq ) ]
70+ pub enum BitcodeSection {
71+ // No bitcode section.
72+ None ,
73+
74+ // An empty bitcode section (to placate tools such as the iOS linker that
75+ // require this section even if they don't use it).
5876 Marker ,
77+
78+ // A full, uncompressed bitcode section.
5979 Full ,
6080}
6181
@@ -84,7 +104,7 @@ pub struct ModuleConfig {
84104 pub emit_bc_compressed : bool ,
85105 pub emit_ir : bool ,
86106 pub emit_asm : bool ,
87- pub emit_obj : bool ,
107+ pub emit_obj : EmitObj ,
88108 // Miscellaneous flags. These are mostly copied from command-line
89109 // options.
90110 pub verify_llvm_ir : bool ,
@@ -96,12 +116,7 @@ pub struct ModuleConfig {
96116 pub merge_functions : bool ,
97117 pub inline_threshold : Option < usize > ,
98118 pub new_llvm_pass_manager : Option < bool > ,
99- // Instead of creating an object file by doing LLVM codegen, just
100- // make the object file bitcode. Provides easy compatibility with
101- // emscripten's ecc compiler, when used as the linker.
102- pub obj_is_bitcode : bool ,
103119 pub no_integrated_as : bool ,
104- pub embed_bitcode : EmbedBitcode ,
105120}
106121
107122impl ModuleConfig {
@@ -124,9 +139,7 @@ impl ModuleConfig {
124139 emit_bc_compressed : false ,
125140 emit_ir : false ,
126141 emit_asm : false ,
127- emit_obj : false ,
128- obj_is_bitcode : false ,
129- embed_bitcode : EmbedBitcode :: None ,
142+ emit_obj : EmitObj :: None ,
130143 no_integrated_as : false ,
131144
132145 verify_llvm_ir : false ,
@@ -147,17 +160,6 @@ impl ModuleConfig {
147160 self . no_builtins = no_builtins || sess. target . target . options . no_builtins ;
148161 self . inline_threshold = sess. opts . cg . inline_threshold ;
149162 self . new_llvm_pass_manager = sess. opts . debugging_opts . new_llvm_pass_manager ;
150- self . obj_is_bitcode =
151- sess. target . target . options . obj_is_bitcode || sess. opts . cg . linker_plugin_lto . enabled ( ) ;
152- self . embed_bitcode =
153- if sess. target . target . options . embed_bitcode || sess. opts . debugging_opts . embed_bitcode {
154- match sess. opts . optimize {
155- config:: OptLevel :: No | config:: OptLevel :: Less => EmbedBitcode :: Marker ,
156- _ => EmbedBitcode :: Full ,
157- }
158- } else {
159- EmbedBitcode :: None
160- } ;
161163
162164 // Copy what clang does by turning on loop vectorization at O2 and
163165 // slp vectorization at O3. Otherwise configure other optimization aspects
@@ -194,9 +196,9 @@ impl ModuleConfig {
194196
195197 pub fn bitcode_needed ( & self ) -> bool {
196198 self . emit_bc
197- || self . obj_is_bitcode
198199 || self . emit_bc_compressed
199- || self . embed_bitcode == EmbedBitcode :: Full
200+ || self . emit_obj == EmitObj :: Bitcode
201+ || self . emit_obj == EmitObj :: ObjectCode ( BitcodeSection :: Full )
200202 }
201203}
202204
@@ -397,6 +399,20 @@ pub fn start_async_codegen<B: ExtraBackendMethods>(
397399 allocator_config. emit_bc_compressed = true ;
398400 }
399401
402+ let emit_obj =
403+ if sess. target . target . options . obj_is_bitcode || sess. opts . cg . linker_plugin_lto . enabled ( ) {
404+ EmitObj :: Bitcode
405+ } else if sess. opts . debugging_opts . embed_bitcode {
406+ match sess. opts . optimize {
407+ config:: OptLevel :: No | config:: OptLevel :: Less => {
408+ EmitObj :: ObjectCode ( BitcodeSection :: Marker )
409+ }
410+ _ => EmitObj :: ObjectCode ( BitcodeSection :: Full ) ,
411+ }
412+ } else {
413+ EmitObj :: ObjectCode ( BitcodeSection :: None )
414+ } ;
415+
400416 modules_config. emit_pre_lto_bc = need_pre_lto_bitcode_for_incr_comp ( sess) ;
401417
402418 modules_config. no_integrated_as =
@@ -416,20 +432,20 @@ pub fn start_async_codegen<B: ExtraBackendMethods>(
416432 // could be invoked specially with output_type_assembly, so
417433 // in this case we still want the metadata object file.
418434 if !sess. opts . output_types . contains_key ( & OutputType :: Assembly ) {
419- metadata_config. emit_obj = true ;
420- allocator_config. emit_obj = true ;
435+ metadata_config. emit_obj = emit_obj ;
436+ allocator_config. emit_obj = emit_obj ;
421437 }
422438 }
423439 OutputType :: Object => {
424- modules_config. emit_obj = true ;
440+ modules_config. emit_obj = emit_obj ;
425441 }
426442 OutputType :: Metadata => {
427- metadata_config. emit_obj = true ;
443+ metadata_config. emit_obj = emit_obj ;
428444 }
429445 OutputType :: Exe => {
430- modules_config. emit_obj = true ;
431- metadata_config. emit_obj = true ;
432- allocator_config. emit_obj = true ;
446+ modules_config. emit_obj = emit_obj ;
447+ metadata_config. emit_obj = emit_obj ;
448+ allocator_config. emit_obj = emit_obj ;
433449 }
434450 OutputType :: Mir => { }
435451 OutputType :: DepInfo => { }
@@ -880,7 +896,7 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
880896 }
881897 }
882898
883- assert_eq ! ( object. is_some( ) , module_config. emit_obj) ;
899+ assert_eq ! ( object. is_some( ) , module_config. emit_obj != EmitObj :: None ) ;
884900 assert_eq ! ( bytecode. is_some( ) , module_config. emit_bc) ;
885901 assert_eq ! ( bytecode_compressed. is_some( ) , module_config. emit_bc_compressed) ;
886902
0 commit comments