Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upLink with ld.gold by default #29974
Conversation
rust-highfive
assigned
alexcrichton
Nov 21, 2015
This comment has been minimized.
This comment has been minimized.
|
(rust_highfive has picked a reviewer for you, use r? to override) |
brson
force-pushed the
brson:gold
branch
from
e6b9c48
to
b5cc5d7
Nov 21, 2015
nagisa
reviewed
Nov 21, 2015
| @@ -199,6 +200,24 @@ impl<'a> Linker for GnuLinker<'a> { | |||
| fn export_symbols(&mut self, _: &Session, _: &CrateTranslation, _: &Path) { | |||
| // noop, visibility in object files takes care of this | |||
| } | |||
|
|
|||
| fn try_gold_linker(&mut self) { | |||
| let gold_exists = Path::new("/usr/bin/ld.gold").exists(); | |||
This comment has been minimized.
This comment has been minimized.
nagisa
Nov 21, 2015
Contributor
You should check for it in all pathes listed in $PATH, not hard-code /usr/bin.
This comment has been minimized.
This comment has been minimized.
eddyb
Nov 23, 2015
Member
This is very important on, e.g. NixOS, where /usr/bin only contains env.
EDIT: Seems to have been brought up by @nagisa already.
nagisa
reviewed
Nov 21, 2015
|
|
||
| fn try_gold_linker(&mut self) { | ||
| let gold_exists = Path::new("/usr/bin/ld.gold").exists(); | ||
| let opt_out = self.sess.opts.cg.disable_gold; |
This comment has been minimized.
This comment has been minimized.
nagisa
Nov 21, 2015
Contributor
I’d rather to just have a regular if here: if self.sess.opts.cg.disable_gold { return; }
bluss
added
the
relnotes
label
Nov 21, 2015
This comment has been minimized.
This comment has been minimized.
|
r=me with probing all of |
This comment has been minimized.
This comment has been minimized.
|
I'm not sure I agree with probing Edit: Ah, I'll just do it |
This comment has been minimized.
This comment has been minimized.
|
In MinGW |
This comment has been minimized.
This comment has been minimized.
|
I'll conditionalize it on linux too then. |
This comment has been minimized.
This comment has been minimized.
|
I figured that if you go out of your way to install |
This comment has been minimized.
This comment has been minimized.
Some distribution/OSes/package managers install to /usr/local/bin by default (and do not link /usr/bin/), then there’s NixOS based things which install to random-looking pathes and may link things into arbitrary pathes. |
nagisa
reviewed
Nov 23, 2015
| @@ -515,6 +515,8 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options, | |||
| "explicitly enable the cfg(debug_assertions) directive"), | |||
| inline_threshold: Option<usize> = (None, parse_opt_uint, | |||
| "set the inlining threshold for"), | |||
| disable_gold: bool = (false, parse_bool, | |||
This comment has been minimized.
This comment has been minimized.
nagisa
Nov 23, 2015
Contributor
This is… a pretty confusing option (both its description and behaviour).
We already have -C linker which possibly swaps out gcc for something else and now we pass a special flag into linker assuming it is gcc-compatible (in absence of this option) without checking if specified linker is indeed compatible. That might make -C linker harder to use.
Maybe it would be better to have -C linker=gcc which overrides any default/dubious flags we might add?
This comment has been minimized.
This comment has been minimized.
brson
Nov 24, 2015
Author
Contributor
We already have -C linker which possibly swaps out gcc for something else and now we pass a special flag into linker assuming it is gcc-compatible (in absence of this option) without checking if specified linker is indeed compatible. That might make -C linker harder to use
As far as I can tell that is an existing problem. Even if you override the linker, rustc assumes it takes either gcc or link.exe style arguments, depending on platform. IOW I tihnk -C linker is only good for specifying a different path to the expected linker, not for using a completely different 'style' of linker.
This comment has been minimized.
This comment has been minimized.
alexcrichton
Nov 25, 2015
Member
I'm not super worried about random codegen options being deprecated at some point, an option like this is pretty flavorful and likely to only be a one-time use case (if ever), so if we in the future just hide this and make it ignored by default then it's probably not too bad.
It may be the case that gcc -fuse-ld=gold -fuse-ld=not-gold (or some similar incantation) also works, so we could just be sure to allow that pattern, but I don't know if it exists. Either way this seems fine to me for now.
This comment has been minimized.
This comment has been minimized.
|
Other than my nits, I really want this to land. |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
I've updated it to search |
nagisa
reviewed
Nov 24, 2015
|
|
||
| let gold_exists = match env::var("PATH") { | ||
| Ok(env_path) => { | ||
| env_path.split(":").any(|p| { |
This comment has been minimized.
This comment has been minimized.
nagisa
reviewed
Nov 24, 2015
| return; | ||
| } | ||
|
|
||
| let gold_exists = match env::var("PATH") { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
nagisa
reviewed
Nov 24, 2015
| @@ -199,6 +201,37 @@ impl<'a> Linker for GnuLinker<'a> { | |||
| fn export_symbols(&mut self, _: &Session, _: &CrateTranslation, _: &Path) { | |||
| // noop, visibility in object files takes care of this | |||
| } | |||
|
|
|||
| fn try_gold_linker(&mut self) { | |||
| if !cfg!(target_os = "linux") { | |||
This comment has been minimized.
This comment has been minimized.
nagisa
Nov 24, 2015
Contributor
I’m not necessarily opposed to having default on linux only, but did you consider the fact that FreeBSD, OpenBSD, DragonflyBSD, and similar UNIX-like OSes use ELF and are likely to have working ld.gold as well?
This comment has been minimized.
This comment has been minimized.
brson
Dec 1, 2015
Author
Contributor
No I didn't. I'm reluctant to impose this on them without proof it works though. We have lots of visibility into Linux, little into the BSDs. If a BSD maintainer wants gold, perhaps they can submit a follow up verifying that it works.
This comment has been minimized.
This comment has been minimized.
I wouldn't be too worried about this, personally. That seems super unlikely to ever happen (if it doesn't support windows) and even if it does exist it'll exist as |
This comment has been minimized.
This comment has been minimized.
|
A very relevant DragonflyBSD commit |
This comment has been minimized.
This comment has been minimized.
|
Gold only works reliably on x86 / x86_64 so this should probably also check that the target is x86 to avoid asking for gold on cross-compiles. Edit: maybe arm? Actually, checking that gold exists anywhere then asking for it for a cross-compile is probably bad. Maybe the check should be that the target == host and is a supported arch. |
brson
referenced this pull request
Dec 1, 2015
Closed
Investigate the impact of using Gold for linking rather than the default linker on systems where it is available #29938
This comment has been minimized.
This comment has been minimized.
|
@bstrie suggests this requires an RFC. cc @rust-lang/compiler |
brson
added
T-compiler
I-nominated
labels
Dec 1, 2015
This comment has been minimized.
This comment has been minimized.
|
@brson my ld.gold --help prints this:
Are you claiming most of these targets do not work? |
This comment has been minimized.
This comment has been minimized.
|
@nagisa No, I'm claiming I have no evidence they do. I know that I read just today that gold's powerpc support is incomplete. Edit: I see my previous statement was strongly saying gold only works on x86. That was a mistake. |
This comment has been minimized.
This comment has been minimized.
|
I made this patch more defensive. Now it only uses gold when ld.gold exists, the host is linux, the host and the target are roughly the same, and the target is x86/x86_64. As @nagisa points out there are other platforms that gold support, but I have most confidence this won't break anything on x86 linux. |
brson
force-pushed the
brson:gold
branch
from
2da4c30
to
4dc0e89
Dec 1, 2015
This comment has been minimized.
This comment has been minimized.
xitep
commented
Dec 31, 2015
|
Hello, being bound to Debian Wheezy, I'm now forced to use
Unfortunately, I'm stuck with cargo based projects containing a custom |
This comment has been minimized.
This comment has been minimized.
|
@xitep You can write a wrapper shell script for |
This comment has been minimized.
This comment has been minimized.
xitep
commented
Dec 31, 2015
|
@eddyb thank you so much for the idea! it works nicely. |
This comment has been minimized.
This comment has been minimized.
|
This might have killed play.rust-lang.org. see e.g. https://play.rust-lang.org/?gist=5dc29f8c79c267056ca2&version=nightly cc @alexcrichton @brson |
niconii
referenced this pull request
Jan 1, 2016
Closed
Playpen currently fails to compile anything in nightly channel #165
This comment has been minimized.
This comment has been minimized.
|
Another bit of incompatibility: gold does not have the same default library search path; in particular, it does not search in |
This comment has been minimized.
This comment has been minimized.
|
@birkenfeld That sounds like a distro bug rather than rustc's fault, unless it's intentional, in which case... what's the reasoning? |
This comment has been minimized.
This comment has been minimized.
|
You mean, the library being in |
This comment has been minimized.
This comment has been minimized.
|
@birkenfeld I was referring to "gold does not have the same default library search path". |
This comment has been minimized.
This comment has been minimized.
|
Ah! That, as far I could find out from quick Googling, is "normal" behavior for gold. Apparently ld.bfd includes the runtime linker search path (i.e. Possibly gold's behavior is cleaner here, I don't know. But it's definitely annoying to trip over these kinds of problems without a good way to disable gold from Cargo. |
This comment has been minimized.
This comment has been minimized.
|
@birkenfeld if gold repsects |
This comment has been minimized.
This comment has been minimized.
|
Yes, I can (and I will). Just noting this as a data point to consider before stabilizing this change (one which likely doesn't show up in a crater run). |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
This broke playpen on nightly. |
This comment has been minimized.
This comment has been minimized.
This seems really bad. So when you use the Rust downloaded from official sources, it doesn't work on Debian? I think rustc needs to be able to figure out this scenario. |
This comment has been minimized.
This comment has been minimized.
|
@xitep Do you know how we could identify configurations like yours and automatically disable gold? |
This was referenced Jan 8, 2016
This comment has been minimized.
This comment has been minimized.
|
@xitep @birkenfeld I filed issues for both the regression you identified. |
This comment has been minimized.
This comment has been minimized.
|
Thanks! |
This comment has been minimized.
This comment has been minimized.
xitep
commented
Jan 8, 2016
|
@brson many thanks! so far i haven't searched intensively, but it looks like something along the lines of you can see the full output on my debian wheezy (stable) of the |
lhecker
referenced
this pull request
in zonyitoo/coio-rs
Jan 10, 2016
This comment has been minimized.
This comment has been minimized.
lhecker
commented
Jan 10, 2016
|
I think I should mention, @brson, that |
larsbergstrom
referenced this pull request
Jan 11, 2016
Merged
Update to rustc 1.7.0-nightly (b4707ebca 2015-12-27) #9093
This comment has been minimized.
This comment has been minimized.
|
Thanks for the interesting note @lhecker. |
This comment has been minimized.
This comment has been minimized.
|
@xitep Thanks for the investigation on detecting -fuse-ld. I'm noting it in the bug. |
brson commentedNov 21, 2015
When using
ccfor linking rustc will, if gold is available (by looking for/usr/bin/ld.gold), pass-fuse-ld=goldtocc.In some scenarios gold links much faster than ld. Servo uses it to considerably speed up linking. gold behaves nearly identically to ld (though I think there are rare corner cases that don't work still). I've run this through crater and everything there continues to link.
To disable, pass
-C disable-gold.