@@ -987,7 +987,7 @@ fn get_crt_libs_path(sess: &Session) -> Option<PathBuf> {
987
987
}
988
988
}
989
989
990
- pub fn get_file_path ( sess : & Session , name : & str ) -> PathBuf {
990
+ fn get_object_file_path ( sess : & Session , name : & str ) -> PathBuf {
991
991
// prefer system {,dll}crt2.o libs, see get_crt_libs_path comment for more details
992
992
if sess. target . target . llvm_target . contains ( "windows-gnu" ) {
993
993
if let Some ( compiler_libs_path) = get_crt_libs_path ( sess) {
@@ -1159,6 +1159,36 @@ pub fn exec_linker(
1159
1159
}
1160
1160
}
1161
1161
1162
+ /// Add begin object files defined by the target spec.
1163
+ fn add_pre_link_objects ( cmd : & mut dyn Linker , sess : & ' a Session , crate_type : config:: CrateType ) {
1164
+ let pre_link_objects = if crate_type == config:: CrateType :: Executable {
1165
+ & sess. target . target . options . pre_link_objects_exe
1166
+ } else {
1167
+ & sess. target . target . options . pre_link_objects_dll
1168
+ } ;
1169
+ for obj in pre_link_objects {
1170
+ cmd. add_object ( & get_object_file_path ( sess, obj) ) ;
1171
+ }
1172
+
1173
+ if crate_type == config:: CrateType :: Executable && sess. crt_static ( Some ( crate_type) ) {
1174
+ for obj in & sess. target . target . options . pre_link_objects_exe_crt {
1175
+ cmd. add_object ( & get_object_file_path ( sess, obj) ) ;
1176
+ }
1177
+ }
1178
+ }
1179
+
1180
+ /// Add end object files defined by the target spec.
1181
+ fn add_post_link_objects ( cmd : & mut dyn Linker , sess : & ' a Session , crate_type : config:: CrateType ) {
1182
+ for obj in & sess. target . target . options . post_link_objects {
1183
+ cmd. add_object ( & get_object_file_path ( sess, obj) ) ;
1184
+ }
1185
+ if sess. crt_static ( Some ( crate_type) ) {
1186
+ for obj in & sess. target . target . options . post_link_objects_crt {
1187
+ cmd. add_object ( & get_object_file_path ( sess, obj) ) ;
1188
+ }
1189
+ }
1190
+ }
1191
+
1162
1192
fn linker_with_args < ' a , B : ArchiveBuilder < ' a > > (
1163
1193
path : & Path ,
1164
1194
flavor : LinkerFlavor ,
@@ -1193,20 +1223,8 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
1193
1223
cmd. arg ( format ! ( "--dynamic-linker={}ld.so.1" , prefix) ) ;
1194
1224
}
1195
1225
1196
- let pre_link_objects = if crate_type == config:: CrateType :: Executable {
1197
- & sess. target . target . options . pre_link_objects_exe
1198
- } else {
1199
- & sess. target . target . options . pre_link_objects_dll
1200
- } ;
1201
- for obj in pre_link_objects {
1202
- cmd. arg ( get_file_path ( sess, obj) ) ;
1203
- }
1204
-
1205
- if crate_type == config:: CrateType :: Executable && sess. crt_static ( Some ( crate_type) ) {
1206
- for obj in & sess. target . target . options . pre_link_objects_exe_crt {
1207
- cmd. arg ( get_file_path ( sess, obj) ) ;
1208
- }
1209
- }
1226
+ // NO-OPT-OUT
1227
+ add_pre_link_objects ( cmd, sess, crate_type) ;
1210
1228
1211
1229
if sess. target . target . options . is_like_emscripten {
1212
1230
cmd. arg ( "-s" ) ;
@@ -1436,14 +1454,10 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
1436
1454
cmd. args ( args) ;
1437
1455
}
1438
1456
}
1439
- for obj in & sess. target . target . options . post_link_objects {
1440
- cmd. arg ( get_file_path ( sess, obj) ) ;
1441
- }
1442
- if sess. crt_static ( Some ( crate_type) ) {
1443
- for obj in & sess. target . target . options . post_link_objects_crt {
1444
- cmd. arg ( get_file_path ( sess, obj) ) ;
1445
- }
1446
- }
1457
+
1458
+ // NO-OPT-OUT
1459
+ add_post_link_objects ( cmd, sess, crate_type) ;
1460
+
1447
1461
if let Some ( args) = sess. target . target . options . post_link_args . get ( & flavor) {
1448
1462
cmd. args ( args) ;
1449
1463
}
0 commit comments