@@ -154,7 +154,7 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(
154
154
// The third parameter is for env vars, used on windows to set up the
155
155
// path for MSVC to find its DLLs, and gcc to find its bundled
156
156
// toolchain
157
- pub fn get_linker ( sess : & Session , linker : & Path , flavor : LinkerFlavor ) -> Command {
157
+ fn get_linker ( sess : & Session , linker : & Path , flavor : LinkerFlavor ) -> Command {
158
158
let msvc_tool = windows_registry:: find_tool ( & sess. opts . target_triple . triple ( ) , "link.exe" ) ;
159
159
160
160
// If our linker looks like a batch script on Windows then to execute this
@@ -285,11 +285,7 @@ pub fn each_linked_rlib(
285
285
/// building an `.rlib` (stomping over one another), or writing an `.rmeta` into a
286
286
/// directory being searched for `extern crate` (observing an incomplete file).
287
287
/// The returned path is the temporary file containing the complete metadata.
288
- pub fn emit_metadata < ' a > (
289
- sess : & ' a Session ,
290
- metadata : & EncodedMetadata ,
291
- tmpdir : & TempDir ,
292
- ) -> PathBuf {
288
+ pub fn emit_metadata ( sess : & Session , metadata : & EncodedMetadata , tmpdir : & TempDir ) -> PathBuf {
293
289
let out_filename = tmpdir. path ( ) . join ( METADATA_FILENAME ) ;
294
290
let result = fs:: write ( & out_filename, & metadata. raw_data ) ;
295
291
@@ -744,7 +740,7 @@ pub fn ignored_for_lto(sess: &Session, info: &CrateInfo, cnum: CrateNum) -> bool
744
740
&& ( info. compiler_builtins == Some ( cnum) || info. is_no_builtins . contains ( & cnum) )
745
741
}
746
742
747
- pub fn linker_and_flavor ( sess : & Session ) -> ( PathBuf , LinkerFlavor ) {
743
+ fn linker_and_flavor ( sess : & Session ) -> ( PathBuf , LinkerFlavor ) {
748
744
fn infer_from (
749
745
sess : & Session ,
750
746
linker : Option < PathBuf > ,
@@ -832,7 +828,7 @@ pub fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
832
828
/// Returns a boolean indicating whether we should preserve the object files on
833
829
/// the filesystem for their debug information. This is often useful with
834
830
/// split-dwarf like schemes.
835
- pub fn preserve_objects_for_their_debuginfo ( sess : & Session ) -> bool {
831
+ fn preserve_objects_for_their_debuginfo ( sess : & Session ) -> bool {
836
832
// If the objects don't have debuginfo there's nothing to preserve.
837
833
if sess. opts . debuginfo == config:: DebugInfo :: None {
838
834
return false ;
@@ -886,7 +882,7 @@ enum RlibFlavor {
886
882
StaticlibBase ,
887
883
}
888
884
889
- pub fn print_native_static_libs ( sess : & Session , all_native_libs : & [ NativeLibrary ] ) {
885
+ fn print_native_static_libs ( sess : & Session , all_native_libs : & [ NativeLibrary ] ) {
890
886
let lib_args: Vec < _ > = all_native_libs
891
887
. iter ( )
892
888
. filter ( |l| relevant_lib ( sess, l) )
@@ -1012,7 +1008,7 @@ fn get_object_file_path(sess: &Session, name: &str) -> PathBuf {
1012
1008
PathBuf :: from ( name)
1013
1009
}
1014
1010
1015
- pub fn exec_linker (
1011
+ fn exec_linker (
1016
1012
sess : & Session ,
1017
1013
cmd : & Command ,
1018
1014
out_filename : & Path ,
@@ -1161,7 +1157,7 @@ pub fn exec_linker(
1161
1157
}
1162
1158
1163
1159
/// Add begin object files defined by the target spec.
1164
- fn add_pre_link_objects ( cmd : & mut dyn Linker , sess : & ' a Session , crate_type : config:: CrateType ) {
1160
+ fn add_pre_link_objects ( cmd : & mut dyn Linker , sess : & Session , crate_type : config:: CrateType ) {
1165
1161
let pre_link_objects = if crate_type == config:: CrateType :: Executable {
1166
1162
& sess. target . target . options . pre_link_objects_exe
1167
1163
} else {
@@ -1179,7 +1175,7 @@ fn add_pre_link_objects(cmd: &mut dyn Linker, sess: &'a Session, crate_type: con
1179
1175
}
1180
1176
1181
1177
/// Add end object files defined by the target spec.
1182
- fn add_post_link_objects ( cmd : & mut dyn Linker , sess : & ' a Session , crate_type : config:: CrateType ) {
1178
+ fn add_post_link_objects ( cmd : & mut dyn Linker , sess : & Session , crate_type : config:: CrateType ) {
1183
1179
for obj in & sess. target . target . options . post_link_objects {
1184
1180
cmd. add_object ( & get_object_file_path ( sess, obj) ) ;
1185
1181
}
@@ -1194,7 +1190,7 @@ fn add_post_link_objects(cmd: &mut dyn Linker, sess: &'a Session, crate_type: co
1194
1190
/// FIXME: Determine where exactly these args need to be inserted.
1195
1191
fn add_pre_link_args (
1196
1192
cmd : & mut dyn Linker ,
1197
- sess : & ' a Session ,
1193
+ sess : & Session ,
1198
1194
flavor : LinkerFlavor ,
1199
1195
crate_type : config:: CrateType ,
1200
1196
) {
@@ -1213,7 +1209,7 @@ fn add_pre_link_args(
1213
1209
/// FIXME: Determine where exactly these args need to be inserted.
1214
1210
fn add_user_defined_link_args (
1215
1211
cmd : & mut dyn Linker ,
1216
- sess : & ' a Session ,
1212
+ sess : & Session ,
1217
1213
codegen_results : & CodegenResults ,
1218
1214
) {
1219
1215
cmd. args ( & sess. opts . cg . link_args ) ;
@@ -1224,7 +1220,7 @@ fn add_user_defined_link_args(
1224
1220
/// FIXME: Determine where exactly these args need to be inserted.
1225
1221
fn add_late_link_args (
1226
1222
cmd : & mut dyn Linker ,
1227
- sess : & ' a Session ,
1223
+ sess : & Session ,
1228
1224
flavor : LinkerFlavor ,
1229
1225
crate_type : config:: CrateType ,
1230
1226
codegen_results : & CodegenResults ,
@@ -1249,7 +1245,7 @@ fn add_late_link_args(
1249
1245
1250
1246
/// Add arbitrary "post-link" args defined by the target spec.
1251
1247
/// FIXME: Determine where exactly these args need to be inserted.
1252
- fn add_post_link_args ( cmd : & mut dyn Linker , sess : & ' a Session , flavor : LinkerFlavor ) {
1248
+ fn add_post_link_args ( cmd : & mut dyn Linker , sess : & Session , flavor : LinkerFlavor ) {
1253
1249
if let Some ( args) = sess. target . target . options . post_link_args . get ( & flavor) {
1254
1250
cmd. args ( args) ;
1255
1251
}
@@ -1264,8 +1260,7 @@ fn add_local_crate_regular_objects(cmd: &mut dyn Linker, codegen_results: &Codeg
1264
1260
1265
1261
/// Add object files for allocator code linked once for the whole crate tree.
1266
1262
fn add_local_crate_allocator_objects ( cmd : & mut dyn Linker , codegen_results : & CodegenResults ) {
1267
- let obj = codegen_results. allocator_module . as_ref ( ) . and_then ( |m| m. object . as_ref ( ) ) ;
1268
- if let Some ( obj) = obj {
1263
+ if let Some ( obj) = codegen_results. allocator_module . as_ref ( ) . and_then ( |m| m. object . as_ref ( ) ) {
1269
1264
cmd. add_object ( obj) ;
1270
1265
}
1271
1266
}
@@ -1280,8 +1275,8 @@ fn add_local_crate_metadata_objects(
1280
1275
// executable. This metadata is in a separate object file from the main
1281
1276
// object file, so we link that in here.
1282
1277
if crate_type == config:: CrateType :: Dylib || crate_type == config:: CrateType :: ProcMacro {
1283
- let obj = codegen_results. metadata_module . as_ref ( ) . and_then ( |m| m. object . as_ref ( ) ) ;
1284
- if let Some ( obj ) = obj {
1278
+ if let Some ( obj) = codegen_results. metadata_module . as_ref ( ) . and_then ( |m| m. object . as_ref ( ) )
1279
+ {
1285
1280
cmd. add_object ( obj) ;
1286
1281
}
1287
1282
}
@@ -1337,25 +1332,24 @@ fn link_local_crate_native_libs_and_dependent_crate_libs<'a, B: ArchiveBuilder<'
1337
1332
}
1338
1333
1339
1334
/// Add sysroot and other globally set directories to the directory search list.
1340
- fn add_library_search_dirs ( cmd : & mut dyn Linker , sess : & ' a Session ) {
1341
- // The default library location, we need this to find the runtime.
1342
- // The location of crates will be determined as needed.
1343
- let lib_path = sess. target_filesearch ( PathKind :: All ) . get_lib_path ( ) ;
1344
-
1345
- // prefer system mingw-w64 libs, see get_crt_libs_path comment for more details
1335
+ fn add_library_search_dirs ( cmd : & mut dyn Linker , sess : & Session ) {
1336
+ // Prefer system mingw-w64 libs, see get_crt_libs_path comment for more details.
1346
1337
if cfg ! ( windows) && sess. target . target . llvm_target . contains ( "windows-gnu" ) {
1347
1338
if let Some ( compiler_libs_path) = get_crt_libs_path ( sess) {
1348
1339
cmd. include_path ( & compiler_libs_path) ;
1349
1340
}
1350
1341
}
1351
1342
1343
+ // The default library location, we need this to find the runtime.
1344
+ // The location of crates will be determined as needed.
1345
+ let lib_path = sess. target_filesearch ( PathKind :: All ) . get_lib_path ( ) ;
1352
1346
cmd. include_path ( & fix_windows_verbatim_for_gcc ( & lib_path) ) ;
1353
1347
}
1354
1348
1355
1349
/// Add options requesting executables to be position-independent or not position-independent.
1356
1350
fn add_position_independent_executable_args (
1357
1351
cmd : & mut dyn Linker ,
1358
- sess : & ' a Session ,
1352
+ sess : & Session ,
1359
1353
flavor : LinkerFlavor ,
1360
1354
crate_type : config:: CrateType ,
1361
1355
codegen_results : & CodegenResults ,
@@ -1364,55 +1358,41 @@ fn add_position_independent_executable_args(
1364
1358
return ;
1365
1359
}
1366
1360
1367
- let mut position_independent_executable = false ;
1368
1361
if sess. target . target . options . position_independent_executables {
1369
1362
let attr_link_args = & * codegen_results. crate_info . link_args ;
1370
1363
let mut user_defined_link_args = sess. opts . cg . link_args . iter ( ) . chain ( attr_link_args) ;
1371
1364
if is_pic ( sess)
1372
1365
&& !sess. crt_static ( Some ( crate_type) )
1373
1366
&& !user_defined_link_args. any ( |x| x == "-static" )
1374
1367
{
1375
- position_independent_executable = true ;
1368
+ cmd. position_independent_executable ( ) ;
1369
+ return ;
1376
1370
}
1377
1371
}
1378
1372
1379
- if position_independent_executable {
1380
- cmd. position_independent_executable ( ) ;
1381
- } else {
1382
- // recent versions of gcc can be configured to generate position
1383
- // independent executables by default. We have to pass -no-pie to
1384
- // explicitly turn that off. Not applicable to ld.
1385
- if sess. target . target . options . linker_is_gnu && flavor != LinkerFlavor :: Ld {
1386
- cmd. no_position_independent_executable ( ) ;
1387
- }
1373
+ // Recent versions of gcc can be configured to generate position
1374
+ // independent executables by default. We have to pass -no-pie to
1375
+ // explicitly turn that off. Not applicable to ld.
1376
+ if sess. target . target . options . linker_is_gnu && flavor != LinkerFlavor :: Ld {
1377
+ cmd. no_position_independent_executable ( ) ;
1388
1378
}
1389
1379
}
1390
1380
1391
1381
/// Add options making relocation sections in the produced ELF files read-only
1392
1382
/// and suppressing lazy binding.
1393
- fn add_relro_args ( cmd : & mut dyn Linker , sess : & ' a Session ) {
1394
- let relro_level = match sess. opts . debugging_opts . relro_level {
1395
- Some ( level) => level,
1396
- None => sess. target . target . options . relro_level ,
1397
- } ;
1398
- match relro_level {
1399
- RelroLevel :: Full => {
1400
- cmd. full_relro ( ) ;
1401
- }
1402
- RelroLevel :: Partial => {
1403
- cmd. partial_relro ( ) ;
1404
- }
1405
- RelroLevel :: Off => {
1406
- cmd. no_relro ( ) ;
1407
- }
1383
+ fn add_relro_args ( cmd : & mut dyn Linker , sess : & Session ) {
1384
+ match sess. opts . debugging_opts . relro_level . unwrap_or ( sess. target . target . options . relro_level ) {
1385
+ RelroLevel :: Full => cmd. full_relro ( ) ,
1386
+ RelroLevel :: Partial => cmd. partial_relro ( ) ,
1387
+ RelroLevel :: Off => cmd. no_relro ( ) ,
1408
1388
RelroLevel :: None => { }
1409
1389
}
1410
1390
}
1411
1391
1412
1392
/// Add library search paths used at runtime by dynamic linkers.
1413
1393
fn add_rpath_args (
1414
1394
cmd : & mut dyn Linker ,
1415
- sess : & ' a Session ,
1395
+ sess : & Session ,
1416
1396
codegen_results : & CodegenResults ,
1417
1397
out_filename : & Path ,
1418
1398
) {
@@ -1623,7 +1603,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
1623
1603
// Also note that the native libraries linked here are only the ones located
1624
1604
// in the current crate. Upstream crates with native library dependencies
1625
1605
// may have their native library pulled in above.
1626
- pub fn add_local_native_libraries (
1606
+ fn add_local_native_libraries (
1627
1607
cmd : & mut dyn Linker ,
1628
1608
sess : & Session ,
1629
1609
codegen_results : & CodegenResults ,
@@ -1953,7 +1933,7 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
1953
1933
// generic function calls a native function, then the generic function must
1954
1934
// be instantiated in the target crate, meaning that the native symbol must
1955
1935
// also be resolved in the target crate.
1956
- pub fn add_upstream_native_libraries (
1936
+ fn add_upstream_native_libraries (
1957
1937
cmd : & mut dyn Linker ,
1958
1938
sess : & Session ,
1959
1939
codegen_results : & CodegenResults ,
@@ -2010,14 +1990,14 @@ pub fn add_upstream_native_libraries(
2010
1990
}
2011
1991
}
2012
1992
2013
- pub fn relevant_lib ( sess : & Session , lib : & NativeLibrary ) -> bool {
1993
+ fn relevant_lib ( sess : & Session , lib : & NativeLibrary ) -> bool {
2014
1994
match lib. cfg {
2015
1995
Some ( ref cfg) => rustc_attr:: cfg_matches ( cfg, & sess. parse_sess , None ) ,
2016
1996
None => true ,
2017
1997
}
2018
1998
}
2019
1999
2020
- pub fn are_upstream_rust_objects_already_included ( sess : & Session ) -> bool {
2000
+ fn are_upstream_rust_objects_already_included ( sess : & Session ) -> bool {
2021
2001
match sess. lto ( ) {
2022
2002
config:: Lto :: Fat => true ,
2023
2003
config:: Lto :: Thin => {
0 commit comments