]>
git.proxmox.com Git - rustc.git/blob - vendor/object/src/common.rs
1 /// A CPU architecture.
3 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5 pub enum Architecture
{
13 #[allow(non_camel_case_types)]
30 /// The size of an address value for this architecture.
32 /// Returns `None` for unknown architectures.
33 pub fn address_size(self) -> Option
<AddressSize
> {
35 Architecture
::Unknown
=> None
,
36 Architecture
::Aarch64
=> Some(AddressSize
::U64
),
37 Architecture
::Arm
=> Some(AddressSize
::U32
),
38 Architecture
::Avr
=> Some(AddressSize
::U8
),
39 Architecture
::Bpf
=> Some(AddressSize
::U64
),
40 Architecture
::I386
=> Some(AddressSize
::U32
),
41 Architecture
::X86_64
=> Some(AddressSize
::U64
),
42 Architecture
::X86_64_X32
=> Some(AddressSize
::U32
),
43 Architecture
::Hexagon
=> Some(AddressSize
::U32
),
44 Architecture
::LoongArch64
=> Some(AddressSize
::U64
),
45 Architecture
::Mips
=> Some(AddressSize
::U32
),
46 Architecture
::Mips64
=> Some(AddressSize
::U64
),
47 Architecture
::Msp430
=> Some(AddressSize
::U16
),
48 Architecture
::PowerPc
=> Some(AddressSize
::U32
),
49 Architecture
::PowerPc64
=> Some(AddressSize
::U64
),
50 Architecture
::Riscv32
=> Some(AddressSize
::U32
),
51 Architecture
::Riscv64
=> Some(AddressSize
::U64
),
52 Architecture
::S390x
=> Some(AddressSize
::U64
),
53 Architecture
::Sparc64
=> Some(AddressSize
::U64
),
54 Architecture
::Wasm32
=> Some(AddressSize
::U32
),
59 /// The size of an address value for an architecture.
61 /// This may differ from the address size supported by the file format (such as for COFF).
62 #[allow(missing_docs)]
63 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
66 pub enum AddressSize
{
74 /// The size in bytes of an address value.
76 pub fn bytes(self) -> u8 {
81 /// A binary file format.
82 #[allow(missing_docs)]
83 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
85 pub enum BinaryFormat
{
93 /// The kind of a section.
94 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
96 pub enum SectionKind
{
97 /// The section kind is unknown.
99 /// An executable code section.
101 /// Example ELF sections: `.text`
103 /// Example Mach-O sections: `__TEXT/__text`
107 /// Example ELF sections: `.data`
109 /// Example Mach-O sections: `__DATA/__data`
111 /// A read only data section.
113 /// Example ELF sections: `.rodata`
115 /// Example Mach-O sections: `__TEXT/__const`, `__DATA/__const`, `__TEXT/__literal4`
117 /// A loadable string section.
119 /// Example ELF sections: `.rodata.str`
121 /// Example Mach-O sections: `__TEXT/__cstring`
123 /// An uninitialized data section.
125 /// Example ELF sections: `.bss`
127 /// Example Mach-O sections: `__DATA/__bss`
129 /// An uninitialized common data section.
131 /// Example Mach-O sections: `__DATA/__common`
133 /// A TLS data section.
135 /// Example ELF sections: `.tdata`
137 /// Example Mach-O sections: `__DATA/__thread_data`
139 /// An uninitialized TLS data section.
141 /// Example ELF sections: `.tbss`
143 /// Example Mach-O sections: `__DATA/__thread_bss`
145 /// A TLS variables section.
147 /// This contains TLS variable structures, rather than the variable initializers.
149 /// Example Mach-O sections: `__DATA/__thread_vars`
151 /// A non-loadable string section.
153 /// Example ELF sections: `.comment`, `.debug_str`
155 /// Some other non-loadable section.
157 /// Example ELF sections: `.debug_info`
159 /// Debug information.
161 /// Example Mach-O sections: `__DWARF/__debug_info`
163 /// Information for the linker.
165 /// Example COFF sections: `.drectve`
167 /// ELF note section.
169 /// Metadata such as symbols or relocations.
171 /// Example ELF sections: `.symtab`, `.strtab`, `.group`
173 /// Some other ELF section type.
175 /// This is the `sh_type` field in the section header.
176 /// The meaning may be dependent on the architecture.
181 /// Return true if this section contains zerofill data.
182 pub fn is_bss(self) -> bool
{
183 self == SectionKind
::UninitializedData
184 || self == SectionKind
::UninitializedTls
185 || self == SectionKind
::Common
189 /// The selection kind for a COMDAT section group.
191 /// This determines the way in which the linker resolves multiple definitions of the COMDAT
193 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
195 pub enum ComdatKind
{
196 /// The selection kind is unknown.
198 /// Multiple definitions are allowed.
200 /// An arbitrary definition is selected, and the rest are removed.
202 /// This is the only supported selection kind for ELF.
204 /// Multiple definitions are not allowed.
206 /// This is used to group sections without allowing duplicates.
208 /// Multiple definitions must have the same size.
210 /// An arbitrary definition is selected, and the rest are removed.
212 /// Multiple definitions must match exactly.
214 /// An arbitrary definition is selected, and the rest are removed.
216 /// Multiple definitions are allowed, and the largest is selected.
218 /// An arbitrary definition with the largest size is selected, and the rest are removed.
220 /// Multiple definitions are allowed, and the newest is selected.
224 /// The kind of a symbol.
225 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
227 pub enum SymbolKind
{
228 /// The symbol kind is unknown.
230 /// The symbol is a null placeholder.
232 /// The symbol is for executable code.
234 /// The symbol is for a data object.
236 /// The symbol is for a section.
238 /// The symbol is the name of a file. It precedes symbols within that file.
240 /// The symbol is for a code label.
242 /// The symbol is for a thread local storage entity.
247 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
248 pub enum SymbolScope
{
251 /// Symbol is visible to the compilation unit.
253 /// Symbol is visible to the static linkage unit.
255 /// Symbol is visible to dynamically linked objects.
259 /// The operation used to calculate the result of the relocation.
261 /// The relocation descriptions use the following definitions. Note that
262 /// these definitions probably don't match any ELF ABI.
264 /// * A - The value of the addend.
265 /// * G - The address of the symbol's entry within the global offset table.
266 /// * L - The address of the symbol's entry within the procedure linkage table.
267 /// * P - The address of the place of the relocation.
268 /// * S - The address of the symbol.
269 /// * GotBase - The address of the global offset table.
270 /// * Image - The base address of the image.
271 /// * Section - The address of the section containing the symbol.
273 /// 'XxxRelative' means 'Xxx + A - P'. 'XxxOffset' means 'S + A - Xxx'.
274 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
276 pub enum RelocationKind
{
295 /// The index of the section containing the symbol.
297 /// Some other ELF relocation. The value is dependent on the architecture.
299 /// Some other Mach-O relocation. The value is dependent on the architecture.
301 /// The relocation type.
303 /// Whether the relocation is relative to the place.
306 /// Some other COFF relocation. The value is dependent on the architecture.
310 /// Information about how the result of the relocation operation is encoded in the place.
312 /// This is usually architecture specific, such as specifying an addressing mode or
313 /// a specific instruction.
314 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
316 pub enum RelocationEncoding
{
317 /// Generic encoding.
320 /// x86 sign extension at runtime.
322 /// Used with `RelocationKind::Absolute`.
324 /// x86 rip-relative addressing.
326 /// The `RelocationKind` must be PC relative.
328 /// x86 rip-relative addressing in movq instruction.
330 /// The `RelocationKind` must be PC relative.
332 /// x86 branch instruction.
334 /// The `RelocationKind` must be PC relative.
337 /// s390x PC-relative offset shifted right by one bit.
339 /// The `RelocationKind` must be PC relative.
342 /// AArch64 call target.
344 /// The `RelocationKind` must be PC relative.
348 /// File flags that are specific to each file format.
349 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
356 /// `os_abi` field in the ELF file header.
358 /// `abi_version` field in the ELF file header.
360 /// `e_flags` field in the ELF file header.
363 /// Mach-O file flags.
365 /// `flags` field in the Mach-O file header.
370 /// `Characteristics` field in the COFF file header.
371 characteristics
: u16,
375 /// Segment flags that are specific to each file format.
376 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
378 pub enum SegmentFlags
{
379 /// No segment flags.
381 /// ELF segment flags.
383 /// `p_flags` field in the segment header.
386 /// Mach-O segment flags.
388 /// `flags` field in the segment header.
390 /// `maxprot` field in the segment header.
392 /// `initprot` field in the segment header.
395 /// COFF segment flags.
397 /// `Characteristics` field in the segment header.
398 characteristics
: u32,
402 /// Section flags that are specific to each file format.
403 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
405 pub enum SectionFlags
{
406 /// No section flags.
408 /// ELF section flags.
410 /// `sh_flags` field in the section header.
413 /// Mach-O section flags.
415 /// `flags` field in the section header.
418 /// COFF section flags.
420 /// `Characteristics` field in the section header.
421 characteristics
: u32,
425 /// Symbol flags that are specific to each file format.
426 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
428 pub enum SymbolFlags
<Section
> {
431 /// ELF symbol flags.
433 /// `st_info` field in the ELF symbol.
435 /// `st_other` field in the ELF symbol.
438 /// Mach-O symbol flags.
440 /// `n_desc` field in the Mach-O symbol.
443 /// COFF flags for a section symbol.
445 /// `Selection` field in the auxiliary symbol for the section.
447 /// `Number` field in the auxiliary symbol for the section.
448 associative_section
: Option
<Section
>,