├── README.md └── elf_forwardcom.h /README.md: -------------------------------------------------------------------------------- 1 | # Object file format 2 | 3 | The file elf_forwardcom.h describes the ELF format for object files and executable files for the ForwardCom architecture. 4 | 5 | The latest version is now in the bintools repository. 6 | -------------------------------------------------------------------------------- /elf_forwardcom.h: -------------------------------------------------------------------------------- 1 | /**************************** elf_forwardcom.h ************************** 2 | * Author: Agner Fog 3 | * Date created: 2016-06-25 4 | * Last modified: 2025-01-21 5 | * ForwardCom version: 1.14 6 | * Program version: 1.14 7 | * Project: ForwardCom binary tools 8 | * Description: Definition of ELF file format. See below 9 | * 10 | * To do: define exception handler and stack unwind information 11 | * To do: define stack size and heap size information 12 | * To do: define memory reservation for runtime linking 13 | * To do: define formats for debug information 14 | * To do: define access rights for executable file or device driver 15 | * 16 | * Copyright 2016-2025 GNU General Public License v. 3 17 | * http://www.gnu.org/licenses/gpl.html 18 | ******************************************************************************* 19 | 20 | This C/C++ header file contains the official definition of the ForwardCom 21 | variant of the ELF file format for object files and executable files. 22 | The latest version is stored at https://github.com/ForwardCom/bintools 23 | 24 | An executable file contains the following elements: 25 | 1. ELF file header with the structure ElfFwcEhdr 26 | 2. Any number of program headers with the structure ElfFwcPhdr 27 | 3. Raw data. Each section aligned by 8 28 | 4. Any number of section headers with the structure ElfFwcShdr 29 | The sections can have different types as defined by sh_type, including 30 | code, data, symbol tables, string tables, and relocation records. 31 | 32 | The program headers and section headers may point to the same raw data. The 33 | program headers are used by the loader and the section headers are used by the 34 | linker. An object file has the same format, but with no program headers. 35 | 36 | The program headers in an executable file must come in the following order: 37 | * const (ip) 38 | * code (ip) 39 | * data (datap) 40 | * bss (datap) 41 | * data (threadp) 42 | * bss (threadp) 43 | There may be any number of headers in each category. 44 | The raw data in an executable file must come in the same order as the headers 45 | that point to them. 46 | These rules are intended to simplify boot loader code in small devices. 47 | 48 | 49 | ForwardCom library files have the standard UNIX archive format with a sorted 50 | symbol table. The details are described below. Dynamic link libraries and 51 | shared objects are not used in the ForwardCom system. 52 | 53 | ******************************************************************************/ 54 | 55 | #ifndef ELF_FORW_H 56 | #define ELF_FORW_H 112 // version number 57 | 58 | 59 | //-------------------------------------------------------------------------- 60 | // ELF FILE HEADER 61 | //-------------------------------------------------------------------------- 62 | 63 | struct ElfFwcEhdr { 64 | uint8_t e_ident[16]; // Magic number and other info 65 | // e_ident[EI_CLASS] = ELFCLASS64: file class 66 | // e_ident[EI_DATA] = ELFDATA2LSB: 2's complement, little endian 67 | // e_ident[EI_VERSION] = EV_CURRENT: current ELF version 68 | // e_ident[EI_OSABI] = ELFOSABI_FORWARDCOM 69 | // e_ident[EI_ABIVERSION] = 0 70 | // The rest is unused padding 71 | uint16_t e_type; // Object file type 72 | uint16_t e_machine; // Architecture 73 | uint32_t e_version; // Object file version 74 | uint64_t e_entry; // Entry point virtual address 75 | uint64_t e_phoff; // Program header table file offset 76 | uint64_t e_shoff; // Section header table file offset 77 | uint32_t e_flags; // Processor-specific flags. We may define any values for these flags 78 | uint16_t e_ehsize; // ELF header size in bytes 79 | uint16_t e_phentsize; // Program header table entry size 80 | uint16_t e_phnum; // Program header table entry count 81 | uint16_t e_shentsize; // Section header table entry size 82 | uint32_t e_shnum; // Section header table entry count (was uint16_t) 83 | uint32_t e_shstrndx; // Section header string table index (was uint16_t) 84 | // additional fields for ForwardCom: 85 | uint32_t e_stackvect; // number of vectors to store on stack. multiply by max vector length and add to stacksize 86 | uint64_t e_stacksize; // size of stack for main thread 87 | uint64_t e_ip_base; // __ip_base relative to first ip based segment 88 | uint64_t e_datap_base; // __datap_base relative to first datap based segment 89 | uint64_t e_threadp_base; // __threadp_base relative to first threadp based segment 90 | }; 91 | 92 | 93 | // Fields in the e_ident array. The EI_* macros are indices into the array. 94 | // The macros under each EI_* macro are the values the byte may have. 95 | 96 | // Conglomeration of the identification bytes, for easy testing as a word. 97 | #define ELFMAG 0x464C457F // 0x7F 'E' 'L' 'F' 98 | 99 | // File class 100 | #define EI_CLASS 4 // File class byte index 101 | #define ELFCLASSNONE 0 // Invalid class 102 | #define ELFCLASS32 1 // 32-bit objects 103 | #define ELFCLASS64 2 // 64-bit objects * 104 | #define ELFCLASSNUM 3 105 | 106 | #define EI_DATA 5 // Data encoding byte index 107 | #define ELFDATANONE 0 // Invalid data encoding 108 | #define ELFDATA2LSB 1 // 2's complement, little endian * 109 | #define ELFDATA2MSB 2 // 2's complement, big endian 110 | #define ELFDATANUM 3 111 | 112 | #define EI_VERSION 6 // File version byte index 113 | 114 | #define EI_OSABI 7 // OS ABI identification 115 | #define ELFOSABI_SYSV 0 // UNIX System V ABI 116 | #define ELFOSABI_HPUX 1 // HP-UX 117 | #define ELFOSABI_ARM 97 // ARM 118 | #define ELFOSABI_STANDALONE 255 // Standalone (embedded) application 119 | #define ELFOSABI_FORWARDCOM 250 // ForwardCom 120 | 121 | #define EI_ABIVERSION 8 // x86 ABI version 122 | #define EI_ABIVERSION_FORWARDCOM 1 // ForwardCom ABI version 123 | 124 | #define EI_PAD 9 // Byte index of padding bytes 125 | 126 | // Legal values for e_type (object file type). 127 | #define ET_NONE 0 // No file type 128 | #define ET_REL 1 // Relocatable file 129 | #define ET_EXEC 2 // Executable file 130 | #define ET_DYN 3 // Shared object file (not used by ForwardCom) 131 | #define ET_CORE 4 // Core file 132 | #define ET_NUM 5 // Number of defined types 133 | #define ET_LOOS 0xfe00 // OS-specific range start 134 | #define ET_HIOS 0xfeff // OS-specific range end 135 | #define ET_LOPROC 0xff00 // Processor-specific range start 136 | #define ET_HIPROC 0xffff // Processor-specific range end 137 | 138 | // Legal values for e_machine (architecture) 139 | #define EM_NONE 0 // No machine 140 | #define EM_M32 1 // AT&T WE 32100 141 | #define EM_SPARC 2 // SUN SPARC 142 | #define EM_386 3 // Intel 80386 143 | #define EM_68K 4 // Motorola m68k family 144 | #define EM_88K 5 // Motorola m88k family 145 | #define EM_860 7 // Intel 80860 146 | #define EM_MIPS 8 // MIPS R3000 big-endian 147 | #define EM_S370 9 // IBM System/370 148 | #define EM_MIPS_RS3_LE 10 // MIPS R3000 little-endian 149 | #define EM_PARISC 15 // HPPA 150 | #define EM_VPP500 17 // Fujitsu VPP500 151 | #define EM_SPARC32PLUS 18 // Sun's "v8plus" 152 | #define EM_960 19 // Intel 80960 153 | #define EM_PPC 20 // PowerPC 154 | #define EM_PPC64 21 // PowerPC 64-bit 155 | #define EM_S390 22 // IBM S390 156 | #define EM_V800 36 // NEC V800 series 157 | #define EM_FR20 37 // Fujitsu FR20 158 | #define EM_RH32 38 // TRW RH-32 159 | #define EM_RCE 39 // Motorola RCE 160 | #define EM_ARM 40 // ARM 161 | #define EM_FAKE_ALPHA 41 // Digital Alpha 162 | #define EM_SH 42 // Hitachi SH 163 | #define EM_SPARCV9 43 // SPARC v9 64-bit 164 | #define EM_TRICORE 44 // Siemens Tricore 165 | #define EM_ARC 45 // Argonaut RISC Core 166 | #define EM_H8_300 46 // Hitachi H8/300 167 | #define EM_H8_300H 47 // Hitachi H8/300H 168 | #define EM_H8S 48 // Hitachi H8S 169 | #define EM_H8_500 49 // Hitachi H8/500 170 | #define EM_IA_64 50 // Intel Merced 171 | #define EM_MIPS_X 51 // Stanford MIPS-X 172 | #define EM_COLDFIRE 52 // Motorola Coldfire 173 | #define EM_68HC12 53 // Motorola M68HC12 174 | #define EM_MMA 54 // Fujitsu MMA Multimedia Accelerator 175 | #define EM_PCP 55 // Siemens PCP 176 | #define EM_NCPU 56 // Sony nCPU embeeded RISC 177 | #define EM_NDR1 57 // Denso NDR1 microprocessor 178 | #define EM_STARCORE 58 // Motorola Start*Core processor 179 | #define EM_ME16 59 // Toyota ME16 processor 180 | #define EM_ST100 60 // STMicroelectronic ST100 processor 181 | #define EM_TINYJ 61 // Advanced Logic Corp. Tinyj emb.fam 182 | #define EM_X86_64 62 // AMD x86-64 architecture 183 | #define EM_PDSP 63 // Sony DSP Processor 184 | #define EM_FX66 66 // Siemens FX66 microcontroller 185 | #define EM_ST9PLUS 67 // STMicroelectronics ST9+ 8/16 mc 186 | #define EM_ST7 68 // STmicroelectronics ST7 8 bit mc 187 | #define EM_68HC16 69 // Motorola MC68HC16 microcontroller 188 | #define EM_68HC11 70 // Motorola MC68HC11 microcontroller 189 | #define EM_68HC08 71 // Motorola MC68HC08 microcontroller 190 | #define EM_68HC05 72 // Motorola MC68HC05 microcontroller 191 | #define EM_SVX 73 // Silicon Graphics SVx 192 | #define EM_AT19 74 // STMicroelectronics ST19 8 bit mc 193 | #define EM_VAX 75 // Digital VAX 194 | #define EM_CRIS 76 // Axis Communications 32-bit embedded processor 195 | #define EM_JAVELIN 77 // Infineon Technologies 32-bit embedded processor 196 | #define EM_FIREPATH 78 // Element 14 64-bit DSP Processor 197 | #define EM_ZSP 79 // LSI Logic 16-bit DSP Processor 198 | #define EM_MMIX 80 // Donald Knuth's educational 64-bit processor 199 | #define EM_HUANY 81 // Harvard University machine-independent object files 200 | #define EM_PRISM 82 // SiTera Prism 201 | #define EM_AVR 83 // Atmel AVR 8-bit microcontroller 202 | #define EM_FR30 84 // Fujitsu FR30 203 | #define EM_D10V 85 // Mitsubishi D10V 204 | #define EM_D30V 86 // Mitsubishi D30V 205 | #define EM_V850 87 // NEC v850 206 | #define EM_M32R 88 // Mitsubishi M32R 207 | #define EM_MN10300 89 // Matsushita MN10300 208 | #define EM_MN10200 90 // Matsushita MN10200 209 | #define EM_PJ 91 // picoJava 210 | #define EM_OPENRISC 92 // OpenRISC 32-bit embedded processor 211 | #define EM_RISCV 243 // RISC-V 212 | #define EM_OR32 0x8472 // Open RISC 213 | #define EM_ALPHA 0x9026 // Digital Alpha 214 | #define EM_FORWARDCOM 0x6233 // ForwardCom preliminary value (constructed from F=6, W=23, C=3) 215 | 216 | // Legal values for e_version (version). 217 | #define EV_NONE 0 // Invalid ELF version 218 | #define EV_CURRENT 1 // Current version 219 | #define EV_NUM 2 220 | 221 | // Values for e_flags (file header flags) 222 | #define EF_INCOMPLETE 0x01 // Incomplete executable file contains unresolved references 223 | #define EF_RELINKABLE 0x02 // Relinking of executable file is possible 224 | #define EF_RELOCATE 0x10 // Relocation needed when program is loaded 225 | #define EF_POSITION_DEPENDENT 0x20 // Contains position-dependent relocations. Multiple processes cannot share same read-only data and code 226 | 227 | 228 | //-------------------------------------------------------------------------- 229 | // SECTION HEADER 230 | //-------------------------------------------------------------------------- 231 | 232 | struct ElfFwcShdr { 233 | uint32_t sh_name; // Section name (string table index) 234 | uint32_t sh_flags; // Section flags 235 | uint64_t sh_addr; // Address relative to section group begin 236 | uint64_t sh_offset; // Section file offset 237 | uint64_t sh_size; // Section size in bytes 238 | uint32_t sh_link; // Link to symbol section or string table 239 | uint32_t sh_entsize; // Entry size if section holds table 240 | uint32_t sh_module; // Module name in relinkable executable 241 | uint32_t sh_library; // Library name in relinkable executable 242 | uint32_t unused1; // Alignment filler 243 | uint8_t sh_type; // Section type 244 | uint8_t sh_align; // Section alignment = 1 << sh_align 245 | uint8_t sh_relink; // Commands used during relinking. Unused in file 246 | uint8_t unused2; // Unused filler 247 | }; 248 | 249 | // Legal values for sh_type (section type) 250 | #define SHT_NULL 0 // Section header table entry unused 251 | #define SHT_SYMTAB 2 // Symbol table. There can be only one symbol table 252 | #define SHT_STRTAB 3 // String table. There are two string tables, one for symbol names and one for section names 253 | #define SHT_RELA 4 // Relocation entries with addends 254 | #define SHT_NOTE 7 // Notes 255 | #define SHT_PROGBITS 0x11 // Program data 256 | #define SHT_NOBITS 0x12 // Uninitialized data space (bss) 257 | #define SHT_COMDAT 0x14 // Communal data or code. Duplicate and unreferenced sections are removed 258 | #define SHT_ALLOCATED 0x10 // Allocated at runtime. This bits indicates SHT_PROGBITS, SHT_NOBITS, SHT_COMDAT 259 | #define SHT_LIST 0x20 // Other list. Not loaded into memory. (unsorted event list, ) 260 | #define SHT_STACKSIZE 0x41 // Records for calculation of stack size 261 | #define SHT_ACCESSRIGHTS 0x42 // Records for indicating desired access rights of executable file or device driver 262 | // obsolete types, not belonging to ForwardCom 263 | //#define SHT_REL 9 // Relocation entries, no addends 264 | //#define SHT_HASH 5 // Symbol hash table 265 | //#define SHT_DYNAMIC 6 // Dynamic linking information 266 | //#define SHT_DYNSYM 0xB // Dynamic linker symbol table 267 | //#define SHT_SHLIB 0xA // Reserved 268 | //#define SHT_GROUP 0x11 // Section group 269 | 270 | // Legal values for sh_flags (section flags). 271 | #define SHF_EXEC 0x1 // Executable 272 | #define SHF_WRITE 0x2 // Writable 273 | #define SHF_READ 0x4 // Readable 274 | #define SHF_PERMISSIONS (SHF_EXEC | SHF_WRITE | SHF_READ) // access permissions mask 275 | #define SHF_MERGE 0x10 // Elements with same value might be merged 276 | #define SHF_STRINGS 0x20 // Contains nul-terminated strings 277 | #define SHF_INFO_LINK 0x40 // sh_info contains section header index 278 | #define SHF_ALLOC 0x100 // Occupies memory during execution 279 | #define SHF_IP 0x1000 // Addressed relative to IP (executable and read-only sections) 280 | #define SHF_DATAP 0x2000 // Addressed relative to DATAP (writeable data sections) 281 | #define SHF_THREADP 0x4000 // Addressed relative to THREADP (thread-local data sections) 282 | #define SHF_BASEPOINTER (SHF_IP | SHF_DATAP | SHF_THREADP) // mask to detect base pointer 283 | #define SHF_EVENT_HND 0x100000 // Event handler list, contains ElfFwcEvent structures 284 | #define SHF_EXCEPTION_HND 0x200000 // Exception handler and stack unroll information 285 | #define SHF_DEBUG_INFO 0x400000 // Debug information 286 | #define SHF_COMMENT 0x800000 // Comments, including copyright and required libraries 287 | #define SHF_RELINK 0x1000000 // Section in executable file can be relinked 288 | #define SHF_FIXED 0x2000000 // Non-relinkable section in relinkable file has fixed address relative to base pointers 289 | #define SHF_AUTOGEN 0x4000000 // Section is generated by the linker. remake when relinking 290 | 291 | 292 | //-------------------------------------------------------------------------- 293 | // SYMBOL TABLES 294 | //-------------------------------------------------------------------------- 295 | 296 | // Symbol table entry, x64 297 | struct Elf64_Sym { 298 | uint32_t st_name; // Symbol name (string tbl index) 299 | uint8_t st_type: 4, // Symbol type 300 | st_bind: 4; // Symbol binding 301 | uint8_t st_other; // Symbol visibility 302 | uint16_t st_section; // Section index 303 | uint64_t st_value; // Symbol value 304 | uint64_t st_size; // Symbol size 305 | }; 306 | 307 | // Symbol table entry, ForwardCom 308 | struct ElfFwcSym { 309 | uint32_t st_name; // Symbol name (string table index) 310 | uint8_t st_type; // Symbol type 311 | uint8_t st_bind; // Symbol binding 312 | uint8_t unused1, unused2;// Alignment fillers 313 | uint32_t st_other; // Symbol visibility and additional type information 314 | uint32_t st_section; // Section header index (zero for external symbols) 315 | uint64_t st_value; // Symbol value 316 | uint32_t st_unitsize; // Size of array elements or data unit. Data type is given by st_unitsize and STV_FLOAT 317 | // st_unitsize is 4 or more for executable code 318 | uint32_t st_unitnum; // Symbol size = st_unitsize * st_unitnum 319 | uint32_t st_reguse1; // Register use. bit 0-31 = r0-r31 320 | uint32_t st_reguse2; // Register use. bit 0-31 = v0-v31 321 | }; 322 | 323 | // Values for st_bind: symbol binding 324 | #define STB_LOCAL 0 // Local symbol 325 | #define STB_GLOBAL 1 // Global symbol 326 | #define STB_WEAK 2 // Weak symbol 327 | #define STB_WEAK2 6 // Weak public symbol with local reference is both import and export 328 | #define STB_UNRESOLVED 0x0A // Symbol is unresolved. Treat as weak 329 | #define STB_IGNORE 0x10 // This value is used only internally in the linker (ignore weak/strong during search; ignore overridden weak symbol) 330 | #define STB_EXE 0x80 // This value is used only internally in the linker (copy to executable file) 331 | 332 | // Values for st_type: symbol type 333 | #define STT_NOTYPE 0 // Symbol type is unspecified 334 | #define STT_OBJECT 1 // Symbol is a data object 335 | #define STT_FUNC 2 // Symbol is a code object 336 | #define STT_SECTION 3 // Symbol is a section begin 337 | #define STT_FILE 4 // Symbol's name is file name 338 | #define STT_COMMON 5 // Symbol is a common data object. Use STV_COMMON instead! 339 | //#define STT_TLS 6 // Thread local data object. Use STV_THREADP instead! 340 | #define STT_CONSTANT 0x10 // Symbol is a constant with no address 341 | #define STT_VARIABLE 0x11 // Symbol is a variable used during assembly. Should not occur in object file 342 | #define STT_EXPRESSION 0x12 // Symbol is an expression used during assembly. Should not occur in object file 343 | #define STT_TYPENAME 0x14 // Symbol is a type name used during assembly. Should not occur in object file 344 | 345 | // Symbol visibility specification encoded in the st_other field. 346 | #define STV_DEFAULT 0 // Default symbol visibility rules 347 | //#define STV_INTERNAL 1 // Processor specific hidden class 348 | #define STV_HIDDEN 0x20 // Symbol unavailable in other modules 349 | //#define STV_PROTECTED 3 // Not preemptible, not exported 350 | // st_other types added for ForwardCom: 351 | #define STV_EXEC SHF_EXEC // = 0x1. Executable code 352 | #define STV_WRITE SHF_WRITE // = 0x2. Writable data 353 | #define STV_READ SHF_READ // = 0x4. Readable data 354 | #define STV_IP SHF_IP // = 0x1000. Addressed relative to IP (in executable and read-only sections) 355 | #define STV_DATAP SHF_DATAP // = 0x2000. Addressed relative to DATAP (in writeable data sections) 356 | #define STV_THREADP SHF_THREADP // = 0x4000. Addressed relative to THREADP (in thrad local data sections) 357 | #define STV_REGUSE 0x10000 // st_reguse field contains register use information 358 | #define STV_FLOAT 0x20000 // st_value is a double precision floating point (with STT_CONSTANT) 359 | #define STV_STRING 0x40000 // st_value is an assemble-time string. Should not occur in object file 360 | #define STV_COMMON 0x100000 // Symbol is communal. Multiple identical instances can be joined. Unreferenced instances can be removed 361 | #define STV_UNWIND 0x400000 // Symbol is a table with exception handling and stack unwind information 362 | #define STV_DEBUG 0x800000 // Symbol is a table with debug information 363 | #define STV_RELINK SHF_RELINK // Symbol in executable file can be relinked 364 | #define STV_AUTOGEN SHF_AUTOGEN // Symbol is generated by the linker. remake when relinking 365 | #define STV_MAIN 0x10000000 // Main entry point in executable file 366 | #define STV_EXPORTED 0x20000000 // Exported from executable file 367 | #define STV_THREAD 0x40000000 // Thread function. Requires own stack 368 | #define STV_SECT_ATTR (SHF_EXEC | SHF_READ | SHF_WRITE | SHF_IP | SHF_DATAP | SHF_THREADP | SHF_RELINK | SHF_AUTOGEN) // section attributes to copy to symbol 369 | 370 | 371 | /* Definition of absolute symbols: 372 | x86 ELF uses symbols with st_section = SHN_ABS_X86 to indicate a public absolute symbol. 373 | ForwardCom uses st_type = STT_CONSTANT and sets st_section to the index of an arbitrary 374 | section in the same module as the absolute symbol. This is necessary for indicating which 375 | module an absolute symbol belongs to in a relinkable executable file. An object file 376 | defining absolute symbols must have at least one section, even if it is empty. 377 | */ 378 | // Special section indices. not used in ForwardCom 379 | #define SHN_UNDEF 0 // Undefined section. external symbol 380 | //#define SHN_LORESERVE ((int16_t)0xff00) // Start of reserved indices 381 | //#define SHN_LOPROC ((int16_t)0xff00) // Start of processor-specific 382 | //#define SHN_HIPROC ((int16_t)0xff1f) // End of processor-specific 383 | //#define SHN_LOOS ((int16_t)0xff20) // Start of OS-specific 384 | //#define SHN_HIOS ((int16_t)0xff3f) // End of OS-specific 385 | #define SHN_ABS_X86 ((int16_t)0xfff1) // Associated symbol is absolute (x86 ELF) 386 | //#define SHN_COMMON ((int16_t)0xfff2) // Associated symbol is common (x86 ELF) 387 | //#define SHN_XINDEX ((int16_t)0xffff) // Index is in extra table 388 | //#define SHN_HIRESERVE ((int16_t)0xffff) // End of reserved indices 389 | 390 | 391 | //-------------------------------------------------------------------------- 392 | // RELOCATION TABLES 393 | //-------------------------------------------------------------------------- 394 | 395 | // Relocation table entry with addend, x86-64 in section of type SHT_RELA. Not used in ForwardCom 396 | struct Elf64_Rela { 397 | uint64_t r_offset; // Address 398 | uint32_t r_type; // Relocation type 399 | uint32_t r_sym; // Symbol index 400 | int64_t r_addend; // Addend 401 | }; 402 | 403 | // Relocation table entry for ForwardCom (in section of type SHT_RELA). 404 | struct ElfFwcReloc { 405 | uint64_t r_offset; // Address relative to section 406 | uint32_t r_section; // Section index 407 | uint32_t r_type; // Relocation type 408 | uint32_t r_sym; // Symbol index 409 | int32_t r_addend; // Addend 410 | uint32_t r_refsym; // Reference symbol 411 | }; 412 | 413 | 414 | // AMD x86-64 relocation types 415 | #define R_X86_64_NONE 0 // No reloc 416 | #define R_X86_64_64 1 // Direct 64 bit 417 | #define R_X86_64_PC32 2 // Self relative 32 bit signed (not RIP relative in the sense used in COFF files) 418 | #define R_X86_64_GOT32 3 // 32 bit GOT entry 419 | #define R_X86_64_PLT32 4 // 32 bit PLT address 420 | #define R_X86_64_COPY 5 // Copy symbol at runtime 421 | #define R_X86_64_GLOB_DAT 6 // Create GOT entry 422 | #define R_X86_64_JUMP_SLOT 7 // Create PLT entry 423 | #define R_X86_64_RELATIVE 8 // Adjust by program base 424 | #define R_X86_64_GOTPCREL 9 // 32 bit signed self relative offset to GOT 425 | #define R_X86_64_32 10 // Direct 32 bit zero extended 426 | #define R_X86_64_32S 11 // Direct 32 bit sign extended 427 | #define R_X86_64_16 12 // Direct 16 bit zero extended 428 | #define R_X86_64_PC16 13 // 16 bit sign extended self relative 429 | #define R_X86_64_8 14 // Direct 8 bit sign extended 430 | #define R_X86_64_PC8 15 // 8 bit sign extended self relative 431 | #define R_X86_64_IRELATIVE 37 // Reference to PLT entry of indirect function (STT_GNU_IFUNC) 432 | 433 | 434 | // ForwardCom relocation types are composed of these three fields: 435 | // Relocation type in bit 16-31 436 | // Relocation size in bit 8-15 437 | // Scale factor in bit 0-7. 438 | // The r_type field is composed by OR'ing these three. 439 | // The value in the relocation field of the specified size will be multiplied by the scale factor. 440 | // All relative relocations use signed values. 441 | // Instructions with self-relative (IP-relative) addressing are using the END of the instruction 442 | // as reference point. The r_addend field must compensate for the distance between 443 | // the end of the instruction and the beginning of the address field. This will be -4 for most 444 | // jump and call instructions. 445 | // Any offset of the target may be added to r_addend. The value of r_addend is not scaled. 446 | // Relocations relative to an arbitrary reference point can be used in jump tables. 447 | // The reference point is indicated by a symbol index in r_refsym. 448 | // The system function ID relocations are done by the loader, where r_sym indicates the name 449 | // of the function in the string table, and r_addend indicates the name of the module or 450 | // device driver. 451 | // The value at r_offset is not used in the calculation but overwritten with the calculated 452 | // target address. 453 | 454 | // ForwardCom relocation types 455 | #define R_FORW_ABS 0x000000 // Absolute address. Scaling is possible, but rarely used 456 | #define R_FORW_SELFREL 0x010000 // Self relative. Scale by 4 for code address 457 | #define R_FORW_IP_BASE 0x040000 // Relative to __ip_base. Any scale 458 | #define R_FORW_DATAP 0x050000 // Relative to __datap_base. Any scale 459 | #define R_FORW_THREADP 0x060000 // Relative to __threadp_base. Any scale 460 | #define R_FORW_REFP 0x080000 // Relative to arbitrary reference point. Reference symbol index in high 32 bits of r_addend. Any scale 461 | #define R_FORW_SYSFUNC 0x100000 // System function ID for system_call, 16 or 32 bit 462 | #define R_FORW_SYSMODUL 0x110000 // System module ID for system_call, 16 or 32 bit 463 | #define R_FORW_SYSCALL 0x120000 // Combined system module and function ID for system_call, 32 or 64 bit 464 | #define R_FORW_DATASTACK 0x200000 // Calculated size of data stack for function, 32 or 64 bit. Scale by 1 or 8 465 | #define R_FORW_CALLSTACK 0x210000 // Calculated size of call stack for function, 32 bit. Scale by 1 or 8 466 | #define R_FORW_REGUSE 0x400000 // Register use of function, 64 bit 467 | #define R_FORW_RELTYPEMASK 0xFF0000 // Mask for isolating relocation type 468 | 469 | // Relocation sizes 470 | #define R_FORW_NONE 0x000000 // No relocation 471 | #define R_FORW_8 0x000100 // 8 bit relocation size 472 | #define R_FORW_16 0x000200 // 16 bit relocation size 473 | #define R_FORW_24 0x000300 // 24 bit relocation size 474 | #define R_FORW_32 0x000400 // 32 bit relocation size 475 | #define R_FORW_32LO 0x000500 // Low 16 of 32 bits relocation 476 | #define R_FORW_32HI 0x000600 // High 16 of 32 bits relocation 477 | #define R_FORW_64 0x000800 // 64 bit relocation size 478 | #define R_FORW_64LO 0x000900 // Low 32 of 64 bits relocation 479 | #define R_FORW_64HI 0x000A00 // High 32 of 64 bits relocation 480 | #define R_FORW_RELSIZEMASK 0x00FF00 // Mask for isolating relocation size 481 | 482 | // Relocation scale factors 483 | #define R_FORW_SCALE1 0x000000 // Scale factor 1 484 | #define R_FORW_SCALE2 0x000001 // Scale factor 2 485 | #define R_FORW_SCALE4 0x000002 // Scale factor 4 486 | #define R_FORW_SCALE8 0x000003 // Scale factor 8 487 | #define R_FORW_SCALE16 0x000004 // Scale factor 16 488 | #define R_FORW_RELSCALEMASK 0x0000FF // Mask for isolating relocation scale factor 489 | 490 | // Relocation options 491 | #define R_FORW_RELINK 0x01000000 // Refers to relinkable symbol in executable file 492 | #define R_FORW_LOADTIME 0x02000000 // Must be relocated at load time. Records with this bit must come first 493 | 494 | 495 | //-------------------------------------------------------------------------- 496 | // PROGRAM HEADER 497 | //-------------------------------------------------------------------------- 498 | 499 | // Program header 500 | struct ElfFwcPhdr { 501 | uint32_t p_type; // Segment type 502 | uint32_t p_flags; // Segment flags 503 | uint64_t p_offset; // Segment file offset 504 | uint64_t p_vaddr; // Segment virtual address 505 | uint64_t p_paddr; // Segment physical address (not used. indicates first section instead) 506 | uint64_t p_filesz; // Segment size in file 507 | uint64_t p_memsz; // Segment size in memory 508 | uint8_t p_align; // Segment alignment 509 | uint8_t unused[7]; 510 | }; 511 | 512 | // Legal values for p_type (segment type). 513 | 514 | #define PT_NULL 0 // Program header table entry unused 515 | #define PT_LOAD 1 // Loadable program segment 516 | #define PT_DYNAMIC 2 // Dynamic linking information 517 | #define PT_INTERP 3 // Program interpreter 518 | #define PT_NOTE 4 // Auxiliary information 519 | #define PT_SHLIB 5 // Reserved 520 | #define PT_PHDR 6 // Entry for header table itself 521 | //#define PT_NUM 7 // Number of defined types 522 | #define PT_LOOS 0x60000000 // Start of OS-specific 523 | #define PT_HIOS 0x6fffffff // End of OS-specific 524 | #define PT_LOPROC 0x10 // Start of processor-specific 525 | #define PT_HIPROC 0x5fffffff // End of processor-specific 526 | 527 | // Legal values for p_flags (segment flags) are the same as section flags, 528 | // see sh_flags above 529 | 530 | /* 531 | // Legal values for note segment descriptor types for core files. Not used 532 | #define NT_PRSTATUS 1 // Contains copy of prstatus struct 533 | #define NT_FPREGSET 2 // Contains copy of fpregset struct 534 | #define NT_PRPSINFO 3 // Contains copy of prpsinfo struct 535 | #define NT_PRXREG 4 // Contains copy of prxregset struct 536 | #define NT_PLATFORM 5 // String from sysinfo(SI_PLATFORM) 537 | #define NT_AUXV 6 // Contains copy of auxv array 538 | #define NT_GWINDOWS 7 // Contains copy of gwindows struct 539 | #define NT_PSTATUS 10 // Contains copy of pstatus struct 540 | #define NT_PSINFO 13 // Contains copy of psinfo struct 541 | #define NT_PRCRED 14 // Contains copy of prcred struct 542 | #define NT_UTSNAME 15 // Contains copy of utsname struct 543 | #define NT_LWPSTATUS 16 // Contains copy of lwpstatus struct 544 | #define NT_LWPSINFO 17 // Contains copy of lwpinfo struct 545 | #define NT_PRFPXREG 20 // Contains copy of fprxregset struct 546 | */ 547 | // Legal values for the note segment descriptor types for object files. 548 | #define NT_VERSION 1 // Contains a version string. 549 | 550 | 551 | // Note section contents. Each entry in the note section begins with a header of a fixed form. 552 | 553 | struct Elf64_Nhdr { 554 | uint32_t n_namesz; // Length of the note's name 555 | uint32_t n_descsz; // Length of the note's descriptor 556 | uint32_t n_type; // Type of the note 557 | }; 558 | 559 | /* Defined note types for GNU systems. */ 560 | 561 | /* ABI information. The descriptor consists of words: 562 | word 0: OS descriptor 563 | word 1: major version of the ABI 564 | word 2: minor version of the ABI 565 | word 3: subminor version of the ABI 566 | */ 567 | #define ELF_NOTE_ABI 1 568 | 569 | /* Known OSes. These value can appear in word 0 of an ELF_NOTE_ABI 570 | note section entry. */ 571 | #define ELF_NOTE_OS_LINUX 0 572 | #define ELF_NOTE_OS_GNU 1 573 | #define ELF_NOTE_OS_SOLARIS2 2 574 | 575 | #define FILE_DATA_ALIGN 3 // section data must be aligned by (1 << FILE_DATA_ALIGN) in ELF file 576 | 577 | // Memory map definitions 578 | #define MEMORY_MAP_ALIGN 3 // align memory map entries by (1 << MEMORY_MAP_ALIGN) 579 | #define DATA_EXTRA_SPACE 0x10 // extra space after const data section and last data section 580 | 581 | 582 | //-------------------------------------------------------------------------- 583 | // EVENT HANDLER SYSTEM 584 | //-------------------------------------------------------------------------- 585 | /* 586 | 587 | A program module may contain a table of event handler records in a read-only 588 | section with the attribute SHF_EVENT_HND. The event handler system may be used 589 | for handling events, commands, and messages. It is also used for initialization 590 | and clean-up. This replaces the constructors and destructors sections of other 591 | systems. 592 | 593 | The linker will sort the event records of all modules according to event id, key, 594 | and priority. If there is more than one event handler for a particular event, 595 | then all the event handlers will be called in the order of priority. 596 | */ 597 | 598 | // event record 599 | struct ElfFwcEvent { 600 | int32_t functionPtr; // scaled relative pointer to event handler function = (function_address - __ip_base) / 4 601 | uint32_t priority; // priority. Highest values are called first. Normal priority = 0x1000 602 | uint32_t key; // keyboard hotkey, menu item, or icon id for user command events 603 | uint32_t event_id; // event ID 604 | }; 605 | 606 | 607 | //-------------------------------------------------------------------------- 608 | // STACK SIZE TABLES 609 | //-------------------------------------------------------------------------- 610 | 611 | // SHT_STACKSIZE stack table entry 612 | // To do: Add information for recursive function calls and indirect calls to unknown functions 613 | struct ElfFwcStacksize { 614 | uint32_t ss_syma; // Public symbol index 615 | uint32_t ss_symb; // External symbol index. Zero for frame function or to indicate own stack use 616 | uint64_t ss_framesize; // Size of data stack frame in syma when calling symb 617 | uint32_t ss_numvectors; // Additional data stack frame size for vectors. Multiply by maximum vector length 618 | uint32_t ss_calls; // Size of call stack when syma calls symb (typically 1). Multiply by stack word size = 8 619 | }; 620 | 621 | 622 | //-------------------------------------------------------------------------- 623 | // MASK BITS 624 | //-------------------------------------------------------------------------- 625 | // Masks are used for conditional execution and for setting options 626 | 627 | // Mask bit numbers. These bits are used in instruction masks and NUMCONTR to specify various options 628 | 629 | #define MSK_ENABLE 0 // the instruction is not executed if bit number 0 is 0 630 | #define MSKI_OPTIONS 18 // bit number 18-23 contain instruction-specific options. currently unused 631 | #define MSKI_ROUNDING 10 // bit number 10-12 indicate rounding mode: 632 | // 00: round to nearest or even 633 | // 01: round down 634 | // 10: round up 635 | // 11: truncate towards zero 636 | // 100: odd if not exact 637 | #define MSKI_EXCEPTIONS 2 // bit number 2-5 enable exceptions for division by zero, overflow, underflow, inexact 638 | #define MSK_DIVZERO 2 // enable NaN exception for floating point division by zero 639 | #define MSK_OVERFLOW 3 // enable NaN exception for floating point overflow 640 | #define MSK_UNDERFLOW 4 // enable NaN exception for floating point underflow 641 | #define MSK_INEXACT 5 // enable NaN exception for floating point inexact 642 | #define MSK_SUBNORMAL 13 // bit 13-14 enable subnormal numbers for float32 and float64 643 | #define MSK_CONST_TIME 31 // constant execution time, independent of data (for cryptographic security) 644 | 645 | 646 | //-------------------------------------------------------------------------- 647 | // EXCEPTION CODES 648 | //-------------------------------------------------------------------------- 649 | 650 | // NaN payloads are used for indicating that floating point exceptions or other 651 | // errors have occurred. 652 | // These values are left-justified in the NaN payload after the 'quiet' bit. 653 | const uint32_t nan_data_uninitialized= 0b111111111; // data not initialized 654 | const uint32_t nan_data_unavailable = 0b111111110; // data not available 655 | const uint32_t nan_div0 = 0b111110111; // division by 0 (mask bit 2) 656 | const uint32_t nan_overflow_div = 0b111101111; // division overflow (mask bit 3) 657 | const uint32_t nan_overflow_mul = 0b111101110; // multiplication overflow (mask bit 3) 658 | const uint32_t nan_overflow_fma = 0b111101101; // FMA overflow (mask bit 3) 659 | const uint32_t nan_overflow_add = 0b111101100; // addition and subtraction overflow (mask bit 3) 660 | const uint32_t nan_overflow_conv = 0b111101011; // conversion overflow (mask bit 3) 661 | const uint32_t nan_overflow_other = 0b111101010; // other overflow (mask bit 3) 662 | 663 | const uint32_t nan_invalid_0div0 = 0b111100111; // 0/0 664 | const uint32_t nan_invalid_infdivinf = 0b111100110; // inf/inf 665 | const uint32_t nan_invalid_0mulinf = 0b111100101; // 0*inf 666 | const uint32_t nan_invalid_inf_sub_inf = 0b111100100;// inf-inf 667 | 668 | const uint32_t nan_underflow = 0b111011111; // underflow (mask bit 4) 669 | const uint32_t nan_inexact = 0b111010111; // inexact result (mask bit 5) 670 | 671 | const uint32_t nan_invalid_sqrt = 0b111001111; // sqrt(-1) 672 | const uint32_t nan_invalid_log = 0b111001110; // log(-1) 673 | const uint32_t nan_invalid_pow = 0b111001101; // pow(-1, 2.3) 674 | const uint32_t nan_invalid_rem = 0b111001100; // inf rem 1, 1 rem 0 675 | 676 | const uint32_t nan_invalid_asin = 0b111000111; // asin(2) 677 | const uint32_t nan_invalid_acos = 0b111000110; // acos(2) 678 | const uint32_t nan_invalid_acosh = 0b111000011; // acosh(0) 679 | const uint32_t nan_invalid_atanh = 0b111000010; // atanh(2) 680 | 681 | // other standard math functions: 0b110xxxxxx 682 | // other math functions: 0b101xxxxxx 683 | // other functions: 0b100xxxxxx 684 | // user-defined: 0b0xxxxxxxx 685 | 686 | 687 | //-------------------------------------------------------------------------- 688 | // FORMAT FOR LIBRARY FILES 689 | //-------------------------------------------------------------------------- 690 | /* 691 | ForwardCom libraries use the standard Unix archive format. 692 | The preferred filename extension is .li 693 | 694 | The first archive member is a sorted symbol list, using the same format as used 695 | by Apple/Mac named "/SYMDEF SORTED/". It contains a sorted list of public symbols. 696 | The sort order is determined by the unsigned bytes of the ASCII/UTF-8 string. 697 | This format is chosen because it provides the fastest symbol search. 698 | 699 | The obsolete archive members with the name "/" containing symbol lists in less 700 | efficient formats are not included. 701 | 702 | The second archive member is a longnames record named "//" as used in Linux 703 | and Windows systems. It contains module names longer than 15 characters. 704 | Module names are stored without path so that they can be extracted on another 705 | computer that does not have the same file structure. 706 | 707 | The remaining modules contain object files in the format described above. 708 | --------------------------------------------------------------------------------*/ 709 | 710 | // Signature defining the start of an archive file 711 | #define archiveSignature "!\n" 712 | 713 | // Each library member starts with a UNIX archive member header: 714 | struct SUNIXLibraryHeader { 715 | char name[16]; // member name, terminated by '/' 716 | char date[12]; // member date, seconds, decimal ASCII 717 | char userID[6]; // member User ID, decimal ASCII 718 | char groupID[6]; // member Group ID, decimal ASCII 719 | char fileMode[8]; // member file mode, octal ASCII 720 | char fileSize[10]; // member file size not including header, decimal ASCII 721 | char headerEnd[2]; // "`\n" 722 | }; 723 | 724 | // Member names no longer than 15 characters are stored in the name field and 725 | // terminated by '/'. Longer names are stored in the longnames record. The name 726 | // field contains '/' followed by an index into the longnames string table. 727 | // This index is in decimal ASCII. 728 | 729 | // The "/SYMDEF SORTED/" record contains the following: 730 | // 1. The size of the symbol list = 8 * n, where n = number of exported symbols 731 | // in the library. 732 | // 2. For each symbol: the name as an index into the string table (relative to 733 | // the start of the sting table), followed by: 734 | // an offset to the module containing this symbol relative to file begin. 735 | // 3. The length of the string table. 736 | // 4. The string table as a sequence of zero-terminated strings. 737 | // 5. Zero-padding to a size divisible by 4. 738 | 739 | // All numbers in "/SYMDEF SORTED/" are 32-bit unsigned integers (little endian). 740 | 741 | // The longnames record has the name "//". It contains member names as zero-terminated strings. 742 | 743 | // All archive members are aligned by 8 744 | 745 | #endif // ELF_FORW_H 746 | --------------------------------------------------------------------------------