Description
from rustc -C help
we're told that:
-C linker=val -- system linker to link outputs with
I mistakenly thought that this accepted a path to a system linker (e.g., /usr/bin/ld
on GNU/Linux or OSX); instead it really seems to want a compiler driver like cc
or clang
.
For example, one would expect the following two invocations to be the same (on a typical GNU/Linux system) if it expected an actual linker:
rustc
rustc -C linker=/usr/bin/ld
but the second errors out because ld
does not understand the emulation mode "64":
note: /usr/bin/ld: unrecognised emulation mode: 64
(but cc
does)
Besides being misleading, the current invocation seems to require the hard-coded command line arguments to be understood by whatever "linker" (compiler driver) is passed.
Perhaps if you're only targetting cc
derivatives this might suffice. But if the flag is for switching out the linker (e.g., using gold instead of ld, or even lld), the current implementation simply will not work.
For example, suppose we're on GNU/Linux and we have our main.rs
, and we compile it with the new shiny --target
switches from nightly like so:
rustc --target=x86_64-apple-darwin main.rs
we'll error out in the linking phase, since cc
is trying to link a mach-o binary using the system linker, /usr/bin/ld
, which only understands ELF binaries.
I naively thought this was what the -C linker
flag was for, for the above reasons, and so tried:
rustc --target=x86_64-apple-darwin -C linker=lld main.rs
But this of course won't work because:
- lld actually requires
-flavor darwin
, etc. flags passed and the current linker= does not facilitate calling it appropriately - the hard-coded flags are for
cc
-esque driver.
So if the purpose of the -C linker
flag is really a compiler driver, then probably -C driver
would be a better name (and at the very least change the -C help output for the flag), but if not, then there's some work cut out... I'm thinking in the latter case it might almost be best if when the user specifies a -C linker
then all linking flags are cleared, and it's up to the user to pass the appropriate flags via -C linker-flags
.