@@ -171,15 +171,14 @@ pub trait Linker {
171
171
fn link_framework_by_name ( & mut self , _name : & str , _verbatim : bool , _as_needed : bool ) {
172
172
bug ! ( "framework linked with unsupported linker" )
173
173
}
174
- fn link_staticlib_by_name ( & mut self , name : & str , verbatim : bool ) ;
175
- fn link_whole_staticlib_by_name (
174
+ fn link_staticlib_by_name (
176
175
& mut self ,
177
176
name : & str ,
178
177
verbatim : bool ,
178
+ whole_archive : bool ,
179
179
search_paths : & SearchPaths ,
180
180
) ;
181
- fn link_staticlib_by_path ( & mut self , path : & Path ) ;
182
- fn link_whole_staticlib_by_path ( & mut self , path : & Path ) ;
181
+ fn link_staticlib_by_path ( & mut self , path : & Path , whole_archive : bool ) ;
183
182
fn include_path ( & mut self , path : & Path ) ;
184
183
fn framework_path ( & mut self , path : & Path ) ;
185
184
fn output_filename ( & mut self , path : & Path ) ;
@@ -482,26 +481,17 @@ impl<'a> Linker for GccLinker<'a> {
482
481
self . cmd . arg ( "-framework" ) . arg ( name) ;
483
482
}
484
483
485
- fn link_staticlib_by_name ( & mut self , name : & str , verbatim : bool ) {
486
- self . hint_static ( ) ;
487
- self . cmd . arg ( format ! ( "-l{}{name}" , if verbatim && self . is_gnu { ":" } else { "" } , ) ) ;
488
- }
489
-
490
- // Here we explicitly ask that the entire archive is included into the
491
- // result artifact. For more details see #15460, but the gist is that
492
- // the linker will strip away any unused objects in the archive if we
493
- // don't otherwise explicitly reference them. This can occur for
494
- // libraries which are just providing bindings, libraries with generic
495
- // functions, etc.
496
- fn link_whole_staticlib_by_name (
484
+ fn link_staticlib_by_name (
497
485
& mut self ,
498
486
name : & str ,
499
487
verbatim : bool ,
488
+ whole_archive : bool ,
500
489
search_paths : & SearchPaths ,
501
490
) {
502
491
self . hint_static ( ) ;
503
- let target = & self . sess . target ;
504
- if !target. is_like_osx {
492
+ if !whole_archive {
493
+ self . cmd . arg ( format ! ( "-l{}{name}" , if verbatim && self . is_gnu { ":" } else { "" } ) ) ;
494
+ } else if !self . sess . target . is_like_osx {
505
495
self . linker_arg ( "--whole-archive" ) ;
506
496
self . cmd . arg ( format ! ( "-l{}{name}" , if verbatim && self . is_gnu { ":" } else { "" } ) ) ;
507
497
self . linker_arg ( "--no-whole-archive" ) ;
@@ -515,14 +505,11 @@ impl<'a> Linker for GccLinker<'a> {
515
505
}
516
506
}
517
507
518
- fn link_staticlib_by_path ( & mut self , path : & Path ) {
508
+ fn link_staticlib_by_path ( & mut self , path : & Path , whole_archive : bool ) {
519
509
self . hint_static ( ) ;
520
- self . cmd . arg ( path) ;
521
- }
522
-
523
- fn link_whole_staticlib_by_path ( & mut self , path : & Path ) {
524
- self . hint_static ( ) ;
525
- if self . sess . target . is_like_osx {
510
+ if !whole_archive {
511
+ self . cmd . arg ( path) ;
512
+ } else if self . sess . target . is_like_osx {
526
513
self . linker_arg ( "-force_load" ) ;
527
514
self . linker_arg ( & path) ;
528
515
} else {
@@ -836,27 +823,28 @@ impl<'a> Linker for MsvcLinker<'a> {
836
823
self . cmd . arg ( format ! ( "{}{}" , name, if verbatim { "" } else { ".lib" } ) ) ;
837
824
}
838
825
839
- fn link_staticlib_by_name ( & mut self , name : & str , verbatim : bool ) {
840
- self . cmd . arg ( format ! ( "{}{}" , name, if verbatim { "" } else { ".lib" } ) ) ;
841
- }
842
-
843
- fn link_whole_staticlib_by_name (
826
+ fn link_staticlib_by_name (
844
827
& mut self ,
845
828
name : & str ,
846
829
verbatim : bool ,
830
+ whole_archive : bool ,
847
831
_search_paths : & SearchPaths ,
848
832
) {
849
- self . cmd . arg ( format ! ( "/WHOLEARCHIVE:{}{}" , name , if verbatim { "" } else { ".lib" } ) ) ;
850
- }
851
-
852
- fn link_staticlib_by_path ( & mut self , path : & Path ) {
853
- self . cmd . arg ( path ) ;
833
+ if !whole_archive {
834
+ self . cmd . arg ( format ! ( "{}{}" , name , if verbatim { "" } else { ".lib" } ) ) ;
835
+ } else {
836
+ self . cmd . arg ( format ! ( "/WHOLEARCHIVE:{}{}" , name , if verbatim { "" } else { ".lib" } ) ) ;
837
+ }
854
838
}
855
839
856
- fn link_whole_staticlib_by_path ( & mut self , path : & Path ) {
857
- let mut arg = OsString :: from ( "/WHOLEARCHIVE:" ) ;
858
- arg. push ( path) ;
859
- self . cmd . arg ( arg) ;
840
+ fn link_staticlib_by_path ( & mut self , path : & Path , whole_archive : bool ) {
841
+ if !whole_archive {
842
+ self . cmd . arg ( path) ;
843
+ } else {
844
+ let mut arg = OsString :: from ( "/WHOLEARCHIVE:" ) ;
845
+ arg. push ( path) ;
846
+ self . cmd . arg ( arg) ;
847
+ }
860
848
}
861
849
862
850
fn add_object ( & mut self , path : & Path ) {
@@ -1062,34 +1050,25 @@ impl<'a> Linker for EmLinker<'a> {
1062
1050
1063
1051
fn set_output_kind ( & mut self , _output_kind : LinkOutputKind , _out_filename : & Path ) { }
1064
1052
1065
- fn link_dylib_by_name ( & mut self , name : & str , verbatim : bool , _as_needed : bool ) {
1053
+ fn link_dylib_by_name ( & mut self , name : & str , _verbatim : bool , _as_needed : bool ) {
1066
1054
// Emscripten always links statically
1067
- self . link_staticlib_by_name ( name, verbatim) ;
1068
- }
1069
-
1070
- fn link_staticlib_by_name ( & mut self , name : & str , _verbatim : bool ) {
1071
1055
self . cmd . arg ( "-l" ) . arg ( name) ;
1072
1056
}
1073
1057
1074
- fn link_whole_staticlib_by_name (
1058
+ fn link_staticlib_by_name (
1075
1059
& mut self ,
1076
1060
name : & str ,
1077
- verbatim : bool ,
1061
+ _verbatim : bool ,
1062
+ _whole_archive : bool ,
1078
1063
_search_paths : & SearchPaths ,
1079
1064
) {
1080
- // not supported?
1081
- self . link_staticlib_by_name ( name, verbatim) ;
1065
+ self . cmd . arg ( "-l" ) . arg ( name) ;
1082
1066
}
1083
1067
1084
- fn link_staticlib_by_path ( & mut self , path : & Path ) {
1068
+ fn link_staticlib_by_path ( & mut self , path : & Path , _whole_archive : bool ) {
1085
1069
self . add_object ( path) ;
1086
1070
}
1087
1071
1088
- fn link_whole_staticlib_by_path ( & mut self , path : & Path ) {
1089
- // not supported?
1090
- self . link_staticlib_by_path ( path) ;
1091
- }
1092
-
1093
1072
fn include_path ( & mut self , path : & Path ) {
1094
1073
self . cmd . arg ( "-L" ) . arg ( path) ;
1095
1074
}
@@ -1255,25 +1234,26 @@ impl<'a> Linker for WasmLd<'a> {
1255
1234
self . cmd . arg ( "-l" ) . arg ( name) ;
1256
1235
}
1257
1236
1258
- fn link_staticlib_by_name ( & mut self , name : & str , _verbatim : bool ) {
1259
- self . cmd . arg ( "-l" ) . arg ( name) ;
1260
- }
1261
-
1262
- fn link_whole_staticlib_by_name (
1237
+ fn link_staticlib_by_name (
1263
1238
& mut self ,
1264
1239
name : & str ,
1265
1240
_verbatim : bool ,
1241
+ whole_archive : bool ,
1266
1242
_search_paths : & SearchPaths ,
1267
1243
) {
1268
- self . cmd . arg ( "--whole-archive" ) . arg ( "-l" ) . arg ( name ) . arg ( "--no-whole-archive" ) ;
1269
- }
1270
-
1271
- fn link_staticlib_by_path ( & mut self , path : & Path ) {
1272
- self . cmd . arg ( path ) ;
1244
+ if !whole_archive {
1245
+ self . cmd . arg ( "-l" ) . arg ( name ) ;
1246
+ } else {
1247
+ self . cmd . arg ( "--whole-archive" ) . arg ( "-l" ) . arg ( name ) . arg ( "--no-whole-archive" ) ;
1248
+ }
1273
1249
}
1274
1250
1275
- fn link_whole_staticlib_by_path ( & mut self , path : & Path ) {
1276
- self . cmd . arg ( "--whole-archive" ) . arg ( path) . arg ( "--no-whole-archive" ) ;
1251
+ fn link_staticlib_by_path ( & mut self , path : & Path , whole_archive : bool ) {
1252
+ if !whole_archive {
1253
+ self . cmd . arg ( path) ;
1254
+ } else {
1255
+ self . cmd . arg ( "--whole-archive" ) . arg ( path) . arg ( "--no-whole-archive" ) ;
1256
+ }
1277
1257
}
1278
1258
1279
1259
fn include_path ( & mut self , path : & Path ) {
@@ -1407,30 +1387,29 @@ impl<'a> Linker for L4Bender<'a> {
1407
1387
bug ! ( "dylibs are not supported on L4Re" ) ;
1408
1388
}
1409
1389
1410
- fn link_staticlib_by_name ( & mut self , name : & str , _verbatim : bool ) {
1411
- self . hint_static ( ) ;
1412
- self . cmd . arg ( format ! ( "-PC{name}" ) ) ;
1413
- }
1414
-
1415
- fn link_whole_staticlib_by_name (
1390
+ fn link_staticlib_by_name (
1416
1391
& mut self ,
1417
1392
name : & str ,
1418
1393
_verbatim : bool ,
1394
+ whole_archive : bool ,
1419
1395
_search_paths : & SearchPaths ,
1420
1396
) {
1421
1397
self . hint_static ( ) ;
1422
- self . cmd . arg ( "--whole-archive" ) . arg ( format ! ( "-l{name}" ) ) ;
1423
- self . cmd . arg ( "--no-whole-archive" ) ;
1424
- }
1425
-
1426
- fn link_staticlib_by_path ( & mut self , path : & Path ) {
1427
- self . hint_static ( ) ;
1428
- self . cmd . arg ( path) ;
1398
+ if !whole_archive {
1399
+ self . cmd . arg ( format ! ( "-PC{name}" ) ) ;
1400
+ } else {
1401
+ self . cmd . arg ( "--whole-archive" ) . arg ( format ! ( "-l{name}" ) ) ;
1402
+ self . cmd . arg ( "--no-whole-archive" ) ;
1403
+ }
1429
1404
}
1430
1405
1431
- fn link_whole_staticlib_by_path ( & mut self , path : & Path ) {
1406
+ fn link_staticlib_by_path ( & mut self , path : & Path , whole_archive : bool ) {
1432
1407
self . hint_static ( ) ;
1433
- self . cmd . arg ( "--whole-archive" ) . arg ( path) . arg ( "--no-whole-archive" ) ;
1408
+ if !whole_archive {
1409
+ self . cmd . arg ( path) ;
1410
+ } else {
1411
+ self . cmd . arg ( "--whole-archive" ) . arg ( path) . arg ( "--no-whole-archive" ) ;
1412
+ }
1434
1413
}
1435
1414
1436
1415
fn include_path ( & mut self , path : & Path ) {
@@ -1593,31 +1572,30 @@ impl<'a> Linker for AixLinker<'a> {
1593
1572
self . cmd . arg ( format ! ( "-l{name}" ) ) ;
1594
1573
}
1595
1574
1596
- fn link_staticlib_by_name ( & mut self , name : & str , _verbatim : bool ) {
1597
- self . hint_static ( ) ;
1598
- self . cmd . arg ( format ! ( "-l{name}" ) ) ;
1599
- }
1600
-
1601
- fn link_whole_staticlib_by_name (
1575
+ fn link_staticlib_by_name (
1602
1576
& mut self ,
1603
1577
name : & str ,
1604
1578
verbatim : bool ,
1579
+ whole_archive : bool ,
1605
1580
search_paths : & SearchPaths ,
1606
1581
) {
1607
1582
self . hint_static ( ) ;
1608
- let lib =
1609
- find_native_static_library ( name, verbatim, search_paths. get ( self . sess ) , self . sess ) ;
1610
- self . cmd . arg ( format ! ( "-bkeepfile:{}" , lib. to_str( ) . unwrap( ) ) ) ;
1611
- }
1612
-
1613
- fn link_staticlib_by_path ( & mut self , path : & Path ) {
1614
- self . hint_static ( ) ;
1615
- self . cmd . arg ( path) ;
1583
+ if !whole_archive {
1584
+ self . cmd . arg ( format ! ( "-l{name}" ) ) ;
1585
+ } else {
1586
+ let lib =
1587
+ find_native_static_library ( name, verbatim, search_paths. get ( self . sess ) , self . sess ) ;
1588
+ self . cmd . arg ( format ! ( "-bkeepfile:{}" , lib. to_str( ) . unwrap( ) ) ) ;
1589
+ }
1616
1590
}
1617
1591
1618
- fn link_whole_staticlib_by_path ( & mut self , path : & Path ) {
1592
+ fn link_staticlib_by_path ( & mut self , path : & Path , whole_archive : bool ) {
1619
1593
self . hint_static ( ) ;
1620
- self . cmd . arg ( format ! ( "-bkeepfile:{}" , path. to_str( ) . unwrap( ) ) ) ;
1594
+ if !whole_archive {
1595
+ self . cmd . arg ( path) ;
1596
+ } else {
1597
+ self . cmd . arg ( format ! ( "-bkeepfile:{}" , path. to_str( ) . unwrap( ) ) ) ;
1598
+ }
1621
1599
}
1622
1600
1623
1601
fn include_path ( & mut self , path : & Path ) {
@@ -1810,24 +1788,17 @@ impl<'a> Linker for PtxLinker<'a> {
1810
1788
panic ! ( "external dylibs not supported" )
1811
1789
}
1812
1790
1813
- fn link_staticlib_by_name ( & mut self , _name : & str , _verbatim : bool ) {
1814
- panic ! ( "staticlibs not supported" )
1815
- }
1816
-
1817
- fn link_whole_staticlib_by_name (
1791
+ fn link_staticlib_by_name (
1818
1792
& mut self ,
1819
1793
_name : & str ,
1820
1794
_verbatim : bool ,
1795
+ _whole_archive : bool ,
1821
1796
_search_paths : & SearchPaths ,
1822
1797
) {
1823
1798
panic ! ( "staticlibs not supported" )
1824
1799
}
1825
1800
1826
- fn link_staticlib_by_path ( & mut self , path : & Path ) {
1827
- self . cmd . arg ( "--rlib" ) . arg ( path) ;
1828
- }
1829
-
1830
- fn link_whole_staticlib_by_path ( & mut self , path : & Path ) {
1801
+ fn link_staticlib_by_path ( & mut self , path : & Path , _whole_archive : bool ) {
1831
1802
self . cmd . arg ( "--rlib" ) . arg ( path) ;
1832
1803
}
1833
1804
@@ -1904,24 +1875,17 @@ impl<'a> Linker for BpfLinker<'a> {
1904
1875
panic ! ( "external dylibs not supported" )
1905
1876
}
1906
1877
1907
- fn link_staticlib_by_name ( & mut self , _name : & str , _verbatim : bool ) {
1908
- panic ! ( "staticlibs not supported" )
1909
- }
1910
-
1911
- fn link_whole_staticlib_by_name (
1878
+ fn link_staticlib_by_name (
1912
1879
& mut self ,
1913
1880
_name : & str ,
1914
1881
_verbatim : bool ,
1882
+ _whole_archive : bool ,
1915
1883
_search_paths : & SearchPaths ,
1916
1884
) {
1917
1885
panic ! ( "staticlibs not supported" )
1918
1886
}
1919
1887
1920
- fn link_staticlib_by_path ( & mut self , path : & Path ) {
1921
- self . cmd . arg ( path) ;
1922
- }
1923
-
1924
- fn link_whole_staticlib_by_path ( & mut self , path : & Path ) {
1888
+ fn link_staticlib_by_path ( & mut self , path : & Path , _whole_archive : bool ) {
1925
1889
self . cmd . arg ( path) ;
1926
1890
}
1927
1891
0 commit comments