@@ -7,7 +7,7 @@ use crate::back::profiling::{
7
7
use crate :: base;
8
8
use crate :: common;
9
9
use crate :: consts;
10
- use crate :: context:: { get_reloc_model , is_pie_binary } ;
10
+ use crate :: context:: all_outputs_are_pic_executables ;
11
11
use crate :: llvm:: { self , DiagnosticInfo , PassManager , SMDiagnostic } ;
12
12
use crate :: llvm_util;
13
13
use crate :: type_:: Type ;
@@ -25,6 +25,7 @@ use rustc_middle::bug;
25
25
use rustc_middle:: ty:: TyCtxt ;
26
26
use rustc_session:: config:: { self , Lto , OutputType , Passes , Sanitizer , SwitchWithOptPath } ;
27
27
use rustc_session:: Session ;
28
+ use rustc_target:: spec:: RelocModel ;
28
29
29
30
use libc:: { c_char, c_int, c_uint, c_void, size_t} ;
30
31
use std:: ffi:: CString ;
@@ -35,16 +36,6 @@ use std::slice;
35
36
use std:: str;
36
37
use std:: sync:: Arc ;
37
38
38
- pub const RELOC_MODEL_ARGS : [ ( & str , llvm:: RelocMode ) ; 7 ] = [
39
- ( "pic" , llvm:: RelocMode :: PIC ) ,
40
- ( "static" , llvm:: RelocMode :: Static ) ,
41
- ( "default" , llvm:: RelocMode :: Default ) ,
42
- ( "dynamic-no-pic" , llvm:: RelocMode :: DynamicNoPic ) ,
43
- ( "ropi" , llvm:: RelocMode :: ROPI ) ,
44
- ( "rwpi" , llvm:: RelocMode :: RWPI ) ,
45
- ( "ropi-rwpi" , llvm:: RelocMode :: ROPI_RWPI ) ,
46
- ] ;
47
-
48
39
pub const CODE_GEN_MODEL_ARGS : & [ ( & str , llvm:: CodeModel ) ] = & [
49
40
( "small" , llvm:: CodeModel :: Small ) ,
50
41
( "kernel" , llvm:: CodeModel :: Kernel ) ,
@@ -84,19 +75,13 @@ pub fn write_output_file(
84
75
}
85
76
}
86
77
87
- pub fn create_informational_target_machine (
88
- sess : & Session ,
89
- find_features : bool ,
90
- ) -> & ' static mut llvm:: TargetMachine {
91
- target_machine_factory ( sess, config:: OptLevel :: No , find_features) ( )
78
+ pub fn create_informational_target_machine ( sess : & Session ) -> & ' static mut llvm:: TargetMachine {
79
+ target_machine_factory ( sess, config:: OptLevel :: No ) ( )
92
80
. unwrap_or_else ( |err| llvm_err ( sess. diagnostic ( ) , & err) . raise ( ) )
93
81
}
94
82
95
- pub fn create_target_machine (
96
- tcx : TyCtxt < ' _ > ,
97
- find_features : bool ,
98
- ) -> & ' static mut llvm:: TargetMachine {
99
- target_machine_factory ( & tcx. sess , tcx. backend_optimization_level ( LOCAL_CRATE ) , find_features) ( )
83
+ pub fn create_target_machine ( tcx : TyCtxt < ' _ > ) -> & ' static mut llvm:: TargetMachine {
84
+ target_machine_factory ( & tcx. sess , tcx. backend_optimization_level ( LOCAL_CRATE ) ) ( )
100
85
. unwrap_or_else ( |err| llvm_err ( tcx. sess . diagnostic ( ) , & err) . raise ( ) )
101
86
}
102
87
@@ -126,15 +111,22 @@ fn to_pass_builder_opt_level(cfg: config::OptLevel) -> llvm::PassBuilderOptLevel
126
111
}
127
112
}
128
113
129
- // If find_features is true this won't access `sess.crate_types` by assuming
130
- // that `is_pie_binary` is false. When we discover LLVM target features
131
- // `sess.crate_types` is uninitialized so we cannot access it.
114
+ fn to_llvm_relocation_model ( relocation_model : RelocModel ) -> llvm:: RelocModel {
115
+ match relocation_model {
116
+ RelocModel :: Static => llvm:: RelocModel :: Static ,
117
+ RelocModel :: Pic => llvm:: RelocModel :: PIC ,
118
+ RelocModel :: DynamicNoPic => llvm:: RelocModel :: DynamicNoPic ,
119
+ RelocModel :: Ropi => llvm:: RelocModel :: ROPI ,
120
+ RelocModel :: Rwpi => llvm:: RelocModel :: RWPI ,
121
+ RelocModel :: RopiRwpi => llvm:: RelocModel :: ROPI_RWPI ,
122
+ }
123
+ }
124
+
132
125
pub fn target_machine_factory (
133
126
sess : & Session ,
134
127
optlvl : config:: OptLevel ,
135
- find_features : bool ,
136
128
) -> Arc < dyn Fn ( ) -> Result < & ' static mut llvm:: TargetMachine , String > + Send + Sync > {
137
- let reloc_model = get_reloc_model ( sess) ;
129
+ let reloc_model = to_llvm_relocation_model ( sess. relocation_model ( ) ) ;
138
130
139
131
let ( opt_level, _) = to_llvm_opt_settings ( optlvl) ;
140
132
let use_softfp = sess. opts . cg . soft_float ;
@@ -175,7 +167,7 @@ pub fn target_machine_factory(
175
167
let features = features. join ( "," ) ;
176
168
let features = CString :: new ( features) . unwrap ( ) ;
177
169
let abi = SmallCStr :: new ( & sess. target . target . options . llvm_abiname ) ;
178
- let is_pie_binary = !find_features && is_pie_binary ( sess) ;
170
+ let pic_is_pie = all_outputs_are_pic_executables ( sess) ;
179
171
let trap_unreachable = sess. target . target . options . trap_unreachable ;
180
172
let emit_stack_size_section = sess. opts . debugging_opts . emit_stack_sizes ;
181
173
@@ -192,7 +184,7 @@ pub fn target_machine_factory(
192
184
reloc_model,
193
185
opt_level,
194
186
use_softfp,
195
- is_pie_binary ,
187
+ pic_is_pie ,
196
188
ffunction_sections,
197
189
fdata_sections,
198
190
trap_unreachable,
0 commit comments