]>
git.proxmox.com Git - rustc.git/blob - vendor/object-0.26.2/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)]
29 /// The size of an address value for this architecture.
31 /// Returns `None` for unknown architectures.
32 pub fn address_size(self) -> Option
<AddressSize
> {
34 Architecture
::Unknown
=> None
,
35 Architecture
::Aarch64
=> Some(AddressSize
::U64
),
36 Architecture
::Arm
=> Some(AddressSize
::U32
),
37 Architecture
::Avr
=> Some(AddressSize
::U8
),
38 Architecture
::Bpf
=> Some(AddressSize
::U64
),
39 Architecture
::I386
=> Some(AddressSize
::U32
),
40 Architecture
::X86_64
=> Some(AddressSize
::U64
),
41 Architecture
::X86_64_X32
=> Some(AddressSize
::U32
),
42 Architecture
::Hexagon
=> Some(AddressSize
::U32
),
43 Architecture
::Mips
=> Some(AddressSize
::U32
),
44 Architecture
::Mips64
=> Some(AddressSize
::U64
),
45 Architecture
::Msp430
=> Some(AddressSize
::U16
),
46 Architecture
::PowerPc
=> Some(AddressSize
::U32
),
47 Architecture
::PowerPc64
=> Some(AddressSize
::U64
),
48 Architecture
::Riscv32
=> Some(AddressSize
::U32
),
49 Architecture
::Riscv64
=> Some(AddressSize
::U64
),
50 Architecture
::S390x
=> Some(AddressSize
::U64
),
51 Architecture
::Sparc64
=> Some(AddressSize
::U64
),
52 Architecture
::Wasm32
=> Some(AddressSize
::U32
),
57 /// The size of an address value for an architecture.
59 /// This may differ from the address size supported by the file format (such as for COFF).
60 #[allow(missing_docs)]
61 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
64 pub enum AddressSize
{
72 /// The size in bytes of an address value.
74 pub fn bytes(self) -> u8 {
79 /// A binary file format.
80 #[allow(missing_docs)]
81 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
83 pub enum BinaryFormat
{
91 /// The kind of a section.
92 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
94 pub enum SectionKind
{
95 /// The section kind is unknown.
97 /// An executable code section.
99 /// Example ELF sections: `.text`
101 /// Example Mach-O sections: `__TEXT/__text`
105 /// Example ELF sections: `.data`
107 /// Example Mach-O sections: `__DATA/__data`
109 /// A read only data section.
111 /// Example ELF sections: `.rodata`
113 /// Example Mach-O sections: `__TEXT/__const`, `__DATA/__const`, `__TEXT/__literal4`
115 /// A loadable string section.
117 /// Example ELF sections: `.rodata.str`
119 /// Example Mach-O sections: `__TEXT/__cstring`
121 /// An uninitialized data section.
123 /// Example ELF sections: `.bss`
125 /// Example Mach-O sections: `__DATA/__bss`
127 /// An uninitialized common data section.
129 /// Example Mach-O sections: `__DATA/__common`
131 /// A TLS data section.
133 /// Example ELF sections: `.tdata`
135 /// Example Mach-O sections: `__DATA/__thread_data`
137 /// An uninitialized TLS data section.
139 /// Example ELF sections: `.tbss`
141 /// Example Mach-O sections: `__DATA/__thread_bss`
143 /// A TLS variables section.
145 /// This contains TLS variable structures, rather than the variable initializers.
147 /// Example Mach-O sections: `__DATA/__thread_vars`
149 /// A non-loadable string section.
151 /// Example ELF sections: `.comment`, `.debug_str`
153 /// Some other non-loadable section.
155 /// Example ELF sections: `.debug_info`
157 /// Debug information.
159 /// Example Mach-O sections: `__DWARF/__debug_info`
161 /// Information for the linker.
163 /// Example COFF sections: `.drectve`
165 /// ELF note section.
167 /// Metadata such as symbols or relocations.
169 /// Example ELF sections: `.symtab`, `.strtab`, `.group`
171 /// Some other ELF section type.
173 /// This is the `sh_type` field in the section header.
174 /// The meaning may be dependent on the architecture.
179 /// Return true if this section contains zerofill data.
180 pub fn is_bss(self) -> bool
{
181 self == SectionKind
::UninitializedData
182 || self == SectionKind
::UninitializedTls
183 || self == SectionKind
::Common
187 /// The selection kind for a COMDAT section group.
189 /// This determines the way in which the linker resolves multiple definitions of the COMDAT
191 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
193 pub enum ComdatKind
{
194 /// The selection kind is unknown.
196 /// Multiple definitions are allowed.
198 /// An arbitrary definition is selected, and the rest are removed.
200 /// This is the only supported selection kind for ELF.
202 /// Multiple definitions are not allowed.
204 /// This is used to group sections without allowing duplicates.
206 /// Multiple definitions must have the same size.
208 /// An arbitrary definition is selected, and the rest are removed.
210 /// Multiple definitions must match exactly.
212 /// An arbitrary definition is selected, and the rest are removed.
214 /// Multiple definitions are allowed, and the largest is selected.
216 /// An arbitrary definition with the largest size is selected, and the rest are removed.
218 /// Multiple definitions are allowed, and the newest is selected.
222 /// The kind of a symbol.
223 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
225 pub enum SymbolKind
{
226 /// The symbol kind is unknown.
228 /// The symbol is a null placeholder.
230 /// The symbol is for executable code.
232 /// The symbol is for a data object.
234 /// The symbol is for a section.
236 /// The symbol is the name of a file. It precedes symbols within that file.
238 /// The symbol is for a code label.
240 /// The symbol is for a thread local storage entity.
245 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
246 pub enum SymbolScope
{
249 /// Symbol is visible to the compilation unit.
251 /// Symbol is visible to the static linkage unit.
253 /// Symbol is visible to dynamically linked objects.
257 /// The operation used to calculate the result of the relocation.
259 /// The relocation descriptions use the following definitions. Note that
260 /// these definitions probably don't match any ELF ABI.
262 /// * A - The value of the addend.
263 /// * G - The address of the symbol's entry within the global offset table.
264 /// * L - The address of the symbol's entry within the procedure linkage table.
265 /// * P - The address of the place of the relocation.
266 /// * S - The address of the symbol.
267 /// * GotBase - The address of the global offset table.
268 /// * Image - The base address of the image.
269 /// * Section - The address of the section containing the symbol.
271 /// 'XxxRelative' means 'Xxx + A - P'. 'XxxOffset' means 'S + A - Xxx'.
272 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
274 pub enum RelocationKind
{
293 /// The index of the section containing the symbol.
295 /// Some other ELF relocation. The value is dependent on the architecture.
297 /// Some other Mach-O relocation. The value is dependent on the architecture.
299 /// The relocation type.
301 /// Whether the relocation is relative to the place.
304 /// Some other COFF relocation. The value is dependent on the architecture.
308 /// Information about how the result of the relocation operation is encoded in the place.
310 /// This is usually architecture specific, such as specifying an addressing mode or
311 /// a specific instruction.
312 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
314 pub enum RelocationEncoding
{
315 /// Generic encoding.
318 /// x86 sign extension at runtime.
320 /// Used with `RelocationKind::Absolute`.
322 /// x86 rip-relative addressing.
324 /// The `RelocationKind` must be PC relative.
326 /// x86 rip-relative addressing in movq instruction.
328 /// The `RelocationKind` must be PC relative.
330 /// x86 branch instruction.
332 /// The `RelocationKind` must be PC relative.
335 /// s390x PC-relative offset shifted right by one bit.
337 /// The `RelocationKind` must be PC relative.
340 /// AArch64 call target.
342 /// The `RelocationKind` must be PC relative.
346 /// File flags that are specific to each file format.
347 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
354 /// `e_flags` field in the ELF file header.
357 /// Mach-O file flags.
359 /// `flags` field in the Mach-O file header.
364 /// `Characteristics` field in the COFF file header.
365 characteristics
: u16,
369 /// Section flags that are specific to each file format.
370 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
372 pub enum SectionFlags
{
373 /// No section flags.
375 /// ELF section flags.
377 /// `sh_flags` field in the section header.
380 /// Mach-O section flags.
382 /// `flags` field in the section header.
385 /// COFF section flags.
387 /// `Characteristics` field in the section header.
388 characteristics
: u32,
392 /// Symbol flags that are specific to each file format.
393 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
395 pub enum SymbolFlags
<Section
> {
398 /// ELF symbol flags.
400 /// `st_info` field in the ELF symbol.
402 /// `st_other` field in the ELF symbol.
405 /// Mach-O symbol flags.
407 /// `n_desc` field in the Mach-O symbol.
410 /// COFF flags for a section symbol.
412 /// `Selection` field in the auxiliary symbol for the section.
414 /// `Number` field in the auxiliary symbol for the section.
415 associative_section
: Option
<Section
>,