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

Use the linker directly on darwin,ios #46255

Closed
wants to merge 2 commits into from

Conversation

tamird
Copy link
Contributor

@tamird tamird commented Nov 25, 2017

See individual commits. r? @alexcrichton cc @japaric

(pnkfelix adds: This is taking steps towards addressing #11937)

@kennytm kennytm added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 25, 2017
@kennytm
Copy link
Member

kennytm commented Nov 25, 2017

This caused several errors on the CI which is running Linux 😕

[00:59:08] failures:
[00:59:08]     [run-make] run-make/fpic
[00:59:08]     [run-make] run-make/print-cfg
[00:59:08]     [run-make] run-make/simd-ffi

@kennytm kennytm added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 25, 2017
@tamird
Copy link
Contributor Author

tamird commented Nov 25, 2017 via email

@tamird
Copy link
Contributor Author

tamird commented Nov 25, 2017

I was able to repro run-make/fpic locally, and the other two were caused by an errant unwrap call which assumed that xcrun is always available (which is not the case when cross-compiling). All three should be fixed now.

@kennytm kennytm added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 25, 2017
@tamird
Copy link
Contributor Author

tamird commented Nov 26, 2017

cc @TimNN

@alexcrichton
Copy link
Member

Thanks for this, it looks pretty cool!

My main worry here would be around the area of regressions. For example this would break anyone using -C link-arg on OSX as the link arguments would need to be passed differently. I think it may be best to do this as a trial run instead of a "immediately change the defaults".

For example I think we should enable -Z linker-flavor=ld to "just work" on OSX. We'd leave the default linker flavor as gcc but we could then have the necessary code in the compiler to switch to ld if necessary.

Switching the iOS targets seems reasonable but we may wish to pursue the same strategy for now and then post on internals about how everyone's using -C link-args and OSX-related things.

@kennytm kennytm added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 27, 2017
@TimNN
Copy link
Contributor

TimNN commented Nov 27, 2017

Hey @tamird, do you need anything particular from me or was the cc just an FYI?

@tamird
Copy link
Contributor Author

tamird commented Nov 27, 2017

@TimNN nah, just thought you might have some opinions on iOS stuff (as I recall you've done some work in that area in the past).

@alexcrichton sounds totally reasonable! one thing that was attractive about making ld the default was that it allowed me to build stage1 and confirm that linking actually worked, but perhaps there is a better way to do this? Specifically, how do I get bootstrap to pass custom flags to rustc (in this case I'd want -Z --linker-flavor=ld -C linker=ld)?

@alexcrichton
Copy link
Member

@tamird yeah I'm quite surprised this worked to bootstrap! (that's awesome!)

We could always tweak our own bootstrap to use this linker by default and avoid cc (seems like a good idea to me) but I think we'll want to leave the default for everyone else as cc for now (until we at least message it out and canvas opinions).

I was also thinking that right now the default linker is cc sort of unconditionally but we can probably infer it based on the linker flavor. That is if you only specify -Z linker-flavor=ld then that should imply, on OSX, that you use a default linker of ld

@tamird
Copy link
Contributor Author

tamird commented Nov 29, 2017

So this is kind of a bummer. In order to make ld "just work" on osx, we need to teach all the targets the correct ld args, which in general are just the cc args with some stuff removed.

I say it's a bummer because it makes me think that "linker flavor", as implemented in rustc, is not a particularly good abstraction because generally (always?) there is only one linker on each platform, which we currently always front with cc. However, nearly all the flags we pass to cc have a direct mapping to an ld flag.

Here's my proposal: we should remove linker flavor and go back to having a list of linker args per target as before, only this time the linker args will all be the ld variant, rather than the cc variant. Then, we can check at link time if the executable we're calling "looks like" cc or ld (or lld, or whatever) and map the ld flags to cc flags. Unfortunately, this will be a breaking change, as you say, with respect to how link args are pass on the command line today (since they'll need to be in ld form).

We could also do this in the reverse direction (mapping cc flags to ld flags), I think, but I imagine it'll be somewhat uglier.

What do you think?

@alexcrichton
Copy link
Member

Sorry I don't currently have the time to evaluate what appears to be major refactorings of the backends and how we pass arguments around, it would be good to consult other compiler team members with these sorts of questions right now.

@kennytm kennytm added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 29, 2017
@kennytm
Copy link
Member

kennytm commented Dec 6, 2017

Reassigning to another person randomly on the compiler team as @alexcrichton doesn't have time to evaluate this.

r? @pnkfelix

@carols10cents
Copy link
Member

Review ping for you @pnkfelix !

@pnkfelix
Copy link
Member

This PR looks fine to me, but I'm not an expert in this domain (in terms of the issues that need to be addressed for #46255

@pnkfelix
Copy link
Member

pnkfelix commented Dec 13, 2017

Reading the dialogue on this PR more carefully, I now realize I was a little too blasé in my pseudo-review (aka rubberstamp) above.

Namely, addressing #46255 is not sufficiently high priority to justify injecting the kinds of breaking changes that @alexcrichton has described.

@alexcrichton gave some suggestions for how to revise the PR so that it would not inject a breaking- change to stable code.

@tamird responded, but it seemed like their alternative approach is still going to inject breakage onto stable clients? (Did I misread their comment that outlined an alternative strategy to what @alexcrichton had suggested?)

So, high-level points + questions:

  • Clearly one should not r+ this PR as it is written currently.
  • The question is what to do next.
  • Do we actually care about addressing Link using the linker directly #11937? It seems like @tamird has a personal investment in addressing it (I'm not clear what actual problem of theirs it is addressing, but I'll assume they have a good reason beyond just architectural cleanliness...)
  • (Related to the previous bullet: Why is the strategy of using -Z --linker-flavor=ld -C linker=ld to accomplish the goal of Link using the linker directly #11937 not acceptable? Because we want to ensure that stable clients do get some way to opt into this?)
  • If we are serious about actually addressing Link using the linker directly #11937, how can we do so without inject a breaking-change for clients of the stable channel who are are today already using -C link-arg?
    • Specifically: I don't think the strategy outlined by @tamird would get r+'ed by the compiler team, because of it being a breaking change.

Update: sigh, everywhere that I wrote #46255 I had meant to write #11937; sorry all...

@kennytm kennytm added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 20, 2017
@kennytm
Copy link
Member

kennytm commented Dec 20, 2017

Triage ping @tamird. Do you have answers to @pnkfelix's questions above?

@tamird
Copy link
Contributor Author

tamird commented Dec 20, 2017

Why is the strategy of using -Z --linker-flavor=ld -C linker=ld to accomplish the goal of #46255 not acceptable?

Because it doesn't always work - if the target platform requires more flags, the user has to specify them all. The (reduced) goal is to be able to pass exactly those flags and have most platforms just work.

The other questions aren't for me to answer.

@kennytm
Copy link
Member

kennytm commented Dec 20, 2017

Should this be raised to the team for discussion? (Due to holiday this will likely need to wait until January)

@tamird
Copy link
Contributor Author

tamird commented Dec 20, 2017 via email

@kennytm kennytm added I-nominated S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 20, 2017
@kennytm
Copy link
Member

kennytm commented Dec 20, 2017

Nominated @rust-lang/compiler.

@kennytm
Copy link
Member

kennytm commented Jan 10, 2018

Triage ping @rust-lang/compiler! Just to remind you all about this PR 😁.

@nikomatsakis
Copy link
Contributor

nikomatsakis commented Jan 11, 2018

We discussed this in the @rust-lang/compiler meeting. Conclusion was:

  • We can land this PR, but only when it is made opt-in and feature-gated.
  • We should open a tracking issue for the relevant feature.
    • I personally think that before stabilization, I'd like to see an RFC, or at least some strong evidence that we've covered all the use cases people might want here.

@kennytm kennytm added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). labels Jan 11, 2018
@shepmaster
Copy link
Member

Triage ping for @tamird — looks like there is some feedback the team would like to see before this PR lands; will you have time to implement them?

@shepmaster
Copy link
Member

Thanks for the contribution, @tamird ! Unfortunately, since we haven't heard from you in a few weeks, I'm going to go ahead and close this to keep the queue tidy. Please fee free to re-open it when you have time to address the most recent feedback!

@shepmaster shepmaster closed this Jan 26, 2018
@shepmaster shepmaster added S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 26, 2018
@alexcrichton
Copy link
Member

@tamird #48125 is doing most of the refactoring that I was thinking about, would you be up for rebasing this once that lands? I think with that we shoudl be able to get all of the following working by default:

$ rustc foo.rs
$ rustc foo.rs -Z linker-flavor=ld
$ rustc foo.rs -Z linker-flavor=ld64.ll

where there we're using the system linker, the ld linker itself, and then finally the bundled version of lld. I'd imagine that with the fixes here those could all work! (and the latter would be great for benchmarking when needed)

@tamird
Copy link
Contributor Author

tamird commented Feb 11, 2018

@alexcrichton sure! Thanks for making me aware of that PR; I'll follow along and pick this up when that's merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants