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

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 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.

source

fn to_cli(self) -> LinkerFlavorCli

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.

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) -> Selfwhere Self: Sized,

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

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

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

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

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

impl PartialEq<LinkerFlavor> for LinkerFlavor

source§

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

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

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

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

impl PartialOrd<LinkerFlavor> 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

This method 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

This method 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

This method 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

This method 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 StructuralEq for LinkerFlavor

source§

impl StructuralPartialEq for LinkerFlavor

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.

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