Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apple: Fix direct linking with +verbatim #132394

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,23 @@ impl<'a> Linker for GccLinker<'a> {
self.hint_static();
let colon = if verbatim && self.is_gnu { ":" } else { "" };
if !whole_archive {
self.link_or_cc_arg(format!("-l{colon}{name}"));
if self.sess.target.is_like_osx && verbatim {
// The man page for ld64's `-l` option says:
// > This option tells the linker to search for libx.dylib or libx.a in the library
// > search path. If string x is of the form y.o, then that file is searched for in
// > the same places, but without prepending `lib` or appending `.a` or `.dylib` to
// > the filename.
//
// So if we're linking a verbatim file, then we need to do the lookup and pass it
// directly as a normal file parameter on the command line.
//
// NOTE: We _could_ add `&& name.ends_with(".o")`, but having more guaranteed
// consistent behaviour in `rustc` regardless of the file extension seems like the
// better solution.
self.link_or_cc_arg(find_native_static_library(name, verbatim, self.sess));
} else {
self.link_or_cc_arg(format!("-l{colon}{name}"));
}
} else if self.sess.target.is_like_osx {
// -force_load is the macOS equivalent of --whole-archive, but it
// involves passing the full path to the library to link.
Expand Down
3 changes: 0 additions & 3 deletions tests/run-make/native-link-modifier-verbatim-linker/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
// This test is the same as native-link-modifier-rustc, but without rlibs.
// See https://github.com/rust-lang/rust/issues/99425

//@ ignore-apple
// Reason: linking fails due to the unusual ".ext" staticlib name.
Comment on lines -6 to -7
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ignore was added in #101806, and only later rationalized when converting to rmake.


use run_make_support::rustc;

fn main() {
Expand Down
Loading