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

[WIP] Infer linker-flavor from the selected linker #50359

Closed
wants to merge 2 commits into from

Conversation

japaric
Copy link
Member

@japaric japaric commented May 1, 2018

And make linker-flavor optional in target specifications.

This PR reduces the need for -Z linker-flavor by having rustc infer the linker flavor from the name of the linker.

This has been tested on Linux and by cross compiling for ARM Cortex-M with 3 different linkers (gcc, rustc's lld and ld.lld), but the logic probably needs quite a bit of tweaking to not break existing use cases so I would suggest not landing this before the 1.27 beta cutoff to maximize test time.

r? @alexcrichton

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 1, 2018
})
}

pub fn linker_flavor(&self) -> LinkerFlavor {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the main change but the logic probably doesn't work correctly on Windows because of the .exe suffix.

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-3.9 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading https://files.pythonhosted.org/packages/3f/6c/dbbd5992740649134e597833bea5a95e1fc093a7123e9b8156d838b960e4/awscli-1.15.11-py2.py3-none-any.whl (1.3MB)
    0% |▎                               | 10kB 10.4MB/s eta 0:00:01
    1% |▌                               | 20kB 1.8MB/s eta 0:00:01
    2% |▉                               | 30kB 2.1MB/s eta 0:00:01
    3% |█                               | 40kB 2.0MB/s eta 0:00:01
---
    100% |████████████████████████████████| 61kB 6.5MB/s 
Collecting botocore==1.10.11 (from awscli)
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading https://files.pythonhosted.org/packages/15/c0/04ec8aec3cdf7dd4887f2666044550eb3370a4f29668e53519cc7143bdcf/botocore-1.10.11-py2.py3-none-any.whl (4.2MB)
    0% |                                | 10kB 32.2MB/s eta 0:00:01
    0% |▏                               | 20kB 30.4MB/s eta 0:00:01
    0% |▎                               | 30kB 36.4MB/s eta 0:00:01
    0% |▎                               | 40kB 17.1MB/s eta 0:00:01
---

[00:05:06] travis_fold:start:tidy
travis_time:start:tidy
tidy check
[00:05:06] tidy error: /checkout/src/librustc_trans/back/link.rs:88: TODO is deprecated; use FIXME
[00:05:08] some tidy checks failed
[00:05:08] 
[00:05:08] 
[00:05:08] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor" "--quiet"
[00:05:08] 
[00:05:08] 
[00:05:08] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:05:08] Build completed unsuccessfully in 0:02:02
[00:05:08] Build completed unsuccessfully in 0:02:02
[00:05:08] Makefile:79: recipe for target 'tidy' failed
[00:05:08] make: *** [tidy] Error 1

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:1282f59a
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@nagisa
Copy link
Member

nagisa commented May 1, 2018

Can we have a method for explicitly specifying the linker flavour?

@japaric
Copy link
Member Author

japaric commented May 1, 2018

@nagisa In what context? (-Z linker-flavor hasn't gone anywhere)

@nagisa
Copy link
Member

nagisa commented May 1, 2018

Oh, well then.

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Thanks @japaric! For actually invoking the linker we need to know the flavor/path to the linker, and I thinkt he high level idea of how I'm thinking we'll do this is (in order):

  • If both are explicitly specified, use them
  • If only flavor is explicitly specified, then infer the default path based on the flavor
  • If only the path is specified, infer the flavor from the file_stem
  • The same logic then applies to the target spec options, recursively
  • If nothing is specified (either explicitly or implicitly through the target spec) then we emit an error

@@ -600,11 +600,51 @@ impl Session {
.panic
.unwrap_or(self.target.target.options.panic_strategy)
}
pub fn linker_flavor(&self) -> LinkerFlavor {

fn linker(&self) -> &str {
Copy link
Member

Choose a reason for hiding this comment

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

AFAIK there's not actually any reason these methods have to live in librustc, if you'd like feel free to delete them here and move the wholesale into librustc_trans

Copy link
Member

Choose a reason for hiding this comment

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

I also think this method looks mostly correct except for the last part. We'll probably want to rename this to something like linker_file_stem and then make sure you use the file_stem method of Path at the end to remove bat/exe suffixes

@@ -42,7 +42,6 @@ pub fn target() -> Result<Target, String> {
target_vendor: "unknown".to_string(),
data_layout: "e-p:32:32-i64:64-v128:32:128-n32-S128".to_string(),
arch: "asmjs".to_string(),
linker_flavor: LinkerFlavor::Em,
Copy link
Member

Choose a reason for hiding this comment

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

I think this ay break emscripten, right? I think there's no other way to say that "the emscripten target uses emcc" by default, right?

@@ -65,7 +65,6 @@ pub fn target() -> Result<Target, String> {
target_vendor: "unknown".to_string(),
data_layout: "e-m:e-p:32:32-i64:64-n32:64-S128".to_string(),
arch: "wasm32".to_string(),
linker_flavor: LinkerFlavor::Lld(LldFlavor::Wasm),
Copy link
Member

Choose a reason for hiding this comment

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

Similar to emscripten above I think this means that wasm will attempt to use cc by default if we don't otherwise set some form of a default here

Copy link
Member

Choose a reason for hiding this comment

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

Or maybe it's best to sum this up as "we probably want to continue have default linker flavors", I think?

LinkerFlavor::Ld
} else if linker == "emcc" {
LinkerFlavor::Em
} else if linker == "link.exe" {
Copy link
Member

@retep998 retep998 May 2, 2018

Choose a reason for hiding this comment

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

lld-link.exe is the LLD equivalent here. Might also be worth handling both with and without the .exe suffix?

@shepmaster shepmaster 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 May 6, 2018
@shepmaster
Copy link
Member

Ping from triage, @japaric ! You have some review feedback to address!

@bors
Copy link
Contributor

bors commented May 11, 2018

☔ The latest upstream changes (presumably #50105) made this pull request unmergeable. Please resolve the merge conflicts.

@japaric
Copy link
Member Author

japaric commented May 16, 2018

Thanks for the input, @alexcrichton. I don't have time to incorporate your feedback right now so I'm going to close this in the meantime to clear the PR queue.

@japaric japaric closed this May 16, 2018
bors added a commit that referenced this pull request Aug 20, 2018
try to infer linker flavor from linker name and vice versa

This is a second take on PR #50359 that implements the logic proposed in #50359 (review)

With this change it would become possible to link `thumb*` binaries using GNU's LD on stable as `-C linker=arm-none-eabi-ld` would be enough to change both the linker and the linker flavor from their default values of `arm-none-eabi-gcc` and `gcc`.

To link `thumb*` binaries using rustc's LLD on stable `-Z linker-flavor` would need to be stabilized as `-C linker=rust-lld -Z linker-flavor=ld.lld` are both required to change the linker and the linker flavor, but this PR doesn't propose that. We would probably need some sort of stability guarantee around `rust-lld`'s name and availability to make linking with rustc's LLD truly stable.

With this change it would also be possible to link `thumb*` binaries using a system installed LLD on stable using the `-C linker=ld.lld` flag (provided that `ld.lld` is a symlink to the system installed LLD).

r? @alexcrichton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants