pub enum Reference {
Call,
Data,
Got,
Thread,
Address {
bytes: u8,
},
Image,
}Expand description
What kind of thing a relocation is asking the linker for.
The first four are the distance from the end of an instruction to something, which is what every reference the code makes is, because this compiler generates position independent code and nothing else. They are told apart by what the linker is allowed to do about each one. The last two are not distances from an instruction at all and are what a table of data asks for: the address itself, which is what an initializer holding the address of something holds, and how far something is from the front of the image, which is what a table the runtime reads holds.
Variants§
Call
A call, which the linker may satisfy with a stub that reaches further than the four bytes
would. R_X86_64_PLT32 on ELF, and the same relocation a branch gets on the other two.
Data
A datum, reached from the instruction pointer. R_X86_64_PC32 on ELF.
Got
A slot of the global offset table, reached from the instruction pointer, holding the address of something another object may be the one that defines.
The distance to the slot rather than to the thing, which is the whole difference: the
distance to the thing is a number only a link that puts the thing in this program can
work out, and a shared library is a link that does not. R_X86_64_REX_GOTPCRELX on ELF,
which says the instruction is a mov with a REX prefix and lets the linker turn it back
into the lea it would have been if the symbol had been here all along.
Thread
A slot of the global offset table, reached from the instruction pointer, holding how far into a thread’s own block of storage a thread-local variable sits.
An offset and not an address, which is what makes it a different relocation from the one
above rather than the same one against a different symbol: a thread-local variable has one
copy per thread and therefore no address for a link to write down, and what every copy has
in common is where it sits inside the block. Adding the block’s own address, which the
machine keeps in a segment register, is what turns one into the other, and that addition is
in the code rather than in the relocation. R_X86_64_GOTTPOFF on ELF, which the linker
turns into a constant in the instruction when it is making an executable and therefore
knows how the blocks are laid out.
Address
The address itself, written into an image. int *p = &y; and nothing else in C.
Fields
Image
How far the thing is from the front of the loaded image, written into four bytes.
What every field of a Windows unwind table is. The table is read at run time by code that
already has the image’s own address, so four bytes of distance from it reach anything in an
image a linker will build, which eight bytes of address would have cost twice as much to say
and a distance from the table itself could not have said at all: a row is looked up by
address in a sorted table, and a row whose meaning depended on where the row was would not
sort. IMAGE_REL_AMD64_ADDR32NB.
ELF has no relocation of this kind because nothing it writes asks the question. Its unwind records are found by walking rather than by binary search, and what they hold is the ordinary distance from the record to the function.
Trait Implementations§
impl Copy for Reference
impl Eq for Reference
impl StructuralPartialEq for Reference
Auto Trait Implementations§
impl Freeze for Reference
impl RefUnwindSafe for Reference
impl Send for Reference
impl Sync for Reference
impl Unpin for Reference
impl UnsafeUnpin for Reference
impl UnwindSafe for Reference
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.