#[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.
| Kind | Contents | Required flags | Forbidden flags |
|---|---|---|---|
Text | machine code | ALLOC, EXEC | TLS |
Data | writable initialized data | ALLOC, WRITE | EXEC |
ReadOnlyData | constants | ALLOC | WRITE, EXEC, TLS |
Bss | zero-filled space, no bytes in the file | ALLOC | EXEC, MERGE, STRINGS |
Note | vendor notes | WRITE, EXEC, TLS, MERGE, STRINGS | |
InitArray, FiniArray, PreinitArray | pointers to constructors or destructors | ALLOC, WRITE | EXEC, TLS, MERGE, STRINGS |
Other | data 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
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
impl SectionKind
Sourcepub const fn default_flags(self) -> SectionFlags
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());Sourcepub const fn is_uninitialized(self) -> bool
pub const fn is_uninitialized(self) -> bool
Sourcepub const fn allows(self, flags: SectionFlags) -> bool
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));