rustc_target::spec

Enum 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,

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> Pointable for T

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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