File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed
compiler/rustc_codegen_ssa/src/back
tests/run-make/native-link-modifier-verbatim-linker Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -585,7 +585,23 @@ impl<'a> Linker for GccLinker<'a> {
585585 self . hint_static ( ) ;
586586 let colon = if verbatim && self . is_gnu { ":" } else { "" } ;
587587 if !whole_archive {
588- self . link_or_cc_arg ( format ! ( "-l{colon}{name}" ) ) ;
588+ if self . sess . target . is_like_osx && verbatim {
589+ // The man page for ld64's `-l` option says:
590+ // > This option tells the linker to search for libx.dylib or libx.a in the library
591+ // > search path. If string x is of the form y.o, then that file is searched for in
592+ // > the same places, but without prepending `lib` or appending `.a` or `.dylib` to
593+ // > the filename.
594+ //
595+ // So if we're linking a verbatim file, then we need to do the lookup and pass it
596+ // directly as a normal file parameter on the command line.
597+ //
598+ // NOTE: We _could_ add `&& name.ends_with(".o")`, but having more guaranteed
599+ // consistent behaviour in `rustc` regardless of the file extension seems like the
600+ // better solution.
601+ self . link_or_cc_arg ( find_native_static_library ( name, verbatim, self . sess ) ) ;
602+ } else {
603+ self . link_or_cc_arg ( format ! ( "-l{colon}{name}" ) ) ;
604+ }
589605 } else if self . sess . target . is_like_osx {
590606 // -force_load is the macOS equivalent of --whole-archive, but it
591607 // involves passing the full path to the library to link.
Original file line number Diff line number Diff line change 33// This test is the same as native-link-modifier-rustc, but without rlibs.
44// See https://github.com/rust-lang/rust/issues/99425
55
6- //@ ignore-apple
7- // Reason: linking fails due to the unusual ".ext" staticlib name.
8-
96use run_make_support:: rustc;
107
118fn main ( ) {
You can’t perform that action at this time.
0 commit comments