| 1 |
//! XCOFF definitions |
| 2 |
//! |
| 3 |
//! These definitions are independent of read/write support, although we do implement |
| 4 |
//! some traits useful for those. |
| 5 |
//! |
| 6 |
//! This module is the equivalent of /usr/include/xcoff.h, and is based heavily on it. |
| 7 |
|
| 8 |
#![allow(missing_docs)] |
| 9 |
|
| 10 |
use crate::endian::{BigEndian as BE, I16, U16, U32, U64}; |
| 11 |
use crate::pod::Pod; |
| 12 |
|
| 13 |
/// The header at the start of every 32-bit XCOFF file. |
| 14 |
#[derive(Debug, Clone, Copy)] |
| 15 |
#[repr(C)] |
| 16 |
pub struct FileHeader32 { |
| 17 |
/// Magic number. Must be 0x01DF. |
| 18 |
pub f_magic: U16<BE>, |
| 19 |
/// Number of sections. |
| 20 |
pub f_nscns: U16<BE>, |
| 21 |
/// Time and date of file creation. |
| 22 |
pub f_timdat: U32<BE>, |
| 23 |
/// Byte offset to symbol table start. |
| 24 |
pub f_symptr: U32<BE>, |
| 25 |
/// Number of entries in symbol table. |
| 26 |
pub f_nsyms: U32<BE>, |
| 27 |
/// Number of bytes in optional header |
| 28 |
pub f_opthdr: U16<BE>, |
| 29 |
/// Extra flags. |
| 30 |
pub f_flags: U16<BE>, |
| 31 |
} |
| 32 |
|
| 33 |
/// The header at the start of every 64-bit XCOFF file. |
| 34 |
#[derive(Debug, Clone, Copy)] |
| 35 |
#[repr(C)] |
| 36 |
pub struct FileHeader64 { |
| 37 |
/// Magic number. Must be 0x01F7. |
| 38 |
pub f_magic: U16<BE>, |
| 39 |
/// Number of sections. |
| 40 |
pub f_nscns: U16<BE>, |
| 41 |
/// Time and date of file creation |
| 42 |
pub f_timdat: U32<BE>, |
| 43 |
/// Byte offset to symbol table start. |
| 44 |
pub f_symptr: U64<BE>, |
| 45 |
/// Number of bytes in optional header |
| 46 |
pub f_opthdr: U16<BE>, |
| 47 |
/// Extra flags. |
| 48 |
pub f_flags: U16<BE>, |
| 49 |
/// Number of entries in symbol table. |
| 50 |
pub f_nsyms: U32<BE>, |
| 51 |
} |
| 52 |
|
| 53 |
// Values for `f_magic`. |
| 54 |
// |
| 55 |
/// the 64-bit mach magic number |
| 56 |
pub const MAGIC_64: u16 = 0x01F7; |
| 57 |
/// the 32-bit mach magic number |
| 58 |
pub const MAGIC_32: u16 = 0x01DF; |
| 59 |
|
| 60 |
// Values for `f_flags`. |
| 61 |
// |
| 62 |
/// Indicates that the relocation information for binding has been removed from |
| 63 |
/// the file. |
| 64 |
pub const F_RELFLG: u16 = 0x0001; |
| 65 |
/// Indicates that the file is executable. No unresolved external references exist. |
| 66 |
pub const F_EXEC: u16 = 0x0002; |
| 67 |
/// Indicates that line numbers have been stripped from the file by a utility program. |
| 68 |
pub const F_LNNO: u16 = 0x0004; |
| 69 |
/// Indicates that the file was profiled with the fdpr command. |
| 70 |
pub const F_FDPR_PROF: u16 = 0x0010; |
| 71 |
/// Indicates that the file was reordered with the fdpr command. |
| 72 |
pub const F_FDPR_OPTI: u16 = 0x0020; |
| 73 |
/// Indicates that the file uses Very Large Program Support. |
| 74 |
pub const F_DSA: u16 = 0x0040; |
| 75 |
/// Indicates that one of the members of the auxiliary header specifying the |
| 76 |
/// medium page sizes is non-zero. |
| 77 |
pub const F_VARPG: u16 = 0x0100; |
| 78 |
/// Indicates the file is dynamically loadable and executable. External references |
| 79 |
/// are resolved by way of imports, and the file might contain exports and loader |
| 80 |
/// relocation. |
| 81 |
pub const F_DYNLOAD: u16 = 0x1000; |
| 82 |
/// Indicates the file is a shared object (shared library). The file is separately |
| 83 |
/// loadable. That is, it is not normally bound with other objects, and its loader |
| 84 |
/// exports symbols are used as automatic import symbols for other object files. |
| 85 |
pub const F_SHROBJ: u16 = 0x2000; |
| 86 |
/// If the object file is a member of an archive, it can be loaded by the system |
| 87 |
/// loader, but the member is ignored by the binder. If the object file is not in |
| 88 |
/// an archive, this flag has no effect. |
| 89 |
pub const F_LOADONLY: u16 = 0x4000; |
| 90 |
|
| 91 |
/// The auxiliary header immediately following file header. If the value of the |
| 92 |
/// f_opthdr field in the file header is 0, the auxiliary header does not exist. |
| 93 |
#[derive(Debug, Clone, Copy)] |
| 94 |
#[repr(C)] |
| 95 |
pub struct AuxHeader32 { |
| 96 |
/// Flags. |
| 97 |
pub o_mflag: U16<BE>, |
| 98 |
/// Version. |
| 99 |
pub o_vstamp: U16<BE>, |
| 100 |
/// Text size in bytes. |
| 101 |
pub o_tsize: U32<BE>, |
| 102 |
/// Initialized data size in bytes. |
| 103 |
pub o_dsize: U32<BE>, |
| 104 |
/// Uninitialized data size in bytes. |
| 105 |
pub o_bsize: U32<BE>, |
| 106 |
/// Entry point descriptor (virtual address). |
| 107 |
pub o_entry: U32<BE>, |
| 108 |
/// Base address of text (virtual address). |
| 109 |
pub o_text_start: U32<BE>, |
| 110 |
/// Base address of data (virtual address). |
| 111 |
pub o_data_start: U32<BE>, |
| 112 |
/// Address of TOC anchor. |
| 113 |
pub o_toc: U32<BE>, |
| 114 |
/// Section number for entry point. |
| 115 |
pub o_snentry: U16<BE>, |
| 116 |
/// Section number for .text. |
| 117 |
pub o_sntext: U16<BE>, |
| 118 |
/// Section number for .data. |
| 119 |
pub o_sndata: U16<BE>, |
| 120 |
/// Section number for TOC. |
| 121 |
pub o_sntoc: U16<BE>, |
| 122 |
/// Section number for loader data. |
| 123 |
pub o_snloader: U16<BE>, |
| 124 |
/// Section number for .bss. |
| 125 |
pub o_snbss: U16<BE>, |
| 126 |
/// Maximum alignment for .text. |
| 127 |
pub o_algntext: U16<BE>, |
| 128 |
/// Maximum alignment for .data. |
| 129 |
pub o_algndata: U16<BE>, |
| 130 |
/// Module type field. |
| 131 |
pub o_modtype: U16<BE>, |
| 132 |
/// Bit flags - cpu types of objects. |
| 133 |
pub o_cpuflag: u8, |
| 134 |
/// Reserved for CPU type. |
| 135 |
pub o_cputype: u8, |
| 136 |
/// Maximum stack size allowed (bytes). |
| 137 |
pub o_maxstack: U32<BE>, |
| 138 |
/// Maximum data size allowed (bytes). |
| 139 |
pub o_maxdata: U32<BE>, |
| 140 |
/// Reserved for debuggers. |
| 141 |
pub o_debugger: U32<BE>, |
| 142 |
/// Requested text page size. |
| 143 |
pub o_textpsize: u8, |
| 144 |
/// Requested data page size. |
| 145 |
pub o_datapsize: u8, |
| 146 |
/// Requested stack page size. |
| 147 |
pub o_stackpsize: u8, |
| 148 |
/// Flags and thread-local storage alignment. |
| 149 |
pub o_flags: u8, |
| 150 |
/// Section number for .tdata. |
| 151 |
pub o_sntdata: U16<BE>, |
| 152 |
/// Section number for .tbss. |
| 153 |
pub o_sntbss: U16<BE>, |
| 154 |
} |
| 155 |
|
| 156 |
/// The auxiliary header immediately following file header. If the value of the |
| 157 |
/// f_opthdr field in the file header is 0, the auxiliary header does not exist. |
| 158 |
#[derive(Debug, Clone, Copy)] |
| 159 |
#[repr(C)] |
| 160 |
pub struct AuxHeader64 { |
| 161 |
/// Flags. |
| 162 |
pub o_mflag: U16<BE>, |
| 163 |
/// Version. |
| 164 |
pub o_vstamp: U16<BE>, |
| 165 |
/// Reserved for debuggers. |
| 166 |
pub o_debugger: U32<BE>, |
| 167 |
/// Base address of text (virtual address). |
| 168 |
pub o_text_start: U64<BE>, |
| 169 |
/// Base address of data (virtual address). |
| 170 |
pub o_data_start: U64<BE>, |
| 171 |
/// Address of TOC anchor. |
| 172 |
pub o_toc: U64<BE>, |
| 173 |
/// Section number for entry point. |
| 174 |
pub o_snentry: U16<BE>, |
| 175 |
/// Section number for .text. |
| 176 |
pub o_sntext: U16<BE>, |
| 177 |
/// Section number for .data. |
| 178 |
pub o_sndata: U16<BE>, |
| 179 |
/// Section number for TOC. |
| 180 |
pub o_sntoc: U16<BE>, |
| 181 |
/// Section number for loader data. |
| 182 |
pub o_snloader: U16<BE>, |
| 183 |
/// Section number for .bss. |
| 184 |
pub o_snbss: U16<BE>, |
| 185 |
/// Maximum alignment for .text. |
| 186 |
pub o_algntext: U16<BE>, |
| 187 |
/// Maximum alignment for .data. |
| 188 |
pub o_algndata: U16<BE>, |
| 189 |
/// Module type field. |
| 190 |
pub o_modtype: U16<BE>, |
| 191 |
/// Bit flags - cpu types of objects. |
| 192 |
pub o_cpuflag: u8, |
| 193 |
/// Reserved for CPU type. |
| 194 |
pub o_cputype: u8, |
| 195 |
/// Requested text page size. |
| 196 |
pub o_textpsize: u8, |
| 197 |
/// Requested data page size. |
| 198 |
pub o_datapsize: u8, |
| 199 |
/// Requested stack page size. |
| 200 |
pub o_stackpsize: u8, |
| 201 |
/// Flags and thread-local storage alignment. |
| 202 |
pub o_flags: u8, |
| 203 |
/// Text size in bytes. |
| 204 |
pub o_tsize: U64<BE>, |
| 205 |
/// Initialized data size in bytes. |
| 206 |
pub o_dsize: U64<BE>, |
| 207 |
/// Uninitialized data size in bytes. |
| 208 |
pub o_bsize: U64<BE>, |
| 209 |
/// Entry point descriptor (virtual address). |
| 210 |
pub o_entry: U64<BE>, |
| 211 |
/// Maximum stack size allowed (bytes). |
| 212 |
pub o_maxstack: U64<BE>, |
| 213 |
/// Maximum data size allowed (bytes). |
| 214 |
pub o_maxdata: U64<BE>, |
| 215 |
/// Section number for .tdata. |
| 216 |
pub o_sntdata: U16<BE>, |
| 217 |
/// Section number for .tbss. |
| 218 |
pub o_sntbss: U16<BE>, |
| 219 |
/// XCOFF64 flags. |
| 220 |
pub o_x64flags: U16<BE>, |
| 221 |
/// Reserved. |
| 222 |
pub o_resv3a: U16<BE>, |
| 223 |
/// Reserved. |
| 224 |
pub o_resv3: [U32<BE>; 2], |
| 225 |
} |
| 226 |
|
| 227 |
/// Some AIX programs generate auxiliary headers for 32-bit object files that |
| 228 |
/// end after the data_start field. |
| 229 |
pub const AOUTHSZ_SHORT: u16 = 28; |
| 230 |
|
| 231 |
/// Section header. |
| 232 |
#[derive(Debug, Clone, Copy)] |
| 233 |
#[repr(C)] |
| 234 |
pub struct SectionHeader32 { |
| 235 |
/// Section name. |
| 236 |
pub s_name: [u8; 8], |
| 237 |
/// Physical address. |
| 238 |
pub s_paddr: U32<BE>, |
| 239 |
/// Virtual address (same as physical address). |
| 240 |
pub s_vaddr: U32<BE>, |
| 241 |
/// Section size. |
| 242 |
pub s_size: U32<BE>, |
| 243 |
/// Offset in file to raw data for section. |
| 244 |
pub s_scnptr: U32<BE>, |
| 245 |
/// Offset in file to relocation entries for section. |
| 246 |
pub s_relptr: U32<BE>, |
| 247 |
/// Offset in file to line number entries for section. |
| 248 |
pub s_lnnoptr: U32<BE>, |
| 249 |
/// Number of relocation entries. |
| 250 |
pub s_nreloc: U16<BE>, |
| 251 |
/// Number of line number entries. |
| 252 |
pub s_nlnno: U16<BE>, |
| 253 |
/// Flags to define the section type. |
| 254 |
pub s_flags: U32<BE>, |
| 255 |
} |
| 256 |
|
| 257 |
/// Section header. |
| 258 |
#[derive(Debug, Clone, Copy)] |
| 259 |
#[repr(C)] |
| 260 |
pub struct SectionHeader64 { |
| 261 |
/// Section name. |
| 262 |
pub s_name: [u8; 8], |
| 263 |
/// Physical address. |
| 264 |
pub s_paddr: U64<BE>, |
| 265 |
/// Virtual address (same as physical address). |
| 266 |
pub s_vaddr: U64<BE>, |
| 267 |
/// Section size. |
| 268 |
pub s_size: U64<BE>, |
| 269 |
/// Offset in file to raw data for section. |
| 270 |
pub s_scnptr: U64<BE>, |
| 271 |
/// Offset in file to relocation entries for section. |
| 272 |
pub s_relptr: U64<BE>, |
| 273 |
/// Offset in file to line number entries for section. |
| 274 |
pub s_lnnoptr: U64<BE>, |
| 275 |
/// Number of relocation entries. |
| 276 |
pub s_nreloc: U32<BE>, |
| 277 |
/// Number of line number entries. |
| 278 |
pub s_nlnno: U32<BE>, |
| 279 |
/// Flags to define the section type. |
| 280 |
pub s_flags: U32<BE>, |
| 281 |
/// Reserved. |
| 282 |
pub s_reserve: U32<BE>, |
| 283 |
} |
| 284 |
|
| 285 |
// Values for `s_flags`. |
| 286 |
// |
| 287 |
/// "regular" section |
| 288 |
pub const STYP_REG: u16 = 0x00; |
| 289 |
/// Specifies a pad section. A section of this type is used to provide alignment |
| 290 |
/// padding between sections within an XCOFF executable object file. This section |
| 291 |
/// header type is obsolete since padding is allowed in an XCOFF file without a |
| 292 |
/// corresponding pad section header. |
| 293 |
pub const STYP_PAD: u16 = 0x08; |
| 294 |
/// Specifies a DWARF debugging section, which provide source file and symbol |
| 295 |
/// information for the symbolic debugger. |
| 296 |
pub const STYP_DWARF: u16 = 0x10; |
| 297 |
/// Specifies an executable text (code) section. A section of this type contains |
| 298 |
/// the executable instructions of a program. |
| 299 |
pub const STYP_TEXT: u16 = 0x20; |
| 300 |
/// Specifies an initialized data section. A section of this type contains the |
| 301 |
/// initialized data and the TOC of a program. |
| 302 |
pub const STYP_DATA: u16 = 0x40; |
| 303 |
/// Specifies an uninitialized data section. A section header of this type |
| 304 |
/// defines the uninitialized data of a program. |
| 305 |
pub const STYP_BSS: u16 = 0x80; |
| 306 |
/// Specifies an exception section. A section of this type provides information |
| 307 |
/// to identify the reason that a trap or exception occurred within an executable |
| 308 |
/// object program. |
| 309 |
pub const STYP_EXCEPT: u16 = 0x0100; |
| 310 |
/// Specifies a comment section. A section of this type provides comments or data |
| 311 |
/// to special processing utility programs. |
| 312 |
pub const STYP_INFO: u16 = 0x0200; |
| 313 |
/// Specifies an initialized thread-local data section. |
| 314 |
pub const STYP_TDATA: u16 = 0x0400; |
| 315 |
/// Specifies an uninitialized thread-local data section. |
| 316 |
pub const STYP_TBSS: u16 = 0x0800; |
| 317 |
/// Specifies a loader section. A section of this type contains object file |
| 318 |
/// information for the system loader to load an XCOFF executable. The information |
| 319 |
/// includes imported symbols, exported symbols, relocation data, type-check |
| 320 |
/// information, and shared object names. |
| 321 |
pub const STYP_LOADER: u16 = 0x1000; |
| 322 |
/// Specifies a debug section. A section of this type contains stabstring |
| 323 |
/// information used by the symbolic debugger. |
| 324 |
pub const STYP_DEBUG: u16 = 0x2000; |
| 325 |
/// Specifies a type-check section. A section of this type contains |
| 326 |
/// parameter/argument type-check strings used by the binder. |
| 327 |
pub const STYP_TYPCHK: u16 = 0x4000; |
| 328 |
/// Specifies a relocation or line-number field overflow section. A section |
| 329 |
/// header of this type contains the count of relocation entries and line |
| 330 |
/// number entries for some other section. This section header is required |
| 331 |
/// when either of the counts exceeds 65,534. |
| 332 |
pub const STYP_OVRFLO: u16 = 0x8000; |
| 333 |
|
| 334 |
pub const SSUBTYP_DWINFO: u32 = 0x10000; |
| 335 |
pub const SSUBTYP_DWLINE: u32 = 0x20000; |
| 336 |
pub const SSUBTYP_DWPBNMS: u32 = 0x30000; |
| 337 |
pub const SSUBTYP_DWPBTYP: u32 = 0x40000; |
| 338 |
pub const SSUBTYP_DWARNGE: u32 = 0x50000; |
| 339 |
pub const SSUBTYP_DWABREV: u32 = 0x60000; |
| 340 |
pub const SSUBTYP_DWSTR: u32 = 0x70000; |
| 341 |
pub const SSUBTYP_DWRNGES: u32 = 0x80000; |
| 342 |
pub const SSUBTYP_DWLOC: u32 = 0x90000; |
| 343 |
pub const SSUBTYP_DWFRAME: u32 = 0xA0000; |
| 344 |
pub const SSUBTYP_DWMAC: u32 = 0xB0000; |
| 345 |
|
| 346 |
pub const SIZEOF_SYMBOL: usize = 18; |
| 347 |
|
| 348 |
#[derive(Debug, Clone, Copy)] |
| 349 |
#[repr(C)] |
| 350 |
pub struct SymbolBytes(pub [u8; SIZEOF_SYMBOL]); |
| 351 |
|
| 352 |
/// Symbol table entry. |
| 353 |
#[derive(Debug, Clone, Copy)] |
| 354 |
#[repr(C)] |
| 355 |
pub struct Symbol32 { |
| 356 |
/// Symbol name. |
| 357 |
/// |
| 358 |
/// If first 4 bytes are 0, then second 4 bytes are offset into string table. |
| 359 |
pub n_name: [u8; 8], |
| 360 |
/// Symbol value; storage class-dependent. |
| 361 |
pub n_value: U32<BE>, |
| 362 |
/// Section number of symbol. |
| 363 |
pub n_scnum: I16<BE>, |
| 364 |
/// Basic and derived type specification. |
| 365 |
pub n_type: U16<BE>, |
| 366 |
/// Storage class of symbol. |
| 367 |
pub n_sclass: u8, |
| 368 |
/// Number of auxiliary entries. |
| 369 |
pub n_numaux: u8, |
| 370 |
} |
| 371 |
|
| 372 |
/// Symbol table entry. |
| 373 |
#[derive(Debug, Clone, Copy)] |
| 374 |
#[repr(C)] |
| 375 |
pub struct Symbol64 { |
| 376 |
/// Symbol value; storage class-dependent. |
| 377 |
pub n_value: U64<BE>, |
| 378 |
/// Offset of the name in string table or .debug section. |
| 379 |
pub n_offset: U32<BE>, |
| 380 |
/// Section number of symbol. |
| 381 |
pub n_scnum: I16<BE>, |
| 382 |
/// Basic and derived type specification. |
| 383 |
pub n_type: U16<BE>, |
| 384 |
/// Storage class of symbol. |
| 385 |
pub n_sclass: u8, |
| 386 |
/// Number of auxiliary entries. |
| 387 |
pub n_numaux: u8, |
| 388 |
} |
| 389 |
|
| 390 |
// Values for `n_scnum`. |
| 391 |
// |
| 392 |
/// A special symbolic debugging symbol. |
| 393 |
pub const N_DEBUG: i16 = -2; |
| 394 |
/// An absolute symbol. The symbol has a value but is not relocatable. |
| 395 |
pub const N_ABS: i16 = -1; |
| 396 |
/// An undefined external symbol. |
| 397 |
pub const N_UNDEF: i16 = 0; |
| 398 |
|
| 399 |
// Values for `n_type`. |
| 400 |
// |
| 401 |
/// Values for visibility as they would appear when encoded in the high 4 bits |
| 402 |
/// of the 16-bit unsigned n_type field of symbol table entries. Valid for |
| 403 |
/// 32-bit XCOFF only when the o_vstamp in the auxiliary header is greater than 1. |
| 404 |
pub const SYM_V_MASK: u16 = 0xF000; |
| 405 |
pub const SYM_V_INTERNAL: u16 = 0x1000; |
| 406 |
pub const SYM_V_HIDDEN: u16 = 0x2000; |
| 407 |
pub const SYM_V_PROTECTED: u16 = 0x3000; |
| 408 |
pub const SYM_V_EXPORTED: u16 = 0x4000; |
| 409 |
|
| 410 |
// Values for `n_sclass`. |
| 411 |
// |
| 412 |
// Storage classes used for symbolic debugging symbols. |
| 413 |
// |
| 414 |
/// Source file name and compiler information. |
| 415 |
pub const C_FILE: u8 = 103; |
| 416 |
/// Beginning of include file. |
| 417 |
pub const C_BINCL: u8 = 108; |
| 418 |
/// Ending of include file. |
| 419 |
pub const C_EINCL: u8 = 109; |
| 420 |
/// Global variable. |
| 421 |
pub const C_GSYM: u8 = 128; |
| 422 |
/// Statically allocated symbol. |
| 423 |
pub const C_STSYM: u8 = 133; |
| 424 |
/// Beginning of common block. |
| 425 |
pub const C_BCOMM: u8 = 135; |
| 426 |
/// End of common block. |
| 427 |
pub const C_ECOMM: u8 = 137; |
| 428 |
/// Alternate entry. |
| 429 |
pub const C_ENTRY: u8 = 141; |
| 430 |
/// Beginning of static block. |
| 431 |
pub const C_BSTAT: u8 = 143; |
| 432 |
/// End of static block. |
| 433 |
pub const C_ESTAT: u8 = 144; |
| 434 |
/// Global thread-local variable. |
| 435 |
pub const C_GTLS: u8 = 145; |
| 436 |
/// Static thread-local variable. |
| 437 |
pub const C_STTLS: u8 = 146; |
| 438 |
/// DWARF section symbol. |
| 439 |
pub const C_DWARF: u8 = 112; |
| 440 |
// |
| 441 |
// Storage classes used for absolute symbols. |
| 442 |
// |
| 443 |
/// Automatic variable allocated on stack. |
| 444 |
pub const C_LSYM: u8 = 129; |
| 445 |
/// Argument to subroutine allocated on stack. |
| 446 |
pub const C_PSYM: u8 = 130; |
| 447 |
/// Register variable. |
| 448 |
pub const C_RSYM: u8 = 131; |
| 449 |
/// Argument to function or procedure stored in register. |
| 450 |
pub const C_RPSYM: u8 = 132; |
| 451 |
/// Local member of common block. |
| 452 |
pub const C_ECOML: u8 = 136; |
| 453 |
/// Function or procedure. |
| 454 |
pub const C_FUN: u8 = 142; |
| 455 |
// |
| 456 |
// Storage classes used for undefined external symbols or symbols of general sections. |
| 457 |
// |
| 458 |
/// External symbol. |
| 459 |
pub const C_EXT: u8 = 2; |
| 460 |
/// Weak external symbol. |
| 461 |
pub const C_WEAKEXT: u8 = 111; |
| 462 |
// |
| 463 |
// Storage classes used for symbols of general sections. |
| 464 |
// |
| 465 |
/// Symbol table entry marked for deletion. |
| 466 |
pub const C_NULL: u8 = 0; |
| 467 |
/// Static. |
| 468 |
pub const C_STAT: u8 = 3; |
| 469 |
/// Beginning or end of inner block. |
| 470 |
pub const C_BLOCK: u8 = 100; |
| 471 |
/// Beginning or end of function. |
| 472 |
pub const C_FCN: u8 = 101; |
| 473 |
/// Un-named external symbol. |
| 474 |
pub const C_HIDEXT: u8 = 107; |
| 475 |
/// Comment string in .info section. |
| 476 |
pub const C_INFO: u8 = 110; |
| 477 |
/// Declaration of object (type). |
| 478 |
pub const C_DECL: u8 = 140; |
| 479 |
// |
| 480 |
// Storage classes - Obsolete/Undocumented. |
| 481 |
// |
| 482 |
/// Automatic variable. |
| 483 |
pub const C_AUTO: u8 = 1; |
| 484 |
/// Register variable. |
| 485 |
pub const C_REG: u8 = 4; |
| 486 |
/// External definition. |
| 487 |
pub const C_EXTDEF: u8 = 5; |
| 488 |
/// Label. |
| 489 |
pub const C_LABEL: u8 = 6; |
| 490 |
/// Undefined label. |
| 491 |
pub const C_ULABEL: u8 = 7; |
| 492 |
/// Member of structure. |
| 493 |
pub const C_MOS: u8 = 8; |
| 494 |
/// Function argument. |
| 495 |
pub const C_ARG: u8 = 9; |
| 496 |
/// Structure tag. |
| 497 |
pub const C_STRTAG: u8 = 10; |
| 498 |
/// Member of union. |
| 499 |
pub const C_MOU: u8 = 11; |
| 500 |
/// Union tag. |
| 501 |
pub const C_UNTAG: u8 = 12; |
| 502 |
/// Type definition. |
| 503 |
pub const C_TPDEF: u8 = 13; |
| 504 |
/// Undefined static. |
| 505 |
pub const C_USTATIC: u8 = 14; |
| 506 |
/// Enumeration tag. |
| 507 |
pub const C_ENTAG: u8 = 15; |
| 508 |
/// Member of enumeration. |
| 509 |
pub const C_MOE: u8 = 16; |
| 510 |
/// Register parameter. |
| 511 |
pub const C_REGPARM: u8 = 17; |
| 512 |
/// Bit field. |
| 513 |
pub const C_FIELD: u8 = 18; |
| 514 |
/// End of structure. |
| 515 |
pub const C_EOS: u8 = 102; |
| 516 |
/// Duplicate tag. |
| 517 |
pub const C_ALIAS: u8 = 105; |
| 518 |
/// Special storage class for external. |
| 519 |
pub const C_HIDDEN: u8 = 106; |
| 520 |
/// Physical end of function. |
| 521 |
pub const C_EFCN: u8 = 255; |
| 522 |
/// Reserved. |
| 523 |
pub const C_TCSYM: u8 = 134; |
| 524 |
|
| 525 |
/// File Auxiliary Entry for C_FILE Symbols. |
| 526 |
#[derive(Debug, Clone, Copy)] |
| 527 |
#[repr(C)] |
| 528 |
pub struct FileAux32 { |
| 529 |
/// The source file name or compiler-related string. |
| 530 |
/// |
| 531 |
/// If first 4 bytes are 0, then second 4 bytes are offset into string table. |
| 532 |
pub x_fname: [u8; 8], |
| 533 |
/// Pad size for file name. |
| 534 |
pub x_fpad: [u8; 6], |
| 535 |
/// The source-file string type. |
| 536 |
pub x_ftype: u8, |
| 537 |
/// Reserved. |
| 538 |
pub x_freserve: [u8; 3], |
| 539 |
} |
| 540 |
|
| 541 |
/// File Auxiliary Entry for C_FILE Symbols. |
| 542 |
#[derive(Debug, Clone, Copy)] |
| 543 |
#[repr(C)] |
| 544 |
pub struct FileAux64 { |
| 545 |
/// The source file name or compiler-related string. |
| 546 |
/// |
| 547 |
/// If first 4 bytes are 0, then second 4 bytes are offset into string table. |
| 548 |
pub x_fname: [u8; 8], |
| 549 |
/// Pad size for file name. |
| 550 |
pub x_fpad: [u8; 6], |
| 551 |
/// The source-file string type. |
| 552 |
pub x_ftype: u8, |
| 553 |
/// Reserved. |
| 554 |
pub x_freserve: [u8; 2], |
| 555 |
/// Specifies the type of auxiliary entry. Contains _AUX_FILE for this auxiliary entry. |
| 556 |
pub x_auxtype: u8, |
| 557 |
} |
| 558 |
|
| 559 |
// Values for `x_ftype`. |
| 560 |
// |
| 561 |
/// Specifies the source-file name. |
| 562 |
pub const XFT_FN: u8 = 0; |
| 563 |
/// Specifies the compiler time stamp. |
| 564 |
pub const XFT_CT: u8 = 1; |
| 565 |
/// Specifies the compiler version number. |
| 566 |
pub const XFT_CV: u8 = 2; |
| 567 |
/// Specifies compiler-defined information. |
| 568 |
pub const XFT_CD: u8 = 128; |
| 569 |
|
| 570 |
/// Csect auxiliary entry for C_EXT, C_WEAKEXT, and C_HIDEXT symbols. |
| 571 |
#[derive(Debug, Clone, Copy)] |
| 572 |
#[repr(C)] |
| 573 |
pub struct CsectAux32 { |
| 574 |
/// Section length. |
| 575 |
pub x_scnlen: U32<BE>, |
| 576 |
/// Offset of parameter type-check hash in .typchk section. |
| 577 |
pub x_parmhash: U32<BE>, |
| 578 |
/// .typchk section number. |
| 579 |
pub x_snhash: U16<BE>, |
| 580 |
/// Symbol alignment and type. |
| 581 |
pub x_smtyp: u8, |
| 582 |
/// Storage mapping class. |
| 583 |
pub x_smclas: u8, |
| 584 |
/// Reserved. |
| 585 |
pub x_stab: U32<BE>, |
| 586 |
/// x_snstab. |
| 587 |
pub x_snstab: U16<BE>, |
| 588 |
} |
| 589 |
|
| 590 |
/// Csect auxiliary entry for C_EXT, C_WEAKEXT, and C_HIDEXT symbols. |
| 591 |
#[derive(Debug, Clone, Copy)] |
| 592 |
#[repr(C)] |
| 593 |
pub struct CsectAux64 { |
| 594 |
/// Low 4 bytes of section length. |
| 595 |
pub x_scnlen_lo: U32<BE>, |
| 596 |
/// Offset of parameter type-check hash in .typchk section. |
| 597 |
pub x_parmhash: U32<BE>, |
| 598 |
/// .typchk section number. |
| 599 |
pub x_snhash: U16<BE>, |
| 600 |
/// Symbol alignment and type. |
| 601 |
pub x_smtyp: u8, |
| 602 |
/// Storage mapping class. |
| 603 |
pub x_smclas: u8, |
| 604 |
/// High 4 bytes of section length. |
| 605 |
pub x_scnlen_hi: U32<BE>, |
| 606 |
/// Reserved. |
| 607 |
pub pad: u8, |
| 608 |
/// Contains _AUX_CSECT; indicates type of auxiliary entry. |
| 609 |
pub x_auxtype: u8, |
| 610 |
} |
| 611 |
|
| 612 |
// Values for `x_smtyp`. |
| 613 |
// |
| 614 |
/// External reference. |
| 615 |
pub const XTY_ER: u8 = 0; |
| 616 |
/// Csect definition for initialized storage. |
| 617 |
pub const XTY_SD: u8 = 1; |
| 618 |
/// Defines an entry point to an initialized csect. |
| 619 |
pub const XTY_LD: u8 = 2; |
| 620 |
/// Common csect definition. For uninitialized storage. |
| 621 |
pub const XTY_CM: u8 = 3; |
| 622 |
|
| 623 |
// Values for `x_smclas`. |
| 624 |
// |
| 625 |
// READ ONLY CLASSES |
| 626 |
// |
| 627 |
/// Program Code |
| 628 |
pub const XMC_PR: u8 = 0; |
| 629 |
/// Read Only Constant |
| 630 |
pub const XMC_RO: u8 = 1; |
| 631 |
/// Debug Dictionary Table |
| 632 |
pub const XMC_DB: u8 = 2; |
| 633 |
/// Global Linkage (Interfile Interface Code) |
| 634 |
pub const XMC_GL: u8 = 6; |
| 635 |
/// Extended Operation (Pseudo Machine Instruction) |
| 636 |
pub const XMC_XO: u8 = 7; |
| 637 |
/// Supervisor Call (32-bit process only) |
| 638 |
pub const XMC_SV: u8 = 8; |
| 639 |
/// Supervisor Call for 64-bit process |
| 640 |
pub const XMC_SV64: u8 = 17; |
| 641 |
/// Supervisor Call for both 32- and 64-bit processes |
| 642 |
pub const XMC_SV3264: u8 = 18; |
| 643 |
/// Traceback Index csect |
| 644 |
pub const XMC_TI: u8 = 12; |
| 645 |
/// Traceback Table csect |
| 646 |
pub const XMC_TB: u8 = 13; |
| 647 |
// |
| 648 |
// READ WRITE CLASSES |
| 649 |
// |
| 650 |
/// Read Write Data |
| 651 |
pub const XMC_RW: u8 = 5; |
| 652 |
/// TOC Anchor for TOC Addressability |
| 653 |
pub const XMC_TC0: u8 = 15; |
| 654 |
/// General TOC item |
| 655 |
pub const XMC_TC: u8 = 3; |
| 656 |
/// Scalar data item in the TOC |
| 657 |
pub const XMC_TD: u8 = 16; |
| 658 |
/// Descriptor csect |
| 659 |
pub const XMC_DS: u8 = 10; |
| 660 |
/// Unclassified - Treated as Read Write |
| 661 |
pub const XMC_UA: u8 = 4; |
| 662 |
/// BSS class (uninitialized static internal) |
| 663 |
pub const XMC_BS: u8 = 9; |
| 664 |
/// Un-named Fortran Common |
| 665 |
pub const XMC_UC: u8 = 11; |
| 666 |
/// Initialized thread-local variable |
| 667 |
pub const XMC_TL: u8 = 20; |
| 668 |
/// Uninitialized thread-local variable |
| 669 |
pub const XMC_UL: u8 = 21; |
| 670 |
/// Symbol mapped at the end of TOC |
| 671 |
pub const XMC_TE: u8 = 22; |
| 672 |
|
| 673 |
/// Function auxiliary entry. |
| 674 |
#[derive(Debug, Clone, Copy)] |
| 675 |
#[repr(C)] |
| 676 |
pub struct FunAux32 { |
| 677 |
/// File offset to exception table entry. |
| 678 |
pub x_exptr: U32<BE>, |
| 679 |
/// Size of function in bytes. |
| 680 |
pub x_fsize: U32<BE>, |
| 681 |
/// File pointer to line number |
| 682 |
pub x_lnnoptr: U32<BE>, |
| 683 |
/// Symbol table index of next entry beyond this function. |
| 684 |
pub x_endndx: U32<BE>, |
| 685 |
/// Pad |
| 686 |
pub pad: U16<BE>, |
| 687 |
} |
| 688 |
|
| 689 |
/// Function auxiliary entry. |
| 690 |
#[derive(Debug, Clone, Copy)] |
| 691 |
#[repr(C)] |
| 692 |
pub struct FunAux64 { |
| 693 |
/// File pointer to line number |
| 694 |
pub x_lnnoptr: U64<BE>, |
| 695 |
/// Size of function in bytes. |
| 696 |
pub x_fsize: U32<BE>, |
| 697 |
/// Symbol table index of next entry beyond this function. |
| 698 |
pub x_endndx: U32<BE>, |
| 699 |
/// Pad |
| 700 |
pub pad: u8, |
| 701 |
/// Contains _AUX_FCN; Type of auxiliary entry. |
| 702 |
pub x_auxtype: u8, |
| 703 |
} |
| 704 |
|
| 705 |
/// Exception auxiliary entry. (XCOFF64 only) |
| 706 |
#[derive(Debug, Clone, Copy)] |
| 707 |
#[repr(C)] |
| 708 |
pub struct ExpAux { |
| 709 |
/// File offset to exception table entry. |
| 710 |
pub x_exptr: U64<BE>, |
| 711 |
/// Size of function in bytes. |
| 712 |
pub x_fsize: U32<BE>, |
| 713 |
/// Symbol table index of next entry beyond this function. |
| 714 |
pub x_endndx: U32<BE>, |
| 715 |
/// Pad |
| 716 |
pub pad: u8, |
| 717 |
/// Contains _AUX_EXCEPT; Type of auxiliary entry |
| 718 |
pub x_auxtype: u8, |
| 719 |
} |
| 720 |
|
| 721 |
/// Block auxiliary entry for the C_BLOCK and C_FCN Symbols. |
| 722 |
#[derive(Debug, Clone, Copy)] |
| 723 |
#[repr(C)] |
| 724 |
pub struct BlockAux32 { |
| 725 |
/// Reserved. |
| 726 |
pub pad: [u8; 2], |
| 727 |
/// High-order 2 bytes of the source line number. |
| 728 |
pub x_lnnohi: U16<BE>, |
| 729 |
/// Low-order 2 bytes of the source line number. |
| 730 |
pub x_lnnolo: U16<BE>, |
| 731 |
/// Reserved. |
| 732 |
pub pad2: [u8; 12], |
| 733 |
} |
| 734 |
|
| 735 |
/// Block auxiliary entry for the C_BLOCK and C_FCN Symbols. |
| 736 |
#[derive(Debug, Clone, Copy)] |
| 737 |
#[repr(C)] |
| 738 |
pub struct BlockAux64 { |
| 739 |
/// Source line number. |
| 740 |
pub x_lnno: U32<BE>, |
| 741 |
/// Reserved. |
| 742 |
pub pad: [u8; 13], |
| 743 |
/// Contains _AUX_SYM; Type of auxiliary entry. |
| 744 |
pub x_auxtype: u8, |
| 745 |
} |
| 746 |
|
| 747 |
/// Section auxiliary entry for the C_STAT Symbol. (XCOFF32 Only) |
| 748 |
#[derive(Debug, Clone, Copy)] |
| 749 |
#[repr(C)] |
| 750 |
pub struct StatAux { |
| 751 |
/// Section length. |
| 752 |
pub x_scnlen: U32<BE>, |
| 753 |
/// Number of relocation entries. |
| 754 |
pub x_nreloc: U16<BE>, |
| 755 |
/// Number of line numbers. |
| 756 |
pub x_nlinno: U16<BE>, |
| 757 |
/// Reserved. |
| 758 |
pub pad: [u8; 10], |
| 759 |
} |
| 760 |
|
| 761 |
/// Section auxiliary entry Format for C_DWARF symbols. |
| 762 |
#[derive(Debug, Clone, Copy)] |
| 763 |
#[repr(C)] |
| 764 |
pub struct DwarfAux32 { |
| 765 |
/// Length of portion of section represented by symbol. |
| 766 |
pub x_scnlen: U32<BE>, |
| 767 |
/// Reserved. |
| 768 |
pub pad: [u8; 4], |
| 769 |
/// Number of relocation entries in section. |
| 770 |
pub x_nreloc: U32<BE>, |
| 771 |
/// Reserved. |
| 772 |
pub pad2: [u8; 6], |
| 773 |
} |
| 774 |
|
| 775 |
/// Section auxiliary entry Format for C_DWARF symbols. |
| 776 |
#[derive(Debug, Clone, Copy)] |
| 777 |
#[repr(C)] |
| 778 |
pub struct DwarfAux64 { |
| 779 |
/// Length of portion of section represented by symbol. |
| 780 |
pub x_scnlen: U64<BE>, |
| 781 |
/// Number of relocation entries in section. |
| 782 |
pub x_nreloc: U64<BE>, |
| 783 |
/// Reserved. |
| 784 |
pub pad: u8, |
| 785 |
/// Contains _AUX_SECT; Type of Auxiliary entry. |
| 786 |
pub x_auxtype: u8, |
| 787 |
} |
| 788 |
|
| 789 |
// Values for `x_auxtype` |
| 790 |
// |
| 791 |
/// Identifies an exception auxiliary entry. |
| 792 |
pub const AUX_EXCEPT: u8 = 255; |
| 793 |
/// Identifies a function auxiliary entry. |
| 794 |
pub const AUX_FCN: u8 = 254; |
| 795 |
/// Identifies a symbol auxiliary entry. |
| 796 |
pub const AUX_SYM: u8 = 253; |
| 797 |
/// Identifies a file auxiliary entry. |
| 798 |
pub const AUX_FILE: u8 = 252; |
| 799 |
/// Identifies a csect auxiliary entry. |
| 800 |
pub const AUX_CSECT: u8 = 251; |
| 801 |
/// Identifies a SECT auxiliary entry. |
| 802 |
pub const AUX_SECT: u8 = 250; |
| 803 |
|
| 804 |
/// Relocation table entry |
| 805 |
#[derive(Debug, Clone, Copy)] |
| 806 |
#[repr(C)] |
| 807 |
pub struct Rel32 { |
| 808 |
/// Virtual address (position) in section to be relocated. |
| 809 |
pub r_vaddr: U32<BE>, |
| 810 |
/// Symbol table index of item that is referenced. |
| 811 |
pub r_symndx: U32<BE>, |
| 812 |
/// Relocation size and information. |
| 813 |
pub r_rsize: u8, |
| 814 |
/// Relocation type. |
| 815 |
pub r_rtype: u8, |
| 816 |
} |
| 817 |
|
| 818 |
/// Relocation table entry |
| 819 |
#[derive(Debug, Clone, Copy)] |
| 820 |
#[repr(C)] |
| 821 |
pub struct Rel64 { |
| 822 |
/// Virtual address (position) in section to be relocated. |
| 823 |
pub r_vaddr: U64<BE>, |
| 824 |
/// Symbol table index of item that is referenced. |
| 825 |
pub r_symndx: U32<BE>, |
| 826 |
/// Relocation size and information. |
| 827 |
pub r_rsize: u8, |
| 828 |
/// Relocation type. |
| 829 |
pub r_rtype: u8, |
| 830 |
} |
| 831 |
|
| 832 |
// Values for `r_rtype`. |
| 833 |
// |
| 834 |
/// Positive relocation. |
| 835 |
pub const R_POS: u8 = 0x00; |
| 836 |
/// Positive indirect load relocation. |
| 837 |
pub const R_RL: u8 = 0x0c; |
| 838 |
/// Positive load address relocation. Modifiable instruction. |
| 839 |
pub const R_RLA: u8 = 0x0d; |
| 840 |
/// Negative relocation. |
| 841 |
pub const R_NEG: u8 = 0x01; |
| 842 |
/// Relative to self relocation. |
| 843 |
pub const R_REL: u8 = 0x02; |
| 844 |
/// Relative to the TOC relocation. |
| 845 |
pub const R_TOC: u8 = 0x03; |
| 846 |
/// TOC relative indirect load relocation. |
| 847 |
pub const R_TRL: u8 = 0x12; |
| 848 |
/// Relative to the TOC or to the thread-local storage base relocation. |
| 849 |
pub const R_TRLA: u8 = 0x13; |
| 850 |
/// Global linkage-external TOC address relocation. |
| 851 |
pub const R_GL: u8 = 0x05; |
| 852 |
/// Local object TOC address relocation. |
| 853 |
pub const R_TCL: u8 = 0x06; |
| 854 |
/// A non-relocating relocation. |
| 855 |
pub const R_REF: u8 = 0x0f; |
| 856 |
/// Branch absolute relocation. References a non-modifiable instruction. |
| 857 |
pub const R_BA: u8 = 0x08; |
| 858 |
/// Branch relative to self relocation. References a non-modifiable instruction. |
| 859 |
pub const R_BR: u8 = 0x0a; |
| 860 |
/// Branch absolute relocation. References a modifiable instruction. |
| 861 |
pub const R_RBA: u8 = 0x18; |
| 862 |
/// Branch relative to self relocation. References a modifiable instruction. |
| 863 |
pub const R_RBR: u8 = 0x1a; |
| 864 |
/// General-dynamic reference to TLS symbol. |
| 865 |
pub const R_TLS: u8 = 0x20; |
| 866 |
/// Initial-exec reference to TLS symbol. |
| 867 |
pub const R_TLS_IE: u8 = 0x21; |
| 868 |
/// Local-dynamic reference to TLS symbol. |
| 869 |
pub const R_TLS_LD: u8 = 0x22; |
| 870 |
/// Local-exec reference to TLS symbol. |
| 871 |
pub const R_TLS_LE: u8 = 0x23; |
| 872 |
/// Module reference to TLS. |
| 873 |
pub const R_TLSM: u8 = 0x24; |
| 874 |
/// Module reference to the local TLS storage. |
| 875 |
pub const R_TLSML: u8 = 0x25; |
| 876 |
/// Relative to TOC upper. |
| 877 |
pub const R_TOCU: u8 = 0x30; |
| 878 |
/// Relative to TOC lower. |
| 879 |
pub const R_TOCL: u8 = 0x31; |
| 880 |
|
| 881 |
unsafe_impl_pod!( |
| 882 |
FileHeader32, |
| 883 |
FileHeader64, |
| 884 |
AuxHeader32, |
| 885 |
AuxHeader64, |
| 886 |
SectionHeader32, |
| 887 |
SectionHeader64, |
| 888 |
SymbolBytes, |
| 889 |
Symbol32, |
| 890 |
Symbol64, |
| 891 |
FileAux32, |
| 892 |
FileAux64, |
| 893 |
CsectAux32, |
| 894 |
CsectAux64, |
| 895 |
FunAux32, |
| 896 |
FunAux64, |
| 897 |
ExpAux, |
| 898 |
BlockAux32, |
| 899 |
BlockAux64, |
| 900 |
StatAux, |
| 901 |
DwarfAux32, |
| 902 |
DwarfAux64, |
| 903 |
Rel32, |
| 904 |
Rel64, |
| 905 |
); |