pub enum LinkerFlavor {
Gnu(Cc, Lld),
Darwin(Cc, Lld),
WasmLld(Cc),
Unix(Cc),
Msvc(Lld),
EmCc,
Bpf,
Ptx,
Llbc,
}
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.
Llbc
LLVM bitcode linker that can be used as a self-contained
linker
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 succeeds 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.
Sourcefn to_cli(self) -> LinkerFlavorCli
fn to_cli(self) -> LinkerFlavorCli
Returns the corresponding backwards-compatible CLI flavor.
Sourcefn to_cli_counterpart(self) -> LinkerFlavorCli
fn to_cli_counterpart(self) -> LinkerFlavorCli
Returns the modern CLI flavor that is the counterpart of this flavor.
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
Sourcepub fn with_lld_enabled(self) -> LinkerFlavor
pub fn with_lld_enabled(self) -> LinkerFlavor
For flavors with an Lld
component, ensure it’s enabled. Otherwise, returns the given
flavor unmodified.
Sourcepub fn with_lld_disabled(self) -> LinkerFlavor
pub fn with_lld_disabled(self) -> LinkerFlavor
For flavors with an Lld
component, ensure it’s disabled. Otherwise, returns the given
flavor unmodified.
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 for LinkerFlavor
impl PartialEq for LinkerFlavor
Source§impl PartialOrd for LinkerFlavor
impl PartialOrd for LinkerFlavor
impl Copy for LinkerFlavor
impl Eq for LinkerFlavor
impl StructuralPartialEq for LinkerFlavor
Auto Trait Implementations§
impl DynSend for LinkerFlavor
impl DynSync for LinkerFlavor
impl Freeze for LinkerFlavor
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<'a, T> Captures<'a> for Twhere
T: ?Sized,
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 bytesLlbc
: 0 bytes