@@ -154,13 +154,16 @@ fn get_llvm_opt_size(optimize: config::OptLevel) -> llvm::CodeGenOptSize {
154154 }
155155}
156156
157- pub fn create_target_machine ( sess : & Session ) -> TargetMachineRef {
158- target_machine_factory ( sess) ( ) . unwrap_or_else ( |err| {
157+ pub fn create_target_machine ( sess : & Session , find_features : bool ) -> TargetMachineRef {
158+ target_machine_factory ( sess, find_features ) ( ) . unwrap_or_else ( |err| {
159159 llvm_err ( sess. diagnostic ( ) , err) . raise ( )
160160 } )
161161}
162162
163- pub fn target_machine_factory ( sess : & Session )
163+ // If find_features is true this won't access `sess.crate_types` by assuming
164+ // that `is_pie_binary` is false. When we discover LLVM target features
165+ // `sess.crate_types` is uninitialized so we cannot access it.
166+ pub fn target_machine_factory ( sess : & Session , find_features : bool )
164167 -> Arc < Fn ( ) -> Result < TargetMachineRef , String > + Send + Sync >
165168{
166169 let reloc_model = get_reloc_model ( sess) ;
@@ -201,7 +204,7 @@ pub fn target_machine_factory(sess: &Session)
201204 } ;
202205 let cpu = CString :: new ( cpu. as_bytes ( ) ) . unwrap ( ) ;
203206 let features = CString :: new ( target_feature ( sess) . as_bytes ( ) ) . unwrap ( ) ;
204- let is_pie_binary = is_pie_binary ( sess) ;
207+ let is_pie_binary = !find_features && is_pie_binary ( sess) ;
205208 let trap_unreachable = sess. target . target . options . trap_unreachable ;
206209
207210 Arc :: new ( move || {
@@ -1510,7 +1513,7 @@ fn start_executing_work(tcx: TyCtxt,
15101513 regular_module_config : modules_config,
15111514 metadata_module_config : metadata_config,
15121515 allocator_module_config : allocator_config,
1513- tm_factory : target_machine_factory ( tcx. sess ) ,
1516+ tm_factory : target_machine_factory ( tcx. sess , false ) ,
15141517 total_cgus,
15151518 msvc_imps_needed : msvc_imps_needed ( tcx) ,
15161519 target_pointer_width : tcx. sess . target . target . target_pointer_width . clone ( ) ,
0 commit comments