Enum rustc_target::spec::LinkerFlavor
source · pub enum LinkerFlavor {
Gnu(Cc, Lld),
Darwin(Cc, Lld),
WasmLld(Cc),
Unix(Cc),
Msvc(Lld),
EmCc,
Bpf,
Ptx,
}
Expand description
All linkers have some kinds of command line interfaces and rustc needs to know which commands to use with each of them. So we cluster all such interfaces into a (somewhat arbitrary) number of classes that we call “linker flavors”.
Technically, it’s not even necessary, we can nearly always infer the flavor from linker name
and target properties like is_like_windows
/is_like_osx
/etc. However, the PRs originally
introducing -Clinker-flavor
(#40018 and friends) were aiming to reduce this kind of inference
and provide something certain and explicitly specified instead, and that design goal is still
relevant now.
The second goal is to keep the number of flavors to the minimum if possible.
LLD somewhat forces our hand here because that linker is self-sufficient only if its executable
(argv[0]
) is named in specific way, otherwise it doesn’t work and requires a
-flavor LLD_FLAVOR
argument to choose which logic to use. Our shipped rust-lld
in
particular is not named in such specific way, so it needs the flavor option, so we make our
linker flavors sufficiently fine-grained to satisfy LLD without inferring its flavor from other
target properties, in accordance with the first design goal.
The first component of the flavor is tightly coupled with the compilation target,
while the Cc
and Lld
flags can vary within the same target.
Variants§
Gnu(Cc, Lld)
Unix-like linker with GNU extensions (both naked and compiler-wrapped forms). Besides similar “default” Linux/BSD linkers this also includes Windows/GNU linker, which is somewhat different because it doesn’t produce ELFs.
Darwin(Cc, Lld)
Unix-like linker for Apple targets (both naked and compiler-wrapped forms).
Extracted from the “umbrella” Unix
flavor due to its corresponding LLD flavor.
WasmLld(Cc)
Unix-like linker for Wasm targets (both naked and compiler-wrapped forms).
Extracted from the “umbrella” Unix
flavor due to its corresponding LLD flavor.
Non-LLD version does not exist, so the lld flag is currently hardcoded here.
Unix(Cc)
Basic Unix-like linker for “any other Unix” targets (Solaris/illumos, L4Re, MSP430, etc), possibly with non-GNU extensions (both naked and compiler-wrapped forms). LLD doesn’t support any of these.
Msvc(Lld)
MSVC-style linker for Windows and UEFI, LLD supports it.
EmCc
Emscripten Compiler Frontend, a wrapper around WasmLld(Cc::Yes)
that has a different
interface and produces some additional JavaScript output.
Bpf
Linker tool for BPF.
Ptx
Linker tool for Nvidia PTX.
Implementations§
source§impl LinkerFlavor
impl LinkerFlavor
sourcefn from_cli_json(
cli: LinkerFlavorCli,
lld_flavor: LldFlavor,
is_gnu: bool
) -> LinkerFlavor
fn from_cli_json( cli: LinkerFlavorCli, lld_flavor: LldFlavor, is_gnu: bool ) -> LinkerFlavor
At this point the target’s reference linker flavor doesn’t yet exist and we need to infer it. The inference always succeds and gives some result, and we don’t report any flavor incompatibility errors for json target specs. The CLI flavor is used as the main source of truth, other flags are used in case of ambiguities.
fn to_cli(self) -> LinkerFlavorCli
fn infer_cli_hints(cli: LinkerFlavorCli) -> (Option<Cc>, Option<Lld>)
fn infer_linker_hints(linker_stem: &str) -> (Option<Cc>, Option<Lld>)
fn with_hints( self, (cc_hint, lld_hint): (Option<Cc>, Option<Lld>) ) -> LinkerFlavor
pub fn with_cli_hints(self, cli: LinkerFlavorCli) -> LinkerFlavor
pub fn with_linker_hints(self, linker_stem: &str) -> LinkerFlavor
pub fn check_compatibility(self, cli: LinkerFlavorCli) -> Option<String>
pub fn lld_flavor(self) -> LldFlavor
pub fn is_gnu(self) -> bool
Trait Implementations§
source§impl Clone for LinkerFlavor
impl Clone for LinkerFlavor
source§fn clone(&self) -> LinkerFlavor
fn clone(&self) -> LinkerFlavor
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for LinkerFlavor
impl Debug for LinkerFlavor
source§impl Ord for LinkerFlavor
impl Ord for LinkerFlavor
source§fn cmp(&self, other: &LinkerFlavor) -> Ordering
fn cmp(&self, other: &LinkerFlavor) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
source§impl PartialEq<LinkerFlavor> for LinkerFlavor
impl PartialEq<LinkerFlavor> for LinkerFlavor
source§fn eq(&self, other: &LinkerFlavor) -> bool
fn eq(&self, other: &LinkerFlavor) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd<LinkerFlavor> for LinkerFlavor
impl PartialOrd<LinkerFlavor> for LinkerFlavor
source§fn partial_cmp(&self, other: &LinkerFlavor) -> Option<Ordering>
fn partial_cmp(&self, other: &LinkerFlavor) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl Copy for LinkerFlavor
impl Eq for LinkerFlavor
impl StructuralEq for LinkerFlavor
impl StructuralPartialEq for LinkerFlavor
Auto Trait Implementations§
impl RefUnwindSafe for LinkerFlavor
impl Send for LinkerFlavor
impl Sync for LinkerFlavor
impl Unpin for LinkerFlavor
impl UnwindSafe for LinkerFlavor
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 3 bytes
Size for each variant:
Gnu
: 2 bytesDarwin
: 2 bytesWasmLld
: 1 byteUnix
: 1 byteMsvc
: 1 byteEmCc
: 0 bytesBpf
: 0 bytesPtx
: 0 bytes