@@ -51,11 +51,31 @@ use std::thread;
51
51
52
52
const PRE_LTO_BC_EXT : & str = "pre-lto.bc" ;
53
53
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.
57
58
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).
58
76
Marker ,
77
+
78
+ // A full, uncompressed bitcode section.
59
79
Full ,
60
80
}
61
81
@@ -84,7 +104,7 @@ pub struct ModuleConfig {
84
104
pub emit_bc_compressed : bool ,
85
105
pub emit_ir : bool ,
86
106
pub emit_asm : bool ,
87
- pub emit_obj : bool ,
107
+ pub emit_obj : EmitObj ,
88
108
// Miscellaneous flags. These are mostly copied from command-line
89
109
// options.
90
110
pub verify_llvm_ir : bool ,
@@ -96,12 +116,7 @@ pub struct ModuleConfig {
96
116
pub merge_functions : bool ,
97
117
pub inline_threshold : Option < usize > ,
98
118
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 ,
103
119
pub no_integrated_as : bool ,
104
- pub embed_bitcode : EmbedBitcode ,
105
120
}
106
121
107
122
impl ModuleConfig {
@@ -124,9 +139,7 @@ impl ModuleConfig {
124
139
emit_bc_compressed : false ,
125
140
emit_ir : false ,
126
141
emit_asm : false ,
127
- emit_obj : false ,
128
- obj_is_bitcode : false ,
129
- embed_bitcode : EmbedBitcode :: None ,
142
+ emit_obj : EmitObj :: None ,
130
143
no_integrated_as : false ,
131
144
132
145
verify_llvm_ir : false ,
@@ -147,17 +160,6 @@ impl ModuleConfig {
147
160
self . no_builtins = no_builtins || sess. target . target . options . no_builtins ;
148
161
self . inline_threshold = sess. opts . cg . inline_threshold ;
149
162
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
- } ;
161
163
162
164
// Copy what clang does by turning on loop vectorization at O2 and
163
165
// slp vectorization at O3. Otherwise configure other optimization aspects
@@ -194,9 +196,9 @@ impl ModuleConfig {
194
196
195
197
pub fn bitcode_needed ( & self ) -> bool {
196
198
self . emit_bc
197
- || self . obj_is_bitcode
198
199
|| self . emit_bc_compressed
199
- || self . embed_bitcode == EmbedBitcode :: Full
200
+ || self . emit_obj == EmitObj :: Bitcode
201
+ || self . emit_obj == EmitObj :: ObjectCode ( BitcodeSection :: Full )
200
202
}
201
203
}
202
204
@@ -397,6 +399,20 @@ pub fn start_async_codegen<B: ExtraBackendMethods>(
397
399
allocator_config. emit_bc_compressed = true ;
398
400
}
399
401
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
+
400
416
modules_config. emit_pre_lto_bc = need_pre_lto_bitcode_for_incr_comp ( sess) ;
401
417
402
418
modules_config. no_integrated_as =
@@ -416,20 +432,20 @@ pub fn start_async_codegen<B: ExtraBackendMethods>(
416
432
// could be invoked specially with output_type_assembly, so
417
433
// in this case we still want the metadata object file.
418
434
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 ;
421
437
}
422
438
}
423
439
OutputType :: Object => {
424
- modules_config. emit_obj = true ;
440
+ modules_config. emit_obj = emit_obj ;
425
441
}
426
442
OutputType :: Metadata => {
427
- metadata_config. emit_obj = true ;
443
+ metadata_config. emit_obj = emit_obj ;
428
444
}
429
445
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 ;
433
449
}
434
450
OutputType :: Mir => { }
435
451
OutputType :: DepInfo => { }
@@ -880,7 +896,7 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
880
896
}
881
897
}
882
898
883
- assert_eq ! ( object. is_some( ) , module_config. emit_obj) ;
899
+ assert_eq ! ( object. is_some( ) , module_config. emit_obj != EmitObj :: None ) ;
884
900
assert_eq ! ( bytecode. is_some( ) , module_config. emit_bc) ;
885
901
assert_eq ! ( bytecode_compressed. is_some( ) , module_config. emit_bc_compressed) ;
886
902
0 commit comments