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

Make -Z gcc-ld=lld work for Apple targets #88250

Merged
merged 3 commits into from
Aug 29, 2021
Merged

Conversation

hkratz
Copy link
Contributor

@hkratz hkratz commented Aug 23, 2021

-Z gcc-ld=lld was introduced in #85961. It does not work on Macos because lld needs be either named ld64 or passed -flavor darwin as the first two arguments in order to select the Mach-O flavor. Rust invokes cc (=clang) on Macos for linking which calls ld as linker binary and not ld64, so just creating an ld64 binary and modifying the search path with -B does not work.

In order to solve this patch does:

  • Set the lld_flavor for all Apple-derived targets to LldFlavor::Ld64. As far as I can see this actually works towards fixing -Xlinker=rust-lld as all those targets use the Mach-O object format.
  • Copy/hardlink rust-lld to the gcc-ld subdirectory as ld64 next to ld.
  • If -Z gcc-ld=lld is used and the target lld flavor is Ld64 add -fuse-ld=/path/to/ld64 to the linker invocation.

Fixes #86945.

@rust-highfive
Copy link
Collaborator

r? @nagisa

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive
Copy link
Collaborator

⚠️ Warning ⚠️

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 23, 2021
@hkratz
Copy link
Contributor Author

hkratz commented Aug 23, 2021

Open questions:

  • The name of the option is no longer accurate.
  • Maybe we should use softlinks instead of copies/hardlinks on everything but Windows? An alternative would be tiny Rust wrappers which just exec rust-lldb with the appropriate flavor. Those could work the same on all platforms.

cc @1000teslas @petrochenkov @bjorn3

@nagisa
Copy link
Member

nagisa commented Aug 23, 2021

The name of the option is no longer accurate.

Not quite as it still only applies to -Clinker-flavor=gcc.

@nagisa
Copy link
Member

nagisa commented Aug 23, 2021

Seems reasonable to me. Unfortunate that there are too many leaky abstractions in between certain parts of rustc and its linker invocation that its not feasible to fix it in a more straightforward way.

@bors r+ Thanks!

@bors
Copy link
Contributor

bors commented Aug 23, 2021

📌 Commit 0f7702e has been approved by nagisa

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 23, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Aug 26, 2021
Make `-Z gcc-ld=lld` work for Apple targets

`-Z gcc-ld=lld` was introduced in rust-lang#85961. It does not work on Macos because lld needs be either named `ld64` or passed `-flavor darwin` as the first two arguments in order to select the Mach-O flavor. Rust invokes cc (=clang) on Macos for linking which calls `ld` as linker binary and not `ld64`, so just creating an `ld64` binary and modifying the search path with `-B` does not work.

In order to solve this patch does:
* Set the `lld_flavor` for all Apple-derived targets to `LldFlavor::Ld64`. As far as I can see this actually works towards fixing `-Xlinker=rust-lld` as all those targets use the Mach-O object format.
* Copy/hardlink rust-lld to the gcc-ld subdirectory as ld64 next to ld.
* If `-Z gcc-ld=lld` is used and the target lld flavor is Ld64 add `-fuse-ld=/path/to/ld64` to the linker invocation.

Fixes rust-lang#86945.
Manishearth added a commit to Manishearth/rust that referenced this pull request Aug 27, 2021
Make `-Z gcc-ld=lld` work for Apple targets

`-Z gcc-ld=lld` was introduced in rust-lang#85961. It does not work on Macos because lld needs be either named `ld64` or passed `-flavor darwin` as the first two arguments in order to select the Mach-O flavor. Rust invokes cc (=clang) on Macos for linking which calls `ld` as linker binary and not `ld64`, so just creating an `ld64` binary and modifying the search path with `-B` does not work.

In order to solve this patch does:
* Set the `lld_flavor` for all Apple-derived targets to `LldFlavor::Ld64`. As far as I can see this actually works towards fixing `-Xlinker=rust-lld` as all those targets use the Mach-O object format.
* Copy/hardlink rust-lld to the gcc-ld subdirectory as ld64 next to ld.
* If `-Z gcc-ld=lld` is used and the target lld flavor is Ld64 add `-fuse-ld=/path/to/ld64` to the linker invocation.

Fixes rust-lang#86945.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Aug 27, 2021
Make `-Z gcc-ld=lld` work for Apple targets

`-Z gcc-ld=lld` was introduced in rust-lang#85961. It does not work on Macos because lld needs be either named `ld64` or passed `-flavor darwin` as the first two arguments in order to select the Mach-O flavor. Rust invokes cc (=clang) on Macos for linking which calls `ld` as linker binary and not `ld64`, so just creating an `ld64` binary and modifying the search path with `-B` does not work.

In order to solve this patch does:
* Set the `lld_flavor` for all Apple-derived targets to `LldFlavor::Ld64`. As far as I can see this actually works towards fixing `-Xlinker=rust-lld` as all those targets use the Mach-O object format.
* Copy/hardlink rust-lld to the gcc-ld subdirectory as ld64 next to ld.
* If `-Z gcc-ld=lld` is used and the target lld flavor is Ld64 add `-fuse-ld=/path/to/ld64` to the linker invocation.

Fixes rust-lang#86945.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Aug 27, 2021
Make `-Z gcc-ld=lld` work for Apple targets

`-Z gcc-ld=lld` was introduced in rust-lang#85961. It does not work on Macos because lld needs be either named `ld64` or passed `-flavor darwin` as the first two arguments in order to select the Mach-O flavor. Rust invokes cc (=clang) on Macos for linking which calls `ld` as linker binary and not `ld64`, so just creating an `ld64` binary and modifying the search path with `-B` does not work.

In order to solve this patch does:
* Set the `lld_flavor` for all Apple-derived targets to `LldFlavor::Ld64`. As far as I can see this actually works towards fixing `-Xlinker=rust-lld` as all those targets use the Mach-O object format.
* Copy/hardlink rust-lld to the gcc-ld subdirectory as ld64 next to ld.
* If `-Z gcc-ld=lld` is used and the target lld flavor is Ld64 add `-fuse-ld=/path/to/ld64` to the linker invocation.

Fixes rust-lang#86945.
@bors
Copy link
Contributor

bors commented Aug 29, 2021

⌛ Testing commit 0f7702e with merge 757a65b...

@bors
Copy link
Contributor

bors commented Aug 29, 2021

☀️ Test successful - checks-actions
Approved by: nagisa
Pushing 757a65b to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 29, 2021
@bors bors merged commit 757a65b into rust-lang:master Aug 29, 2021
@rustbot rustbot added this to the 1.56.0 milestone Aug 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Get gcc-ld=lld working on macos
5 participants