pub enum Directives {
Elf,
MachO,
Coff,
}Expand description
The directives one object format wraps a function in.
Variants§
Elf
ELF, which is Linux and the freestanding targets.
MachO
Mach-O, which is Apple’s.
Coff
COFF, which is Windows.
Implementations§
Source§impl Directives
impl Directives
Sourcepub const fn of(format: ObjectFormat) -> Directives
pub const fn of(format: ObjectFormat) -> Directives
The directives that go with that object format.
Sourcepub const fn symbol(self) -> &'static str
pub const fn symbol(self) -> &'static str
What goes in front of a C name to make the name the linker sees.
Mach-O keeps the underscore that every Unix linker once had, so main in C is _main in
the object, and a listing that leaves it off refers to a symbol nothing defines.
Sourcepub const fn local(self) -> &'static str
pub const fn local(self) -> &'static str
What goes in front of a label that belongs to one function and leaves no symbol behind.
Sourcepub fn code(self, out: &mut String, name: &str, sections: Sections)
pub fn code(self, out: &mut String, name: &str, sections: Sections)
The directive that opens the section one function goes in, and nothing at all when they are all going in the same one.
Nothing on Mach-O either, whatever was asked for. Every Mach-O object ends with
.subsections_via_symbols, which tells the linker it may split a section at each symbol in
it and drop the parts nothing reaches, so the format does by default what the flag asks a
linker to be able to do and there is nothing left for it to change. Clang takes both flags
on an Apple target and writes one text section, which is the same answer.
ELF names the section after the function and COFF gives one name to several sections and
tells the linker which symbol each belongs to. The COFF form is a COMDAT, which is more
than the ELF one says: a linker keeps one section out of every group that names the same
symbol. That is what a Windows toolchain does with /Gy, and it is what clang writes for
-ffunction-sections on a Windows target, so it is what a Windows linker is expecting.
Sourcepub fn open(
self,
out: &mut String,
name: &str,
align: u32,
binding: Binding,
visibility: Visibility,
)
pub fn open( self, out: &mut String, name: &str, align: u32, binding: Binding, visibility: Visibility, )
What is said about a function before its first instruction.
The binding is written the way it is written for a variable, and a local one gets no
directive at all: a name no directive mentions is still in the symbol table, as a local,
which is what static is. Windows says the same thing as a storage class, where three is
the local one and two the rest.
align is in bytes and is a power of two, and the padding is 0x90 because the space in
front of a function is reached by falling off the end of the one before it.
Sourcepub fn seen(
self,
out: &mut String,
name: &str,
binding: Binding,
visibility: Visibility,
)
pub fn seen( self, out: &mut String, name: &str, binding: Binding, visibility: Visibility, )
What is said about how far a name reaches outside a shared library, which is nothing at all in the ordinary case.
A local name gets no directive whatever was asked for. static is already invisible to
everything outside the file, so there is no dynamic symbol table for it to be in or out of,
and gcc writes no visibility directive for one either.
ELF says both of the other two and says them the same way an assembler expects. Mach-O has
one of them: .private_extern is a symbol that leaves this object and does not leave the
library, which is what hidden means, and there is no Mach-O spelling of protected because
the format has no way to say a symbol is exported and cannot be interposed. COFF has
neither, since what leaves a Windows DLL is decided by an export table the linker is given
rather than by a bit on each symbol.
Sourcepub fn section(
self,
out: &mut String,
place: &Place,
name: &str,
sections: Sections,
)
pub fn section( self, out: &mut String, place: &Place, name: &str, sections: Sections, )
The directive that opens the section a variable goes in.
The three formats disagree about the names and about how much has to be said. ELF and COFF have a directive per section that every assembler knows, and both want the flags spelled out for a section the program named, since nothing else says whether it may be written to. Mach-O has one directive and a segment in front of every section name.
name is the variable’s, which matters only when it is being given a section of its own.
Sourcepub fn variable(
self,
out: &mut String,
var: &Variable,
sections: Sections,
) -> bool
pub fn variable( self, out: &mut String, var: &Variable, sections: Sections, ) -> bool
What is said about a variable before its image, and whether an image follows.
Two kinds of variable are one directive rather than a section, a label and bytes. A tentative definition is a request to the linker for that much zeroed space on every format, and on Mach-O so is a variable whose image is all zeros, because the section that would hold it is one nothing may write bytes into.
Sourcepub fn close(self, out: &mut String, name: &str)
pub fn close(self, out: &mut String, name: &str)
What is said about a function after its last instruction.
The size, on the format that has one. It is written as the distance from the label to here rather than as a number, because the assembler is the one that knows how long an instruction turned out to be and this file is what it is about to find out from.
Sourcepub fn alias(self, out: &mut String, alias: &Alias)
pub fn alias(self, out: &mut String, alias: &Alias)
A second name for something the file already wrote down.
The binding and then .set, which is all gcc writes and all an assembler needs: the type
and the size of the new symbol are taken from the old one, so writing them again would
only be a second chance to disagree. Nothing opens a section first, because the symbol is
an entry in a table rather than a byte of anything, and no .size closes it for the same
reason.
Trait Implementations§
Source§impl Clone for Directives
impl Clone for Directives
Source§fn clone(&self) -> Directives
fn clone(&self) -> Directives
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for Directives
Source§impl Debug for Directives
impl Debug for Directives
impl Eq for Directives
Source§impl PartialEq for Directives
impl PartialEq for Directives
impl StructuralPartialEq for Directives
Auto Trait Implementations§
impl Freeze for Directives
impl RefUnwindSafe for Directives
impl Send for Directives
impl Sync for Directives
impl Unpin for Directives
impl UnsafeUnpin for Directives
impl UnwindSafe for Directives
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.