Enum rustc_target::spec::LinkerFlavor

source ·
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

source

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.

source

fn to_cli(self) -> LinkerFlavorCli

Returns the corresponding backwards-compatible CLI flavor.

source

fn to_cli_counterpart(self) -> LinkerFlavorCli

Returns the modern CLI flavor that is the counterpart of this flavor.

source

fn infer_cli_hints(cli: LinkerFlavorCli) -> (Option<Cc>, Option<Lld>)

source

fn infer_linker_hints(linker_stem: &str) -> (Option<Cc>, Option<Lld>)

source

fn with_hints( self, (cc_hint, lld_hint): (Option<Cc>, Option<Lld>), ) -> LinkerFlavor

source

pub fn with_cli_hints(self, cli: LinkerFlavorCli) -> LinkerFlavor

source

pub fn with_linker_hints(self, linker_stem: &str) -> LinkerFlavor

source

pub fn check_compatibility(self, cli: LinkerFlavorCli) -> Option<String>

source

pub fn lld_flavor(self) -> LldFlavor

source

pub fn is_gnu(self) -> bool

source

pub fn uses_lld(self) -> bool

Returns whether the flavor uses the lld linker.

source

pub fn uses_cc(self) -> bool

Returns whether the flavor calls the linker via a C/C++ compiler.

source

pub fn with_lld_enabled(self) -> LinkerFlavor

For flavors with an Lld component, ensure it’s enabled. Otherwise, returns the given flavor unmodified.

source

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

source§

fn clone(&self) -> LinkerFlavor

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for LinkerFlavor

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Ord for LinkerFlavor

source§

fn cmp(&self, other: &LinkerFlavor) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for LinkerFlavor

source§

fn eq(&self, other: &LinkerFlavor) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for LinkerFlavor

source§

fn partial_cmp(&self, other: &LinkerFlavor) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Copy for LinkerFlavor

source§

impl Eq for LinkerFlavor

source§

impl StructuralPartialEq for LinkerFlavor

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Aligned for T

source§

const ALIGN: Alignment = _

Alignment of Self.
source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<'a, T> Captures<'a> for T
where 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 bytes
  • Darwin: 2 bytes
  • WasmLld: 1 byte
  • Unix: 1 byte
  • Msvc: 1 byte
  • EmCc: 0 bytes
  • Bpf: 0 bytes
  • Ptx: 0 bytes
  • Llbc: 0 bytes