@@ -2,8 +2,6 @@ use super::archive::LlvmArchiveBuilder;
2
2
use super :: rpath:: RPathConfig ;
3
3
use super :: rpath;
4
4
use crate :: back:: wasm;
5
- use crate :: context:: get_reloc_model;
6
- use crate :: llvm;
7
5
use rustc_codegen_ssa:: { METADATA_FILENAME , RLIB_BYTECODE_EXTENSION } ;
8
6
use rustc_codegen_ssa:: back:: archive:: ArchiveBuilder ;
9
7
use rustc_codegen_ssa:: back:: linker:: Linker ;
@@ -40,6 +38,7 @@ pub(crate) fn link_binary<'a>(sess: &'a Session,
40
38
codegen_results : & CodegenResults ,
41
39
outputs : & OutputFilenames ,
42
40
crate_name : & str ) -> Vec < PathBuf > {
41
+ let target_cpu = crate :: llvm_util:: target_cpu ( sess) ;
43
42
let mut out_filenames = Vec :: new ( ) ;
44
43
for & crate_type in sess. crate_types . borrow ( ) . iter ( ) {
45
44
// Ignore executable crates if we have -Z no-codegen, as they will error.
@@ -58,7 +57,8 @@ pub(crate) fn link_binary<'a>(sess: &'a Session,
58
57
codegen_results,
59
58
crate_type,
60
59
outputs,
61
- crate_name) ;
60
+ crate_name,
61
+ target_cpu) ;
62
62
out_filenames. extend ( out_files) ;
63
63
}
64
64
@@ -92,7 +92,8 @@ fn link_binary_output<'a, B: ArchiveBuilder<'a>>(sess: &'a Session,
92
92
codegen_results : & CodegenResults ,
93
93
crate_type : config:: CrateType ,
94
94
outputs : & OutputFilenames ,
95
- crate_name : & str ) -> Vec < PathBuf > {
95
+ crate_name : & str ,
96
+ target_cpu : & str ) -> Vec < PathBuf > {
96
97
for obj in codegen_results. modules . iter ( ) . filter_map ( |m| m. object . as_ref ( ) ) {
97
98
check_file_is_writeable ( obj, sess) ;
98
99
}
@@ -134,7 +135,7 @@ fn link_binary_output<'a, B: ArchiveBuilder<'a>>(sess: &'a Session,
134
135
link_staticlib :: < B > ( sess, codegen_results, & out_filename, & tmpdir) ;
135
136
}
136
137
_ => {
137
- link_natively :: < B > ( sess, crate_type, & out_filename, codegen_results, tmpdir. path ( ) ) ;
138
+ link_natively :: < B > ( sess, crate_type, & out_filename, codegen_results, tmpdir. path ( ) , target_cpu ) ;
138
139
}
139
140
}
140
141
out_filenames. push ( out_filename) ;
@@ -167,11 +168,6 @@ fn emit_metadata<'a>(
167
168
out_filename
168
169
}
169
170
170
- enum RlibFlavor {
171
- Normal ,
172
- StaticlibBase ,
173
- }
174
-
175
171
// Create an 'rlib'
176
172
//
177
173
// An rlib in its current incarnation is essentially a renamed .a file. The
@@ -354,7 +350,8 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(sess: &'a Session,
354
350
crate_type : config:: CrateType ,
355
351
out_filename : & Path ,
356
352
codegen_results : & CodegenResults ,
357
- tmpdir : & Path ) {
353
+ tmpdir : & Path ,
354
+ target_cpu : & str ) {
358
355
info ! ( "preparing {:?} to {:?}" , crate_type, out_filename) ;
359
356
let ( linker, flavor) = linker_and_flavor ( sess) ;
360
357
@@ -407,7 +404,6 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(sess: &'a Session,
407
404
}
408
405
409
406
{
410
- let target_cpu = crate :: llvm_util:: target_cpu ( sess) ;
411
407
let mut linker = codegen_results. linker_info . to_linker ( cmd, & sess, flavor, target_cpu) ;
412
408
link_args :: < B > ( & mut * linker, flavor, sess, crate_type, tmpdir,
413
409
out_filename, codegen_results) ;
@@ -663,8 +659,7 @@ fn link_args<'a, B: ArchiveBuilder<'a>>(cmd: &mut dyn Linker,
663
659
let more_args = & sess. opts . cg . link_arg ;
664
660
let mut args = args. iter ( ) . chain ( more_args. iter ( ) ) . chain ( used_link_args. iter ( ) ) ;
665
661
666
- if get_reloc_model ( sess) == llvm:: RelocMode :: PIC
667
- && !sess. crt_static ( ) && !args. any ( |x| * x == "-static" ) {
662
+ if is_pic ( sess) && !sess. crt_static ( ) && !args. any ( |x| * x == "-static" ) {
668
663
position_independent_executable = true ;
669
664
}
670
665
}
@@ -1106,3 +1101,12 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(cmd: &mut dyn Linker,
1106
1101
parent. unwrap_or ( Path :: new ( "" ) ) ) ;
1107
1102
}
1108
1103
}
1104
+
1105
+ fn is_pic ( sess : & Session ) -> bool {
1106
+ let reloc_model_arg = match sess. opts . cg . relocation_model {
1107
+ Some ( ref s) => & s[ ..] ,
1108
+ None => & sess. target . target . options . relocation_model [ ..] ,
1109
+ } ;
1110
+
1111
+ reloc_model_arg == "pic"
1112
+ }
0 commit comments