@@ -7,7 +7,7 @@ use crate::back::profiling::{
77use crate :: base;
88use crate :: common;
99use crate :: consts;
10- use crate :: context:: { get_reloc_model , is_pie_binary} ;
10+ use crate :: context:: is_pie_binary;
1111use crate :: llvm:: { self , DiagnosticInfo , PassManager , SMDiagnostic } ;
1212use crate :: llvm_util;
1313use crate :: type_:: Type ;
@@ -25,6 +25,7 @@ use rustc_middle::bug;
2525use rustc_middle:: ty:: TyCtxt ;
2626use rustc_session:: config:: { self , Lto , OutputType , Passes , Sanitizer , SwitchWithOptPath } ;
2727use rustc_session:: Session ;
28+ use rustc_target:: spec:: RelocModel ;
2829
2930use libc:: { c_char, c_int, c_uint, c_void, size_t} ;
3031use std:: ffi:: CString ;
@@ -35,16 +36,6 @@ use std::slice;
3536use std:: str;
3637use std:: sync:: Arc ;
3738
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-
4839pub const CODE_GEN_MODEL_ARGS : & [ ( & str , llvm:: CodeModel ) ] = & [
4940 ( "small" , llvm:: CodeModel :: Small ) ,
5041 ( "kernel" , llvm:: CodeModel :: Kernel ) ,
@@ -126,6 +117,17 @@ fn to_pass_builder_opt_level(cfg: config::OptLevel) -> llvm::PassBuilderOptLevel
126117 }
127118}
128119
120+ fn to_llvm_relocation_model ( relocation_model : RelocModel ) -> llvm:: RelocMode {
121+ match relocation_model {
122+ RelocModel :: Static => llvm:: RelocMode :: Static ,
123+ RelocModel :: Pic => llvm:: RelocMode :: PIC ,
124+ RelocModel :: DynamicNoPic => llvm:: RelocMode :: DynamicNoPic ,
125+ RelocModel :: Ropi => llvm:: RelocMode :: ROPI ,
126+ RelocModel :: Rwpi => llvm:: RelocMode :: RWPI ,
127+ RelocModel :: RopiRwpi => llvm:: RelocMode :: ROPI_RWPI ,
128+ }
129+ }
130+
129131// If find_features is true this won't access `sess.crate_types` by assuming
130132// that `is_pie_binary` is false. When we discover LLVM target features
131133// `sess.crate_types` is uninitialized so we cannot access it.
@@ -134,7 +136,7 @@ pub fn target_machine_factory(
134136 optlvl : config:: OptLevel ,
135137 find_features : bool ,
136138) -> Arc < dyn Fn ( ) -> Result < & ' static mut llvm:: TargetMachine , String > + Send + Sync > {
137- let reloc_model = get_reloc_model ( sess) ;
139+ let reloc_model = to_llvm_relocation_model ( sess. relocation_model ( ) ) ;
138140
139141 let ( opt_level, _) = to_llvm_opt_settings ( optlvl) ;
140142 let use_softfp = sess. opts . cg . soft_float ;
0 commit comments