@@ -170,6 +170,9 @@ pub trait Linker {
170170 fn cmd ( & mut self ) -> & mut Command ;
171171 fn set_output_kind ( & mut self , output_kind : LinkOutputKind , out_filename : & Path ) ;
172172 fn link_dylib_by_name ( & mut self , name : & str , verbatim : bool , as_needed : bool ) ;
173+ fn link_dylib_by_path ( & mut self , path : & Path , _as_needed : bool ) {
174+ self . cmd ( ) . arg ( path) ;
175+ }
173176 fn link_framework_by_name ( & mut self , _name : & str , _verbatim : bool , _as_needed : bool ) {
174177 bug ! ( "framework linked with unsupported linker" )
175178 }
@@ -342,6 +345,31 @@ impl<'a> GccLinker<'a> {
342345 }
343346 }
344347 }
348+
349+ fn open_as_needed ( & mut self , as_needed : bool ) {
350+ if !as_needed {
351+ if self . sess . target . is_like_osx {
352+ // FIXME(81490): ld64 doesn't support these flags but macOS 11
353+ // has -needed-l{} / -needed_library {}
354+ // but we have no way to detect that here.
355+ self . sess . dcx ( ) . emit_warn ( errors:: Ld64UnimplementedModifier ) ;
356+ } else if self . is_gnu && !self . sess . target . is_like_windows {
357+ self . linker_arg ( "--no-as-needed" ) ;
358+ } else {
359+ self . sess . dcx ( ) . emit_warn ( errors:: LinkerUnsupportedModifier ) ;
360+ }
361+ }
362+ }
363+
364+ fn close_as_needed ( & mut self , as_needed : bool ) {
365+ if !as_needed {
366+ if self . sess . target . is_like_osx {
367+ // See above FIXME comment
368+ } else if self . is_gnu && !self . sess . target . is_like_windows {
369+ self . linker_arg ( "--as-needed" ) ;
370+ }
371+ }
372+ }
345373}
346374
347375impl < ' a > Linker for GccLinker < ' a > {
@@ -443,27 +471,17 @@ impl<'a> Linker for GccLinker<'a> {
443471 // to the linker.
444472 return ;
445473 }
446- if !as_needed {
447- if self . sess . target . is_like_osx {
448- // FIXME(81490): ld64 doesn't support these flags but macOS 11
449- // has -needed-l{} / -needed_library {}
450- // but we have no way to detect that here.
451- self . sess . dcx ( ) . emit_warn ( errors:: Ld64UnimplementedModifier ) ;
452- } else if self . is_gnu && !self . sess . target . is_like_windows {
453- self . linker_arg ( "--no-as-needed" ) ;
454- } else {
455- self . sess . dcx ( ) . emit_warn ( errors:: LinkerUnsupportedModifier ) ;
456- }
457- }
458474 self . hint_dynamic ( ) ;
475+ self . open_as_needed ( as_needed) ;
459476 self . cmd . arg ( format ! ( "-l{}{name}" , if verbatim && self . is_gnu { ":" } else { "" } , ) ) ;
460- if !as_needed {
461- if self . sess . target . is_like_osx {
462- // See above FIXME comment
463- } else if self . is_gnu && !self . sess . target . is_like_windows {
464- self . linker_arg ( "--as-needed" ) ;
465- }
466- }
477+ self . close_as_needed ( as_needed) ;
478+ }
479+
480+ fn link_dylib_by_path ( & mut self , path : & Path , as_needed : bool ) {
481+ self . hint_dynamic ( ) ;
482+ self . open_as_needed ( as_needed) ;
483+ self . cmd . arg ( path) ;
484+ self . close_as_needed ( as_needed) ;
467485 }
468486
469487 fn link_framework_by_name ( & mut self , name : & str , _verbatim : bool , as_needed : bool ) {
@@ -1537,6 +1555,11 @@ impl<'a> Linker for AixLinker<'a> {
15371555 self . cmd . arg ( format ! ( "-l{name}" ) ) ;
15381556 }
15391557
1558+ fn link_dylib_by_path ( & mut self , path : & Path , _as_needed : bool ) {
1559+ self . hint_dynamic ( ) ;
1560+ self . cmd ( ) . arg ( path) ;
1561+ }
1562+
15401563 fn link_staticlib_by_name ( & mut self , name : & str , verbatim : bool , whole_archive : bool ) {
15411564 self . hint_static ( ) ;
15421565 if !whole_archive {
0 commit comments