#[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
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.
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
UndefinedEntry
The entry point the linker was configured with is not defined by any object. Define the symbol, or link without an entry point.
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
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
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
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<'de> Deserialize<'de> for LinkError
impl<'de> Deserialize<'de> for LinkError
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for LinkError
Source§impl Error for LinkError
impl Error for LinkError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()