Skip to main content

LinkError

Enum LinkError 

Source
#[non_exhaustive]
pub enum LinkError { DuplicateSymbol { name: String, }, UndefinedSymbol { name: String, object: String, }, UndefinedEntry { name: String, }, InvalidSection { object: String, section: String, }, RelocationOutOfRange { object: String, section: String, offset: u64, }, RelocationOverflow { target: String, width: Width, }, LayoutOverflow, }
Expand description

The reason a link could not be completed.

A link can fail for a handful of distinct reasons: two objects claim the same symbol, a relocation or entry point names a symbol nobody defines, a relocation’s slot does not fit the section it is in or the address does not fit the slot, or the laid-out image would run past the address space. Each case points at the object, symbol, or section involved so the producer can be fixed.

The set is #[non_exhaustive]: a future linking feature (a new relocation kind, a new layout constraint) may add a variant, so a match on this type must include a wildcard arm.

§Examples

use linker_lang::{link, LinkError, Object};

// Two objects both define `main`.
let mut a = Object::new("a");
a.section(".text", [0u8; 1]);
a.define("main", ".text", 0);

let mut b = Object::new("b");
b.section(".text", [0u8; 1]);
b.define("main", ".text", 0);

match link(&[a, b]) {
    Err(LinkError::DuplicateSymbol { name }) => assert_eq!(name, "main"),
    other => panic!("expected a DuplicateSymbol error, got {other:?}"),
}

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

DuplicateSymbol

A symbol of this name is defined by more than one object. A symbol’s name is its identity across the link, so two definitions are ambiguous; rename one or drop the duplicate definition.

Fields

§name: String

The name defined more than once.

§

UndefinedSymbol

A relocation names a target symbol that no object defines. The wrapped object is the one that requested the relocation; define the symbol or remove the reference.

Fields

§name: String

The unresolved symbol name.

§object: String

The object whose relocation referenced it.

§

UndefinedEntry

The entry point the linker was configured with is not defined by any object. Define the symbol, or link without an entry point.

Fields

§name: String

The configured entry symbol name.

§

InvalidSection

A symbol or relocation names a section the object never created with Object::section. The name is almost certainly a typo for a real section.

Fields

§object: String

The object that named the section.

§section: String

The section name that does not exist in that object.

§

RelocationOutOfRange

A relocation’s slot — offset plus its Width — runs past the end of the section it patches. The producer recorded an offset the section’s bytes do not cover.

Fields

§object: String

The object that requested the relocation.

§section: String

The section the slot is in.

§offset: u64

The byte offset of the slot within the object’s section.

§

RelocationOverflow

A relocation resolved to an address that does not fit its Width — it is negative after the addend, or larger than the width can hold. Widen the slot or adjust the layout so the address fits.

Fields

§target: String

The symbol whose resolved address overflowed.

§width: Width

The width the address had to fit.

§

LayoutOverflow

The laid-out image would extend past the end of the 64-bit address space. The base address plus the total section size does not fit in a u64.

Trait Implementations§

Source§

impl Clone for LinkError

Source§

fn clone(&self) -> LinkError

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for LinkError

Source§

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

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

impl<'de> Deserialize<'de> for LinkError

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for LinkError

Source§

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

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

impl Eq for LinkError

Source§

impl Error for LinkError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl PartialEq for LinkError

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 Serialize for LinkError

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for LinkError

Auto Trait Implementations§

Blanket Implementations§

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, dest: *mut u8)

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.