@@ -275,7 +275,12 @@ pub(crate) trait Linker {
275
275
fn is_cc ( & self ) -> bool {
276
276
false
277
277
}
278
- fn set_output_kind ( & mut self , output_kind : LinkOutputKind , out_filename : & Path ) ;
278
+ fn set_output_kind (
279
+ & mut self ,
280
+ output_kind : LinkOutputKind ,
281
+ crate_type : CrateType ,
282
+ out_filename : & Path ,
283
+ ) ;
279
284
fn link_dylib_by_name ( & mut self , _name : & str , _verbatim : bool , _as_needed : bool ) {
280
285
bug ! ( "dylib linked with unsupported linker" )
281
286
}
@@ -396,7 +401,7 @@ impl<'a> GccLinker<'a> {
396
401
] ) ;
397
402
}
398
403
399
- fn build_dylib ( & mut self , out_filename : & Path ) {
404
+ fn build_dylib ( & mut self , crate_type : CrateType , out_filename : & Path ) {
400
405
// On mac we need to tell the linker to let this library be rpathed
401
406
if self . sess . target . is_like_osx {
402
407
if !self . is_ld {
@@ -427,7 +432,7 @@ impl<'a> GccLinker<'a> {
427
432
let mut out_implib = OsString :: from ( "--out-implib=" ) ;
428
433
out_implib. push ( out_filename. with_file_name ( implib_name) ) ;
429
434
self . link_arg ( out_implib) ;
430
- } else {
435
+ } else if crate_type == CrateType :: Dylib {
431
436
// When dylibs are linked by a full path this value will get into `DT_NEEDED`
432
437
// instead of the full path, so the library can be later found in some other
433
438
// location than that specific path.
@@ -474,7 +479,12 @@ impl<'a> Linker for GccLinker<'a> {
474
479
!self . is_ld
475
480
}
476
481
477
- fn set_output_kind ( & mut self , output_kind : LinkOutputKind , out_filename : & Path ) {
482
+ fn set_output_kind (
483
+ & mut self ,
484
+ output_kind : LinkOutputKind ,
485
+ crate_type : CrateType ,
486
+ out_filename : & Path ,
487
+ ) {
478
488
match output_kind {
479
489
LinkOutputKind :: DynamicNoPicExe => {
480
490
if !self . is_ld && self . is_gnu {
@@ -509,10 +519,10 @@ impl<'a> Linker for GccLinker<'a> {
509
519
self . link_args ( & [ "-static" , "-pie" , "--no-dynamic-linker" , "-z" , "text" ] ) ;
510
520
}
511
521
}
512
- LinkOutputKind :: DynamicDylib => self . build_dylib ( out_filename) ,
522
+ LinkOutputKind :: DynamicDylib => self . build_dylib ( crate_type , out_filename) ,
513
523
LinkOutputKind :: StaticDylib => {
514
524
self . link_or_cc_arg ( "-static" ) ;
515
- self . build_dylib ( out_filename) ;
525
+ self . build_dylib ( crate_type , out_filename) ;
516
526
}
517
527
LinkOutputKind :: WasiReactorExe => {
518
528
self . link_args ( & [ "--entry" , "_initialize" ] ) ;
@@ -866,7 +876,12 @@ impl<'a> Linker for MsvcLinker<'a> {
866
876
& mut self . cmd
867
877
}
868
878
869
- fn set_output_kind ( & mut self , output_kind : LinkOutputKind , out_filename : & Path ) {
879
+ fn set_output_kind (
880
+ & mut self ,
881
+ output_kind : LinkOutputKind ,
882
+ _crate_type : CrateType ,
883
+ out_filename : & Path ,
884
+ ) {
870
885
match output_kind {
871
886
LinkOutputKind :: DynamicNoPicExe
872
887
| LinkOutputKind :: DynamicPicExe
@@ -1124,7 +1139,13 @@ impl<'a> Linker for EmLinker<'a> {
1124
1139
true
1125
1140
}
1126
1141
1127
- fn set_output_kind ( & mut self , _output_kind : LinkOutputKind , _out_filename : & Path ) { }
1142
+ fn set_output_kind (
1143
+ & mut self ,
1144
+ _output_kind : LinkOutputKind ,
1145
+ _crate_type : CrateType ,
1146
+ _out_filename : & Path ,
1147
+ ) {
1148
+ }
1128
1149
1129
1150
fn link_dylib_by_name ( & mut self , name : & str , _verbatim : bool , _as_needed : bool ) {
1130
1151
// Emscripten always links statically
@@ -1273,7 +1294,12 @@ impl<'a> Linker for WasmLd<'a> {
1273
1294
& mut self . cmd
1274
1295
}
1275
1296
1276
- fn set_output_kind ( & mut self , output_kind : LinkOutputKind , _out_filename : & Path ) {
1297
+ fn set_output_kind (
1298
+ & mut self ,
1299
+ output_kind : LinkOutputKind ,
1300
+ _crate_type : CrateType ,
1301
+ _out_filename : & Path ,
1302
+ ) {
1277
1303
match output_kind {
1278
1304
LinkOutputKind :: DynamicNoPicExe
1279
1305
| LinkOutputKind :: DynamicPicExe
@@ -1422,7 +1448,13 @@ impl<'a> Linker for L4Bender<'a> {
1422
1448
& mut self . cmd
1423
1449
}
1424
1450
1425
- fn set_output_kind ( & mut self , _output_kind : LinkOutputKind , _out_filename : & Path ) { }
1451
+ fn set_output_kind (
1452
+ & mut self ,
1453
+ _output_kind : LinkOutputKind ,
1454
+ _crate_type : CrateType ,
1455
+ _out_filename : & Path ,
1456
+ ) {
1457
+ }
1426
1458
1427
1459
fn link_staticlib_by_name ( & mut self , name : & str , _verbatim : bool , whole_archive : bool ) {
1428
1460
self . hint_static ( ) ;
@@ -1568,7 +1600,12 @@ impl<'a> Linker for AixLinker<'a> {
1568
1600
& mut self . cmd
1569
1601
}
1570
1602
1571
- fn set_output_kind ( & mut self , output_kind : LinkOutputKind , out_filename : & Path ) {
1603
+ fn set_output_kind (
1604
+ & mut self ,
1605
+ output_kind : LinkOutputKind ,
1606
+ _crate_type : CrateType ,
1607
+ out_filename : & Path ,
1608
+ ) {
1572
1609
match output_kind {
1573
1610
LinkOutputKind :: DynamicDylib => {
1574
1611
self . hint_dynamic ( ) ;
@@ -1775,7 +1812,13 @@ impl<'a> Linker for PtxLinker<'a> {
1775
1812
& mut self . cmd
1776
1813
}
1777
1814
1778
- fn set_output_kind ( & mut self , _output_kind : LinkOutputKind , _out_filename : & Path ) { }
1815
+ fn set_output_kind (
1816
+ & mut self ,
1817
+ _output_kind : LinkOutputKind ,
1818
+ _crate_type : CrateType ,
1819
+ _out_filename : & Path ,
1820
+ ) {
1821
+ }
1779
1822
1780
1823
fn link_staticlib_by_name ( & mut self , _name : & str , _verbatim : bool , _whole_archive : bool ) {
1781
1824
panic ! ( "staticlibs not supported" )
@@ -1841,7 +1884,13 @@ impl<'a> Linker for LlbcLinker<'a> {
1841
1884
& mut self . cmd
1842
1885
}
1843
1886
1844
- fn set_output_kind ( & mut self , _output_kind : LinkOutputKind , _out_filename : & Path ) { }
1887
+ fn set_output_kind (
1888
+ & mut self ,
1889
+ _output_kind : LinkOutputKind ,
1890
+ _crate_type : CrateType ,
1891
+ _out_filename : & Path ,
1892
+ ) {
1893
+ }
1845
1894
1846
1895
fn link_staticlib_by_name ( & mut self , _name : & str , _verbatim : bool , _whole_archive : bool ) {
1847
1896
panic ! ( "staticlibs not supported" )
@@ -1912,7 +1961,13 @@ impl<'a> Linker for BpfLinker<'a> {
1912
1961
& mut self . cmd
1913
1962
}
1914
1963
1915
- fn set_output_kind ( & mut self , _output_kind : LinkOutputKind , _out_filename : & Path ) { }
1964
+ fn set_output_kind (
1965
+ & mut self ,
1966
+ _output_kind : LinkOutputKind ,
1967
+ _crate_type : CrateType ,
1968
+ _out_filename : & Path ,
1969
+ ) {
1970
+ }
1916
1971
1917
1972
fn link_staticlib_by_name ( & mut self , _name : & str , _verbatim : bool , _whole_archive : bool ) {
1918
1973
panic ! ( "staticlibs not supported" )
0 commit comments