Skip to main content

SectionKind

Enum SectionKind 

Source
#[non_exhaustive]
pub enum SectionKind { Text, Data, ReadOnlyData, Bss, Note, InitArray, FiniArray, PreinitArray, Other, }
Expand description

What a section holds. The kind decides how a format stores the section (an ELF section type, a COFF characteristic, a Mach-O section type) and which SectionFlags it may carry.

KindContentsRequired flagsForbidden flags
Textmachine codeALLOC, EXECTLS
Datawritable initialized dataALLOC, WRITEEXEC
ReadOnlyDataconstantsALLOCWRITE, EXEC, TLS
Bsszero-filled space, no bytes in the fileALLOCEXEC, MERGE, STRINGS
Notevendor notesWRITE, EXEC, TLS, MERGE, STRINGS
InitArray, FiniArray, PreinitArraypointers to constructors or destructorsALLOC, WRITEEXEC, TLS, MERGE, STRINGS
Otherdata not loaded at run time (comments, metadata)ALLOC, WRITE, EXEC, TLS

The rule for the first four rows is what makes a kind recoverable from a file: with ALLOC, EXEC means code, else WRITE means data, else read-only data, and without ALLOC the section is Other.

§Examples

use object_lang::{SectionFlags, SectionKind};

assert_eq!(SectionKind::Text.default_flags(), SectionFlags::ALLOC | SectionFlags::EXEC);
assert!(SectionKind::Bss.is_uninitialized());

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

Text

Executable machine code (.text).

§

Data

Writable, initialized data (.data; with TLS, .tdata).

§

ReadOnlyData

Read-only data (.rodata).

§

Bss

Zero-initialized space that takes no room in the file (.bss; with TLS, .tbss). Its size is set with with_bss_size or reserve.

§

Note

Notes for the loader or tools (SHT_NOTE in ELF).

§

InitArray

Pointers to functions run before main (.init_array).

§

FiniArray

Pointers to functions run at exit (.fini_array).

§

PreinitArray

Pointers to functions run before shared-library initializers (.preinit_array).

§

Other

Data that is not loaded at run time: comments, tool metadata, debug information.

Implementations§

Source§

impl SectionKind

Source

pub const fn default_flags(self) -> SectionFlags

The flags Section::new gives a section of this kind: the required flags in the table above.

§Examples
use object_lang::{SectionFlags, SectionKind};

assert_eq!(SectionKind::Data.default_flags(), SectionFlags::ALLOC | SectionFlags::WRITE);
assert_eq!(SectionKind::Other.default_flags(), SectionFlags::empty());
Source

pub const fn is_uninitialized(self) -> bool

Whether sections of this kind hold no bytes, only a size (Bss).

§Examples
use object_lang::SectionKind;

assert!(SectionKind::Bss.is_uninitialized());
assert!(!SectionKind::Data.is_uninitialized());
Source

pub const fn allows(self, flags: SectionFlags) -> bool

Whether flags are allowed on a section of this kind (the table on SectionKind).

§Examples
use object_lang::{SectionFlags, SectionKind};

assert!(SectionKind::Data.allows(SectionFlags::ALLOC | SectionFlags::WRITE | SectionFlags::TLS));
assert!(!SectionKind::ReadOnlyData.allows(SectionFlags::ALLOC | SectionFlags::WRITE));

Trait Implementations§

Source§

impl Clone for SectionKind

Source§

fn clone(&self) -> Self

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 Copy for SectionKind

Source§

impl Debug for SectionKind

Source§

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

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

impl Eq for SectionKind

Source§

impl Hash for SectionKind

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for SectionKind

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for SectionKind

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.