@@ -266,7 +266,12 @@ pub trait Linker {
266266 fn is_cc ( & self ) -> bool {
267267 false
268268 }
269- fn set_output_kind ( & mut self , output_kind : LinkOutputKind , out_filename : & Path ) ;
269+ fn set_output_kind (
270+ & mut self ,
271+ output_kind : LinkOutputKind ,
272+ crate_type : CrateType ,
273+ out_filename : & Path ,
274+ ) ;
270275 fn link_dylib_by_name ( & mut self , _name : & str , _verbatim : bool , _as_needed : bool ) {
271276 bug ! ( "dylib linked with unsupported linker" )
272277 }
@@ -387,7 +392,7 @@ impl<'a> GccLinker<'a> {
387392 ] ) ;
388393 }
389394
390- fn build_dylib ( & mut self , out_filename : & Path ) {
395+ fn build_dylib ( & mut self , crate_type : CrateType , out_filename : & Path ) {
391396 // On mac we need to tell the linker to let this library be rpathed
392397 if self . sess . target . is_like_osx {
393398 if !self . is_ld {
@@ -418,7 +423,7 @@ impl<'a> GccLinker<'a> {
418423 let mut out_implib = OsString :: from ( "--out-implib=" ) ;
419424 out_implib. push ( out_filename. with_file_name ( implib_name) ) ;
420425 self . link_arg ( out_implib) ;
421- } else {
426+ } else if crate_type == CrateType :: Dylib {
422427 // When dylibs are linked by a full path this value will get into `DT_NEEDED`
423428 // instead of the full path, so the library can be later found in some other
424429 // location than that specific path.
@@ -465,7 +470,12 @@ impl<'a> Linker for GccLinker<'a> {
465470 !self . is_ld
466471 }
467472
468- fn set_output_kind ( & mut self , output_kind : LinkOutputKind , out_filename : & Path ) {
473+ fn set_output_kind (
474+ & mut self ,
475+ output_kind : LinkOutputKind ,
476+ crate_type : CrateType ,
477+ out_filename : & Path ,
478+ ) {
469479 match output_kind {
470480 LinkOutputKind :: DynamicNoPicExe => {
471481 if !self . is_ld && self . is_gnu {
@@ -500,10 +510,10 @@ impl<'a> Linker for GccLinker<'a> {
500510 self . link_args ( & [ "-static" , "-pie" , "--no-dynamic-linker" , "-z" , "text" ] ) ;
501511 }
502512 }
503- LinkOutputKind :: DynamicDylib => self . build_dylib ( out_filename) ,
513+ LinkOutputKind :: DynamicDylib => self . build_dylib ( crate_type , out_filename) ,
504514 LinkOutputKind :: StaticDylib => {
505515 self . link_or_cc_arg ( "-static" ) ;
506- self . build_dylib ( out_filename) ;
516+ self . build_dylib ( crate_type , out_filename) ;
507517 }
508518 LinkOutputKind :: WasiReactorExe => {
509519 self . link_args ( & [ "--entry" , "_initialize" ] ) ;
@@ -859,7 +869,12 @@ impl<'a> Linker for MsvcLinker<'a> {
859869 & mut self . cmd
860870 }
861871
862- fn set_output_kind ( & mut self , output_kind : LinkOutputKind , out_filename : & Path ) {
872+ fn set_output_kind (
873+ & mut self ,
874+ output_kind : LinkOutputKind ,
875+ _crate_type : CrateType ,
876+ out_filename : & Path ,
877+ ) {
863878 match output_kind {
864879 LinkOutputKind :: DynamicNoPicExe
865880 | LinkOutputKind :: DynamicPicExe
@@ -1111,7 +1126,13 @@ impl<'a> Linker for EmLinker<'a> {
11111126 true
11121127 }
11131128
1114- fn set_output_kind ( & mut self , _output_kind : LinkOutputKind , _out_filename : & Path ) { }
1129+ fn set_output_kind (
1130+ & mut self ,
1131+ _output_kind : LinkOutputKind ,
1132+ _crate_type : CrateType ,
1133+ _out_filename : & Path ,
1134+ ) {
1135+ }
11151136
11161137 fn link_dylib_by_name ( & mut self , name : & str , _verbatim : bool , _as_needed : bool ) {
11171138 // Emscripten always links statically
@@ -1260,7 +1281,12 @@ impl<'a> Linker for WasmLd<'a> {
12601281 & mut self . cmd
12611282 }
12621283
1263- fn set_output_kind ( & mut self , output_kind : LinkOutputKind , _out_filename : & Path ) {
1284+ fn set_output_kind (
1285+ & mut self ,
1286+ output_kind : LinkOutputKind ,
1287+ _crate_type : CrateType ,
1288+ _out_filename : & Path ,
1289+ ) {
12641290 match output_kind {
12651291 LinkOutputKind :: DynamicNoPicExe
12661292 | LinkOutputKind :: DynamicPicExe
@@ -1409,7 +1435,13 @@ impl<'a> Linker for L4Bender<'a> {
14091435 & mut self . cmd
14101436 }
14111437
1412- fn set_output_kind ( & mut self , _output_kind : LinkOutputKind , _out_filename : & Path ) { }
1438+ fn set_output_kind (
1439+ & mut self ,
1440+ _output_kind : LinkOutputKind ,
1441+ _crate_type : CrateType ,
1442+ _out_filename : & Path ,
1443+ ) {
1444+ }
14131445
14141446 fn link_staticlib_by_name ( & mut self , name : & str , _verbatim : bool , whole_archive : bool ) {
14151447 self . hint_static ( ) ;
@@ -1556,7 +1588,12 @@ impl<'a> Linker for AixLinker<'a> {
15561588 & mut self . cmd
15571589 }
15581590
1559- fn set_output_kind ( & mut self , output_kind : LinkOutputKind , out_filename : & Path ) {
1591+ fn set_output_kind (
1592+ & mut self ,
1593+ output_kind : LinkOutputKind ,
1594+ _crate_type : CrateType ,
1595+ out_filename : & Path ,
1596+ ) {
15601597 match output_kind {
15611598 LinkOutputKind :: DynamicDylib => {
15621599 self . hint_dynamic ( ) ;
@@ -1763,7 +1800,13 @@ impl<'a> Linker for PtxLinker<'a> {
17631800 & mut self . cmd
17641801 }
17651802
1766- fn set_output_kind ( & mut self , _output_kind : LinkOutputKind , _out_filename : & Path ) { }
1803+ fn set_output_kind (
1804+ & mut self ,
1805+ _output_kind : LinkOutputKind ,
1806+ _crate_type : CrateType ,
1807+ _out_filename : & Path ,
1808+ ) {
1809+ }
17671810
17681811 fn link_staticlib_by_name ( & mut self , _name : & str , _verbatim : bool , _whole_archive : bool ) {
17691812 panic ! ( "staticlibs not supported" )
@@ -1829,7 +1872,13 @@ impl<'a> Linker for LlbcLinker<'a> {
18291872 & mut self . cmd
18301873 }
18311874
1832- fn set_output_kind ( & mut self , _output_kind : LinkOutputKind , _out_filename : & Path ) { }
1875+ fn set_output_kind (
1876+ & mut self ,
1877+ _output_kind : LinkOutputKind ,
1878+ _crate_type : CrateType ,
1879+ _out_filename : & Path ,
1880+ ) {
1881+ }
18331882
18341883 fn link_staticlib_by_name ( & mut self , _name : & str , _verbatim : bool , _whole_archive : bool ) {
18351884 panic ! ( "staticlibs not supported" )
@@ -1900,7 +1949,13 @@ impl<'a> Linker for BpfLinker<'a> {
19001949 & mut self . cmd
19011950 }
19021951
1903- fn set_output_kind ( & mut self , _output_kind : LinkOutputKind , _out_filename : & Path ) { }
1952+ fn set_output_kind (
1953+ & mut self ,
1954+ _output_kind : LinkOutputKind ,
1955+ _crate_type : CrateType ,
1956+ _out_filename : & Path ,
1957+ ) {
1958+ }
19041959
19051960 fn link_staticlib_by_name ( & mut self , _name : & str , _verbatim : bool , _whole_archive : bool ) {
19061961 panic ! ( "staticlibs not supported" )
0 commit comments