@@ -275,7 +275,12 @@ pub(crate) trait Linker {
275275fn is_cc ( & self ) -> bool {
276276false
277277}
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+ ) ;
279284fn link_dylib_by_name ( & mut self , _name : & str , _verbatim : bool , _as_needed : bool ) {
280285bug ! ( "dylib linked with unsupported linker" )
281286}
@@ -396,7 +401,7 @@ impl<'a> GccLinker<'a> {
396401] ) ;
397402}
398403
399- fn build_dylib ( & mut self , out_filename : & Path ) {
404+ fn build_dylib ( & mut self , crate_type : CrateType , out_filename : & Path ) {
400405// On mac we need to tell the linker to let this library be rpathed
401406if self . sess . target . is_like_osx {
402407if !self . is_ld {
@@ -427,7 +432,7 @@ impl<'a> GccLinker<'a> {
427432let mut out_implib = OsString :: from ( "--out-implib=" ) ;
428433 out_implib. push ( out_filename. with_file_name ( implib_name) ) ;
429434self . link_arg ( out_implib) ;
430- } else {
435+ } else if crate_type == CrateType :: Dylib {
431436// When dylibs are linked by a full path this value will get into `DT_NEEDED`
432437// instead of the full path, so the library can be later found in some other
433438// location than that specific path.
@@ -474,7 +479,12 @@ impl<'a> Linker for GccLinker<'a> {
474479 !self . is_ld
475480}
476481
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+ ) {
478488match output_kind {
479489LinkOutputKind :: DynamicNoPicExe => {
480490if !self . is_ld && self . is_gnu {
@@ -509,10 +519,10 @@ impl<'a> Linker for GccLinker<'a> {
509519self . link_args ( & [ "-static" , "-pie" , "--no-dynamic-linker" , "-z" , "text" ] ) ;
510520}
511521}
512- LinkOutputKind :: DynamicDylib => self . build_dylib ( out_filename) ,
522+ LinkOutputKind :: DynamicDylib => self . build_dylib ( crate_type , out_filename) ,
513523LinkOutputKind :: StaticDylib => {
514524self . link_or_cc_arg ( "-static" ) ;
515- self . build_dylib ( out_filename) ;
525+ self . build_dylib ( crate_type , out_filename) ;
516526}
517527LinkOutputKind :: WasiReactorExe => {
518528self . link_args ( & [ "--entry" , "_initialize" ] ) ;
@@ -866,7 +876,12 @@ impl<'a> Linker for MsvcLinker<'a> {
866876& mut self . cmd
867877}
868878
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+ ) {
870885match output_kind {
871886LinkOutputKind :: DynamicNoPicExe
872887 | LinkOutputKind :: DynamicPicExe
@@ -1124,7 +1139,13 @@ impl<'a> Linker for EmLinker<'a> {
11241139true
11251140}
11261141
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+ }
11281149
11291150fn link_dylib_by_name ( & mut self , name : & str , _verbatim : bool , _as_needed : bool ) {
11301151// Emscripten always links statically
@@ -1273,7 +1294,12 @@ impl<'a> Linker for WasmLd<'a> {
12731294& mut self . cmd
12741295}
12751296
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+ ) {
12771303match output_kind {
12781304LinkOutputKind :: DynamicNoPicExe
12791305 | LinkOutputKind :: DynamicPicExe
@@ -1422,7 +1448,13 @@ impl<'a> Linker for L4Bender<'a> {
14221448& mut self . cmd
14231449}
14241450
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+ }
14261458
14271459fn link_staticlib_by_name ( & mut self , name : & str , _verbatim : bool , whole_archive : bool ) {
14281460self . hint_static ( ) ;
@@ -1568,7 +1600,12 @@ impl<'a> Linker for AixLinker<'a> {
15681600& mut self . cmd
15691601}
15701602
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+ ) {
15721609match output_kind {
15731610LinkOutputKind :: DynamicDylib => {
15741611self . hint_dynamic ( ) ;
@@ -1775,7 +1812,13 @@ impl<'a> Linker for PtxLinker<'a> {
17751812& mut self . cmd
17761813}
17771814
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+ }
17791822
17801823fn link_staticlib_by_name ( & mut self , _name : & str , _verbatim : bool , _whole_archive : bool ) {
17811824panic ! ( "staticlibs not supported" )
@@ -1841,7 +1884,13 @@ impl<'a> Linker for LlbcLinker<'a> {
18411884& mut self . cmd
18421885}
18431886
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+ }
18451894
18461895fn link_staticlib_by_name ( & mut self , _name : & str , _verbatim : bool , _whole_archive : bool ) {
18471896panic ! ( "staticlibs not supported" )
@@ -1912,7 +1961,13 @@ impl<'a> Linker for BpfLinker<'a> {
19121961& mut self . cmd
19131962}
19141963
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+ }
19161971
19171972fn link_staticlib_by_name ( & mut self , _name : & str , _verbatim : bool , _whole_archive : bool ) {
19181973panic ! ( "staticlibs not supported" )
0 commit comments