COFFI
1.2
               
coffi_types.hpp
Go to the documentation of this file.
1 /*
2 Copyright (C) 2014-2014 by Serge Lamikhov-Center
3 
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 THE SOFTWARE.
21 */
22 
23 /*! @file coffi_types.hpp
24  * @brief COFFI library basic structures and types.
25  *
26  * Do not include this file directly. This file is included by coffi.hpp.
27  */
28 
29 #ifndef COFFI_TYPES_HPP
30 #define COFFI_TYPES_HPP
31 
32 #include <string>
33 
34 namespace COFFI {
35 
36 #if !defined(COFFI_NO_OWN_TYPES) && !defined(COFFI_NO_CSTDINT) && \
37  !defined(COFFI_NO_INTTYPES) && !defined(DOXYGEN)
38 #include <stdint.h>
39 #else
40 typedef unsigned char uint8_t;
41 typedef signed char int8_t;
42 typedef uint16_t uint16_t;
43 typedef signed short int16_t;
44 #ifdef _MSC_VER
45 typedef unsigned __int32 uint32_t;
46 typedef signed __int32 int32_t;
47 typedef unsigned __int64 uint64_t;
48 typedef signed __int64 int64_t;
49 #else
50 typedef unsigned int uint32_t;
51 typedef signed int int32_t;
52 typedef unsigned long long uint64_t;
53 typedef signed long long int64_t;
54 #endif // _MSC_VER
55 #endif
56 
57 /*! @brief COFF symbol names size
58  *
59  * The name field in a symbol table consists of eight bytes that contain the name itself, if not too long, or else give an offset into the string table.
60  * See COFFI::coffi_strings.
61  */
62 #define COFFI_NAME_SIZE 8
63 
64 //! @name Identification index
65 //! @{
66 #define CI_MAG0 0
67 #define CI_MAG1 1
68 #define CI_MAG2 0
69 #define CI_MAG3 1
70 #define CI_MAG4 2
71 #define CI_MAG5 3
72 #define CI_NIDENT0 2
73 #define CI_NIDENT1 4
74 
75 //! @}
76 
77 //! @name Magic numbers
78 //! @{
79 #define PEMAG0 'M'
80 #define PEMAG1 'Z'
81 #define PEMAG2 'P'
82 #define PEMAG3 'E'
83 #define PEMAG4 0
84 #define PEMAG5 0
85 
86 //! @}
87 
88 //! @name Magic numbers of optional header
89 //! @{
90 #define OH_MAGIC_PE32 0x10B //!< PE32 format
91 #define OH_MAGIC_PE32ROM 0x107
92 #define OH_MAGIC_PE32PLUS 0x20B //!< PE32+ format
93 
94 //! @}
95 
96 // clang-format off
97 //! @name PE file characteristics
98 //! @{
99 #define IMAGE_FILE_RELOCS_STRIPPED 0x0001 //!< Image only, Windows CE, Windows NT and above. Indicates that the file does not contain base relocations and must therefore be loaded at its preferred base address. If the base address is not available, the loader reports an error. Operating systems running on top of MS-DOS (Win32s™) are generally not able to use the preferred base address and so cannot run these images. However, beginning with version 4.0, Windows will use an application’s preferred base address. The default behavior of the linker is to strip base relocations from EXEs.
100 #define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002 //!< Image only. Indicates that the image file is valid and can be run. If this flag is not set, it generally indicates a linker error.
101 #define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004 //!< COFF line numbers have been removed.
102 #define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008 //!< COFF symbol table entries for local symbols have been removed
103 #define IMAGE_FILE_AGGRESSIVE_WS_TRIM 0x0010 //!< Aggressively trim working set.
104 #define IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020 //!< App can handle > 2gb addresses.
105 #define IMAGE_FILE_16BIT_MACHINE 0x0040 //!< Use of this flag is reserved for future use.
106 #define IMAGE_FILE_BYTES_REVERSED_LO 0x0080 //!< Little endian: LSB precedes MSB in memory.
107 #define IMAGE_FILE_32BIT_MACHINE 0x0100 //!< Machine based on 32-bit-word architecture.
108 #define IMAGE_FILE_DEBUG_STRIPPED 0x0200 //!< Debugging information removed from image file.
109 #define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400 //!< If image is on removable media, copy and run from swap file.
110 #define IMAGE_FILE_SYSTEM 0x1000 //!< The image file is a system file, not a user program.
111 #define IMAGE_FILE_DLL 0x2000 //!< The image file is a dynamic-link library (DLL). Such files are considered executable files for almost all purposes, although they cannot be directly run.
112 #define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000 //!< File should be run only on a UP machine.
113 #define IMAGE_FILE_BYTES_REVERSED_HI 0x8000 //!< Big endian: MSB precedes LSB in memory.
114 
115 //! @}
116 
117 //! @name PE machine Types
118 //! @{
119 #define IMAGE_FILE_MACHINE_UNKNOWN 0x0000 //!< The contents of this field are assumed to be applicable to any machine type
120 #define IMAGE_FILE_MACHINE_AM33 0x01d3 //!< Matsushita AM33
121 #define IMAGE_FILE_MACHINE_AMD64 0x8664 //!< x64
122 #define IMAGE_FILE_MACHINE_ARM 0x01c0 //!< ARM little endian
123 #define IMAGE_FILE_MACHINE_ARMNT 0x01c4 //!< ARMv7( or higher ) Thumb mode only
124 #define IMAGE_FILE_MACHINE_ARM64 0xaa64 //!< ARMv8 in 64 - bit mode
125 #define IMAGE_FILE_MACHINE_EBC 0x0ebc //!< EFI byte code
126 #define IMAGE_FILE_MACHINE_I386 0x014c //!< Intel 386 or later processors and compatible processors
127 #define IMAGE_FILE_MACHINE_IA64 0x0200 //!< Intel Itanium processor family
128 #define IMAGE_FILE_MACHINE_M32R 0x9041 //!< Mitsubishi M32R little endian
129 #define IMAGE_FILE_MACHINE_MIPS16 0x0266 //!< MIPS16
130 #define IMAGE_FILE_MACHINE_MIPSFPU 0x0366 //!< MIPS with FPU
131 #define IMAGE_FILE_MACHINE_MIPSFPU16 0x0466 //!< MIPS16 with FPU
132 #define IMAGE_FILE_MACHINE_POWERPC 0x01f0 //!< Power PC little endian
133 #define IMAGE_FILE_MACHINE_POWERPCFP 0x01f1 //!< Power PC with floating point support
134 #define IMAGE_FILE_MACHINE_R4000 0x0166 //!< MIPS little endian
135 #define IMAGE_FILE_MACHINE_SH3 0x01a2 //!< Hitachi SH3
136 #define IMAGE_FILE_MACHINE_SH3DSP 0x01a3 //!< Hitachi SH3 DSP
137 #define IMAGE_FILE_MACHINE_SH4 0x01a6 //!< Hitachi SH4
138 #define IMAGE_FILE_MACHINE_SH5 0x01a8 //!< Hitachi SH5
139 #define IMAGE_FILE_MACHINE_THUMB 0x01c2 //!< ARM or Thumb( "interworking" )
140 #define IMAGE_FILE_MACHINE_WCEMIPSV2 0x0169 //!< MIPS little - endian WCE v2
141 
142 //! @}
143 
144 //! @name PE section flags
145 //! @{
146 #define IMAGE_SCN_TYPE_NO_PAD 0x00000008 //!< The section should not be padded to the next boundary.This flag is obsolete and is replaced by IMAGE_SCN_ALIGN_1BYTES.This is valid only for object files.
147 #define IMAGE_SCN_CNT_CODE 0x00000020 //!< The section contains executable code.
148 #define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 //!< The section contains initialized data.
149 #define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 //!< The section contains uninitialized data.
150 #define IMAGE_SCN_LNK_OTHER 0x00000100 //!< Reserved for future use.
151 #define IMAGE_SCN_LNK_INFO 0x00000200 //!< The section contains comments or other information.The.drectve section has this type.This is valid for object files only.
152 #define IMAGE_SCN_LNK_REMOVE 0x00000800 //!< The section will not become part of the image.This is valid only for object files.
153 #define IMAGE_SCN_LNK_COMDAT 0x00001000 //!< The section contains COMDAT data.For more information, see section 5.5.6, "COMDAT Sections( Object Only )." This is valid only for object files.
154 #define IMAGE_SCN_GPREL 0x00008000 //!< The section contains data referenced through the global pointer( GP ).
155 #define IMAGE_SCN_MEM_PURGEABLE 0x00020000 //!< Reserved for future use.
156 #define IMAGE_SCN_MEM_16BIT 0x00020000 //!< For ARM machine types, the section contains Thumb code.Reserved for future use with other machine types.
157 #define IMAGE_SCN_MEM_LOCKED 0x00040000 //!< Reserved for future use.
158 #define IMAGE_SCN_MEM_PRELOAD 0x00080000 //!< Reserved for future use.
159 #define IMAGE_SCN_ALIGN_1BYTES 0x00100000 //!< Align data on a 1 - byte boundary.Valid only for object files.
160 #define IMAGE_SCN_ALIGN_2BYTES 0x00200000 //!< Align data on a 2 - byte boundary.Valid only for object files.
161 #define IMAGE_SCN_ALIGN_4BYTES 0x00300000 //!< Align data on a 4 - byte boundary.Valid only for object files.
162 #define IMAGE_SCN_ALIGN_8BYTES 0x00400000 //!< Align data on an 8 - byte boundary.Valid only for object files.
163 #define IMAGE_SCN_ALIGN_16BYTES 0x00500000 //!< Align data on a 16 - byte boundary.Valid only for object files.
164 #define IMAGE_SCN_ALIGN_32BYTES 0x00600000 //!< Align data on a 32 - byte boundary.Valid only for object files.
165 #define IMAGE_SCN_ALIGN_64BYTES 0x00700000 //!< Align data on a 64 - byte boundary.Valid only for object files.
166 #define IMAGE_SCN_ALIGN_128BYTES 0x00800000 //!< Align data on a 128 - byte boundary.Valid only for object files.
167 #define IMAGE_SCN_ALIGN_256BYTES 0x00900000 //!< Align data on a 256 - byte boundary.Valid only for object files.
168 #define IMAGE_SCN_ALIGN_512BYTES 0x00A00000 //!< Align data on a 512 - byte boundary.Valid only for object files.
169 #define IMAGE_SCN_ALIGN_1024BYTES 0x00B00000 //!< Align data on a 1024 - byte boundary.Valid only for object files.
170 #define IMAGE_SCN_ALIGN_2048BYTES 0x00C00000 //!< Align data on a 2048 - byte boundary.Valid only for object files.
171 #define IMAGE_SCN_ALIGN_4096BYTES 0x00D00000 //!< Align data on a 4096 - byte boundary.Valid only for object files.
172 #define IMAGE_SCN_ALIGN_8192BYTES 0x00E00000 //!< Align data on an 8192 - byte boundary.Valid only for object files.
173 #define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000 //!< The section contains extended relocations.
174 #define IMAGE_SCN_MEM_DISCARDABLE 0x02000000 //!< The section can be discarded as needed.
175 #define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 //!< The section cannot be cached.
176 #define IMAGE_SCN_MEM_NOT_PAGED 0x08000000 //!< The section is not pageable.
177 #define IMAGE_SCN_MEM_SHARED 0x10000000 //!< The section can be shared in memory.
178 #define IMAGE_SCN_MEM_EXECUTE 0x20000000 //!< The section can be executed as code.
179 #define IMAGE_SCN_MEM_READ 0x40000000 //!< The section can be read.
180 #define IMAGE_SCN_MEM_WRITE 0x80000000 //!< The section can be written to.
181 
182 //! @}
183 
184 //! @name Portable Executable directories index
185 //! @{
186 #define DIRECTORY_EXPORT_TABLE 0
187 #define DIRECTORY_IMPORT_TABLE 1
188 #define DIRECTORY_RESOURCE_TABLE 2
189 #define DIRECTORY_EXCEPTION_TABLE 3
190 #define DIRECTORY_CERTIFICATE_TABLE 4
191 #define DIRECTORY_BASE_RELOCATION_TABLE 5
192 #define DIRECTORY_DEBUG 6
193 #define DIRECTORY_ARCHITECTURE 7
194 #define DIRECTORY_GLOBAL_PTR 8
195 #define DIRECTORY_TLS_TABLE 9
196 #define DIRECTORY_LOAD_CONFIG_TABLE 10
197 #define DIRECTORY_BOUND_IMPORT 11
198 #define DIRECTORY_IAT 12
199 #define DIRECTORY_DELAY_IMPORT_DESCRIPTOR 13
200 #define DIRECTORY_COMPLUS_RUNTIME_HEADER 14
201 #define DIRECTORY_RESERVED 15
202 
203 //! @}
204 
205 //! @name COFF Relocations Type Indicators - Intel 386
206 //! @{
207 #define IMAGE_REL_I386_ABSOLUTE 0x0000 //!< This relocation is ignored.
208 #define IMAGE_REL_I386_DIR16 0x0001 //!< Not supported.
209 #define IMAGE_REL_I386_REL16 0x0002 //!< Not supported.
210 #define IMAGE_REL_I386_DIR32 0x0006 //!< The target’s 32-bit virtual address.
211 #define IMAGE_REL_I386_DIR32NB 0x0007 //!< The target’s 32-bit relative virtual address.
212 #define IMAGE_REL_I386_SEG12 0x0009 //!< Not supported.
213 #define IMAGE_REL_I386_SECTION 0x000A //!< The 16-bit-section index of the section containing the target. This is used to support debugging information.
214 #define IMAGE_REL_I386_SECREL 0x000B //!< The 32-bit offset of the target from the beginning of its section. This is used to support debugging information as well as static thread local storage.
215 #define IMAGE_REL_I386_REL32 0x0014 //!< The 32-bit relative displacement to the target. This supports the x86 relative branch and call instructions.
216 
217 //! @}
218 
219 //! @name COFF Relocations Type Indicators - MIPS Processors
220 //! @{
221 #define IMAGE_REL_MIPS_ABSOLUTE 0x0000 //!< This relocation is ignored.
222 #define IMAGE_REL_MIPS_REFHALF 0x0001 //!< The high 16 bits of the target’s 32-bit virtual address.
223 #define IMAGE_REL_MIPS_REFWORD 0x0002 //!< The target’s 32-bit virtual address.
224 #define IMAGE_REL_MIPS_JMPADDR 0x0003 //!< The low 26 bits of the target’s virtual address. This supports the MIPS J and JAL instructions.
225 #define IMAGE_REL_MIPS_REFHI 0x0004 //!< The high 16 bits of the target’s 32-bit virtual address. Used for the first instruction in a two-instruction sequence that loads a full address. This relocation must be immediately followed by a PAIR relocations whose SymbolTableIndex contains a signed 16-bit displacement which is added to the upper 16 bits taken from the location being relocated.
226 #define IMAGE_REL_MIPS_REFLO 0x0005 //!< The low 16 bits of the target’s virtual address.
227 #define IMAGE_REL_MIPS_GPREL 0x0006 //!< 16-bit signed displacement of the target relative to the Global Pointer (GP) register.
228 #define IMAGE_REL_MIPS_LITERAL 0x0007 //!< Same as IMAGE_REL_MIPS_GPREL.
229 #define IMAGE_REL_MIPS_SECTION 0x000A //!< The 16-bit section index of the section containing the target. This is used to support debugging information.
230 #define IMAGE_REL_MIPS_SECREL 0x000B //!< The 32-bit offset of the target from the beginning of its section. This is used to support debugging information as well as static thread local storage.
231 #define IMAGE_REL_MIPS_SECRELLO 0x000C //!< The low 16 bits of the 32-bit offset of the target from the beginning of its section.
232 #define IMAGE_REL_MIPS_SECRELHI 0x000D //!< The high 16 bits of the 32-bit offset of the target from the beginning of its section. A AIR relocation must immediately follow this on. The SymbolTableIndex of the PAIR relocation contains a signed 16-bit displacement, which is added to the upper 16 bits taken from the location being relocated.
233 #define IMAGE_REL_MIPS_JMPADDR16 0x0010 //!< The low 26 bits of the target’s virtual address. This supports the MIPS16 JAL instruction.
234 #define IMAGE_REL_MIPS_REFWORDNB 0x0022 //!< The target’s 32-bit relative virtual address.
235 #define IMAGE_REL_MIPS_PAIR 0x0025 //!< This relocation is only valid when it immediately follows a REFHI or SECRELHI relocation. Its SymbolTableIndex contains a displacement and not an index into the symbol table.
236 
237 //! @}
238 
239 //! @name COFF Relocations Type Indicators - Alpha Processors
240 //! @{
241 #define IMAGE_REL_ALPHA_ABSOLUTE 0x0000 //!< This relocation is ignored.
242 #define IMAGE_REL_ALPHA_REFLONG 0x0001 //!< The target’s 32-bit virtual address. This fixup is illegal in a PE32+ image unless the image has been sandboxed by clearing the IMAGE_FILE_LARGE_ADDRESS_AWARE bit in the File Header.
243 #define IMAGE_REL_ALPHA_REFQUAD 0x0002 //!< The target’s 64-bit virtual address.
244 #define IMAGE_REL_ALPHA_GPREL32 0x0003 //!< 32-bit signed displacement of the target relative to the Global Pointer (GP) register.
245 #define IMAGE_REL_ALPHA_LITERAL 0x0004 //!< 16-bit signed displacement of the target relative to the Global Pointer (GP) register.
246 #define IMAGE_REL_ALPHA_LITUSE 0x0005 //!< Reserved for future use.
247 #define IMAGE_REL_ALPHA_GPDISP 0x0006 //!< Reserved for future use.
248 #define IMAGE_REL_ALPHA_BRADDR 0x0007 //!< The 21-bit relative displacement to the target. This supports the Alpha relative branch instructions.
249 #define IMAGE_REL_ALPHA_HINT 0x0008 //!< 14-bit hints to the processor for the target of an Alpha jump instruction.
250 #define IMAGE_REL_ALPHA_INLINE_REFLONG 0x0009 //!< The target’s 32-bit virtual address split into high and low 16-bit parts. Either an ABSOLUTE or MATCH relocation must immediately follow this relocation. The high 16 bits of the target address are stored in the location identified by the INLINE_REFLONG relocation. The low 16 bits are stored four bytes later if the following relocation is of type ABSOLUTE or at a signed displacement given in the SymbolTableIndex if the following relocation is of type MATCH.
251 #define IMAGE_REL_ALPHA_REFHI 0x000A //!< The high 16 bits of the target’s 32-bit virtual address. Used for the first instruction in a two-instruction sequence that loads a full address. This relocation must be immediately followed by a PAIR relocations whose SymbolTableIndex contains a signed 16-bit displacement which is added to the upper 16 bits taken from the location being relocated.
252 #define IMAGE_REL_ALPHA_REFLO 0x000B //!< The low 16 bits of the target’s virtual address.
253 #define IMAGE_REL_ALPHA_PAIR 0x000C //!< This relocation is only valid when it immediately follows a REFHI , REFQ3, REFQ2, or SECRELHI relocation. Its SymbolTableIndex contains a displacement and not an index into the symbol table.
254 #define IMAGE_REL_ALPHA_MATCH 0x000D //!< This relocation is only valid when it immediately follows INLINE_REFLONG relocation. Its SymbolTableIndex contains the displacement in bytes of the location for the matching low address and not an index into the symbol table.
255 #define IMAGE_REL_ALPHA_SECTION 0x000E //!< The 16-bit section index of the section containing the target. This is used to support debugging information.
256 #define IMAGE_REL_ALPHA_SECREL 0x000F //!< The 32-bit offset of the target from the beginning of its section. This is used to support debugging information as well as static thread local storage.
257 #define IMAGE_REL_ALPHA_REFLONGNB 0x0010 //!< The target’s 32-bit relative virtual address. IMAGE_REL_ALPHA_SECRELLO 0x0011 The low 16 bits of the 32-bit offset of the target from the beginning of its section.
258 #define IMAGE_REL_ALPHA_SECRELHI 0x0012 //!< The high 16 bits of the 32-bit offset of the target from the beginning of its section. A PAIR relocation must immediately follow this on. The SymbolTableIndex of the PAIR relocation contains a signed 16-bit displacement which is added to the upper 16 bits taken from the location being relocated.
259 #define IMAGE_REL_ALPHA_REFQ3 0x0013 //!< The low 16 bits of the high 32 bits of the target’s 64-bit virtual address. This relocation must be immediately followed by a PAIR relocations whose SymbolTableIndex contains a signed 32-bit displacement which is added to the 16 bits taken from the location being relocated. The 16 bits in the relocated location are shifted left by 32 before this addition.
260 #define IMAGE_REL_ALPHA_REFQ2 0x0014 //!< The high 16 bits of the low 32 bits of the target’s 64-bit virtual address. This relocation must be immediately followed by a PAIR relocations whose SymbolTableIndex contains a signed 16-bit displacement which is added to the upper 16 bits taken from the location being relocated.
261 #define IMAGE_REL_ALPHA_REFQ1 0x0015 //!< The low 16 bits of the target’s 64-bit virtual address.
262 #define IMAGE_REL_ALPHA_GPRELLO 0x0016 //!< The low 16 bits of the 32-bit signed displacement of the target relative to the Global Pointer (GP) register.
263 #define IMAGE_REL_ALPHA_GPRELHI 0x0017 //!< The high 16 bits of the 32-bit signed displacement of the target relative to the Global Pointer (GP) register.
264 
265 //! @}
266 
267 //! @name COFF Relocations Type Indicators - IBM PowerPC Processors
268 //! @{
269 #define IMAGE_REL_PPC_ABSOLUTE 0x0000 //!< This relocation is ignored.
270 #define IMAGE_REL_PPC_ADDR64 0x0001 //!< The target’s 64-bit virtual address.
271 #define IMAGE_REL_PPC_ADDR32 0x0002 //!< The target’s 32-bit virtual address.
272 #define IMAGE_REL_PPC_ADDR24 0x0003 //!< The low 24 bits of the target’s virtual address. This is only valid when the target symbol is absolute and can be sign extended to its original value.
273 #define IMAGE_REL_PPC_ADDR16 0x0004 //!< The low 16 bits of the target’s virtual address.
274 #define IMAGE_REL_PPC_ADDR14 0x0005 //!< The low 14 bits of the target’s virtual address. This is only valid when the target symbol is absolute and can be sign extended to its original value.
275 #define IMAGE_REL_PPC_REL24 0x0006 //!< A 24-bit PC-relative offset to the symbol’s location.
276 #define IMAGE_REL_PPC_REL14 0x0007 //!< A 14-bit PC-relative offset to the symbol’s location.
277 #define IMAGE_REL_PPC_ADDR32NB 0x000A //!< The target’s 32-bit relative virtual address.
278 #define IMAGE_REL_PPC_SECREL 0x000B //!< The 32-bit offset of the target from the beginning of its section. This is used to support debugging information as well as static thread local storage.
279 #define IMAGE_REL_PPC_SECTION 0x000C //!< The 16-bit section index of the section containing the target. This is used to support debugging information.
280 #define IMAGE_REL_PPC_SECREL16 0x000F //!< The 16-bit offset of the target from the beginning of its section. This is used to support debugging information as well as static thread local storage.
281 #define IMAGE_REL_PPC_REFHI 0x0010 //!< The high 16 bits of the target’s 32-bit virtual address. Used for the first instruction in a two-instruction sequence that loads a full address. This relocation must be immediately followed by a PAIR relocations whose SymbolTableIndex contains a signed 16-bit displacement which is added to the upper 16 bits taken from the location being relocated.
282 #define IMAGE_REL_PPC_REFLO 0x0011 //!< The low 16 bits of the target’s virtual address.
283 #define IMAGE_REL_PPC_PAIR 0x0012 //!< This relocation is only valid when it immediately follows a REFHI or SECRELHI relocation. Its SymbolTableIndex contains a displacement and not an index into the symbol table.
284 #define IMAGE_REL_PPC_SECRELLO 0x0013 //!< The low 16 bits of the 32-bit offset of the target from the beginning of its section.
285 #define IMAGE_REL_PPC_SECRELHI 0x0014 //!< The high 16 bits of the 32-bit offset of the target from the beginning of its section. A PAIR relocation must immediately follow this on. The SymbolTableIndex of the PAIR relocation contains a signed 16-bit displacement which is added to the upper 16 bits taken from the location being relocated.
286 #define IMAGE_REL_PPC_GPREL 0x0015 //!< 16-bit signed displacement of the target relative to the Global Pointer (GP) register.
287 
288 //! @}
289 
290 //! @name COFF Relocations Type Indicators - Hitachi SuperH Processors
291 //! @{
292 #define IMAGE_REL_SH3_ABSOLUTE 0x0000 //!< This relocation is ignored.
293 #define IMAGE_REL_SH3_DIRECT16 0x0001 //!< Reference to the 16-bit location that contains the virtual address of the target symbol.
294 #define IMAGE_REL_SH3_DIRECT32 0x0002 //!< The target’s 32-bit virtual address.
295 #define IMAGE_REL_SH3_DIRECT8 0x0003 //!< Reference to the 8-bit location that contains the virtual address of the target symbol.
296 #define IMAGE_REL_SH3_DIRECT8_WORD 0x0004 //!< Reference to the 8-bit instruction that contains the effective 16-bit virtual address of the target symbol.
297 #define IMAGE_REL_SH3_DIRECT8_LONG 0x0005 //!< Reference to the 8-bit instruction that contains the effective 32-bit virtual address of the target symbol.
298 #define IMAGE_REL_SH3_DIRECT4 0x0006 //!< Reference to the 8-bit location whose low 4 bits contain the virtual address of the target symbol.
299 #define IMAGE_REL_SH3_DIRECT4_WORD 0x0007 //!< Reference to the 8-bit instruction whose low 4 bits contain the effective 16-bit virtual address of the target symbol.
300 #define IMAGE_REL_SH3_DIRECT4_LONG 0x0008 //!< Reference to the 8-bit instruction whose low 4 bits contain the effective 32-bit virtual address of the target symbol.
301 #define IMAGE_REL_SH3_PCREL8_WORD 0x0009 //!< Reference to the 8-bit instruction which contains the effective 16-bit relative offset of the target symbol.
302 #define IMAGE_REL_SH3_PCREL8_LONG 0x000A //!< Reference to the 8-bit instruction which contains the effective 32-bit relative offset of the target symbol.
303 #define IMAGE_REL_SH3_PCREL12_WORD 0x000B //!< Reference to the 16-bit instruction whose low 12 bits contain the effective 16-bit relative offset of the target symbol.
304 #define IMAGE_REL_SH3_STARTOF_SECTION 0x000C //!< Reference to a 32-bit location that is the virtual address of the symbol’s section.
305 #define IMAGE_REL_SH3_SIZEOF_SECTION 0x000D //!< Reference to the 32-bit location that is the size of the symbol’s section.
306 #define IMAGE_REL_SH3_SECTION 0x000E //!< The 16-bit section index of the section containing the target. This is used to support debugging information.
307 #define IMAGE_REL_SH3_SECREL 0x000F //!< The 32-bit offset of the target from the beginning of its section. This is used to support debugging information as well as static thread local storage.
308 #define IMAGE_REL_SH3_DIRECT32_NB 0x0010 //!< The target’s 32-bit relative virtual address.
309 
310 //! @}
311 
312 //! @name COFF Relocations Type Indicators - ARM Processors
313 //! @{
314 #define IMAGE_REL_ARM_ABSOLUTE 0x0000 //!< This relocation is ignored.
315 #define IMAGE_REL_ARM_ADDR32 0x0001 //!< The target’s 32-bit virtual address.
316 #define IMAGE_REL_ARM_ADDR32NB 0x0002 //!< The target’s 32-bit relative virtual address.
317 #define IMAGE_REL_ARM_BRANCH24 0x0003 //!< The 24-bit relative displacement to the target.
318 #define IMAGE_REL_ARM_BRANCH11 0x0004 //!< Reference to a subroutine call, consisting of two 16-bit instructions with 11-bit offsets.
319 #define IMAGE_REL_ARM_SECTION 0x000E //!< The 16-bit section index of the section containing the target. This is used to support debugging information.
320 #define IMAGE_REL_ARM_SECREL 0x000F //!< The 32-bit offset of the target from the beginning of its section. This is used to support debugging information as well as static thread local storage.
321 
322 //! @}
323 
324 //! @name COFF Symbol Table, Section Number Values (symbol.section_number)
325 //! @{
326 #define IMAGE_SYM_UNDEFINED 0 //!< Symbol record is not yet assigned a section. If the value is 0 this indicates a references to an external symbol defined elsewhere. If the value is non-zero this is a common symbol with a size specified by the value.
327 #define IMAGE_SYM_ABSOLUTE -1 //!< The symbol has an absolute (non-relocatable) value and is not an address.
328 #define IMAGE_SYM_DEBUG -2 //!< The symbol provides general type or debugging information but does not correspond to a section. Microsoft tools use this setting along with .file records (storage class FILE).
329 
330 //! @}
331 
332 //! @name COFF Symbol Table, Type Representation (symbol.type)
333 //! @{
334 #define IMAGE_SYM_TYPE_NULL 0 //!< No type information or unknown base type. Microsoft tools use this setting.
335 #define IMAGE_SYM_TYPE_VOID 1 //!< No valid type; used with void pointers and functions.
336 #define IMAGE_SYM_TYPE_CHAR 2 //!< Character (signed byte).
337 #define IMAGE_SYM_TYPE_SHORT 3 //!< Two-byte signed integer.
338 #define IMAGE_SYM_TYPE_INT 4 //!< Natural integer type (normally four bytes in Windows NT).
339 #define IMAGE_SYM_TYPE_LONG 5 //!< Four-byte signed integer.
340 #define IMAGE_SYM_TYPE_FLOAT 6 //!< Four-byte floating-point number.
341 #define IMAGE_SYM_TYPE_DOUBLE 7 //!< Eight-byte floating-point number.
342 #define IMAGE_SYM_TYPE_STRUCT 8 //!< Structure.
343 #define IMAGE_SYM_TYPE_UNION 9 //!< Union.
344 #define IMAGE_SYM_TYPE_ENUM 10 //!< Enumerated type.
345 #define IMAGE_SYM_TYPE_MOE 11 //!< Member of enumeration (a specific value).
346 #define IMAGE_SYM_TYPE_BYTE 12 //!< Byte; unsigned one-byte integer.
347 #define IMAGE_SYM_TYPE_WORD 13 //!< Word; unsigned two-byte integer.
348 #define IMAGE_SYM_TYPE_UINT 14 //!< Unsigned integer of natural size (normally, four bytes).
349 #define IMAGE_SYM_TYPE_DWORD 15 //!< Unsigned four-byte integer.
350 
351 //! @}
352 
353 //! @name Microsoft tools use the type field only to indicate whether or not the symbol is a function, so that the only two resulting values are 0x0 and 0x20 for the Type field.
354 //! @{
355 #define IMAGE_SYM_TYPE_NOT_FUNCTION 0
356 #define IMAGE_SYM_TYPE_FUNCTION 0x20
357 
358 //! @}
359 
360 //! @name Complex types
361 //! @{
362 #define IMAGE_SYM_DTYPE_NULL 0 //!< No derived type; the symbol is a simple scalar variable.
363 #define IMAGE_SYM_DTYPE_POINTER 1 //!< Pointer to base type.
364 #define IMAGE_SYM_DTYPE_FUNCTION 2 //!< Function returning base type.
365 #define IMAGE_SYM_DTYPE_ARRAY 3 //!< Array of base type.
366 
367 //! @}
368 
369 //! @name COFF Symbol Table, Storage Class (symbol.storage_class)
370 //! @{
371 #define IMAGE_SYM_CLASS_END_OF_FUNCTION -1 //!< Special symbol representing end of function, for debugging purposes.
372 #define IMAGE_SYM_CLASS_NULL 0 //!< No storage class assigned.
373 #define IMAGE_SYM_CLASS_AUTOMATIC 1 //!< Automatic (stack) variable. The Value field specifies stack frame offset.
374 #define IMAGE_SYM_CLASS_EXTERNAL 2 //!< Used by Microsoft tools for external symbols. The Value field indicates the size if the section number is IMAGE_SYM_UNDEFINED (0). If the section number is not 0, then the Value field specifies the offset within the section.
375 #define IMAGE_SYM_CLASS_STATIC 3 //!< The Value field specifies the offset of the symbol within the section. If the Value is 0, then the symbol represents a section name.
376 #define IMAGE_SYM_CLASS_REGISTER 4 //!< Register variable. The Value field specifies register number.
377 #define IMAGE_SYM_CLASS_EXTERNAL_DEF 5 //!< Symbol is defined externally.
378 #define IMAGE_SYM_CLASS_LABEL 6 //!< Code label defined within the module. The Value field specifies the offset of the symbol within the section.
379 #define IMAGE_SYM_CLASS_UNDEFINED_LABEL 7 //!< Reference to a code label not defined. IMAGE_SYM_CLASS_MEMBER_OF_STRUCT 8 Structure member. The Value field specifies nth member.
380 #define IMAGE_SYM_CLASS_ARGUMENT 9 //!< Formal argument (parameter)of a function. The Value field specifies nth argument.
381 #define IMAGE_SYM_CLASS_STRUCT_TAG 10 //!< Structure tag-name entry.
382 #define IMAGE_SYM_CLASS_MEMBER_OF_UNION 11 //!< Union member. The Value field specifies nth member.
383 #define IMAGE_SYM_CLASS_UNION_TAG 12 //!< Union tag-name entry.
384 #define IMAGE_SYM_CLASS_TYPE_DEFINITION 13 //!< Typedef entry.
385 #define IMAGE_SYM_CLASS_UNDEFINED_STATIC 14 //!< Static data declaration.
386 #define IMAGE_SYM_CLASS_ENUM_TAG 15 //!< Enumerated type tagname entry.
387 #define IMAGE_SYM_CLASS_MEMBER_OF_ENUM 16 //!< Member of enumeration. Value specifies nth member.
388 #define IMAGE_SYM_CLASS_REGISTER_PARAM 17 //!< Register parameter.
389 #define IMAGE_SYM_CLASS_BIT_FIELD 18 //!< Bit-field reference. Value specifies nth bit in the bit field.
390 #define IMAGE_SYM_CLASS_BLOCK 100 //!< A .bb (beginning of block) or .eb (end of block) record. Value is the relocatable address of the code location.
391 #define IMAGE_SYM_CLASS_FUNCTION 101 //!< Used by Microsoft tools for symbol records that define the extent of a function: begin function (named .bf), end function (.ef), and lines in function (.lf). For .lf records, Value gives the number of source lines in the function. For .ef records, Value gives the size of function code.
392 #define IMAGE_SYM_CLASS_END_OF_STRUCT 102 //!< End of structure entry.
393 #define IMAGE_SYM_CLASS_FILE 103 //!< Used by Microsoft tools, as well as traditional COFF format, for the source-file symbol record. The symbol is followed by auxiliary records that name the file.
394 #define IMAGE_SYM_CLASS_SECTION 104 //!< Definition of a section (Microsoft tools use STATIC storage class instead).
395 #define IMAGE_SYM_CLASS_WEAK_EXTERNAL 105 //!< Weak external
396 
397 //! @}
398 
399 //! @name COMDAT Sections (auxiliary_symbol_record_5.selection)
400 //! @{
401 #define IMAGE_COMDAT_SELECT_NODUPLICATES 1
402 #define IMAGE_COMDAT_SELECT_ANY 2
403 #define IMAGE_COMDAT_SELECT_SAME_SIZE 3
404 #define IMAGE_COMDAT_SELECT_EXACT_MATCH 4
405 #define IMAGE_COMDAT_SELECT_ASSOCIATIVE 5
406 #define IMAGE_COMDAT_SELECT_LARGEST 6
407 
408 //! @}
409 
410 // See Texas Instruments documentation spraao8
411 
412 //! @name Texas Instruments File Header Flags
413 //! @{
414 #define F_RELFLG 0x0001
415 #define F_EXEC 0x0002
416 #define F_LNNO 0x0004
417 #define F_LSYMS 0x0008
418 #define F_LITTLE 0x0100
419 #define F_BIG 0x0200
420 #define F_SYMMERGE 0x1000
421 
422 //! @}
423 
424 //! @name Texas Instruments Section Header Flags
425 //! @{
426 #define STYP_REG 0x00000000
427 #define STYP_DSECT 0x00000001
428 #define STYP_NOLOAD 0x00000002
429 #define STYP_GROUP 0x00000004
430 #define STYP_PAD 0x00000008
431 #define STYP_COPY 0x00000010
432 #define STYP_TEXT 0x00000020
433 #define STYP_DATA 0x00000040
434 #define STYP_BSS 0x00000080
435 #define STYP_BLOCK 0x00001000
436 #define STYP_PASS 0x00002000
437 #define STYP_CLINK 0x00004000
438 #define STYP_VECTOR 0x00008000
439 #define STYP_PADDED 0x00010000
440 #define STYP_ALIGN_2 0x00000100
441 #define STYP_ALIGN_4 0x00000200
442 #define STYP_ALIGN_8 0x00000300
443 #define STYP_ALIGN_16 0x00000400
444 #define STYP_ALIGN_32 0x00000500
445 #define STYP_ALIGN_64 0x00000600
446 #define STYP_ALIGN_128 0x00000700
447 #define STYP_ALIGN_256 0x00000800
448 #define STYP_ALIGN_512 0x00000900
449 #define STYP_ALIGN_1024 0x00000A00
450 #define STYP_ALIGN_2048 0x00000B00
451 #define STYP_ALIGN_4096 0x00000C00
452 #define STYP_ALIGN_8192 0x00000D00
453 #define STYP_ALIGN_16384 0x00000E00
454 #define STYP_ALIGN_32768 0x00000F00
455 
456 //! @}
457 
458 //! @name Texas Instruments target ID
459 //! @{
460 #define TMS470 0x0097
461 #define TMS320C5400 0x0098
462 #define TMS320C6000 0x0099
463 #define TMS320C5500 0x009C
464 #define TMS320C2800 0x009D
465 #define MSP430 0x00A0
466 #define TMS320C5500plus 0x00A1
467 
468 //! @}
469 
470 //! @name Texas Instruments Generic Relocation Types (rel_entry.type)
471 //! @{
472 #define RE_ADD 0x4000 //!< Addition (+)
473 #define RE_SUB 0x4001 //!< Subtraction (-)
474 #define RE_NEG 0x4002 //!< Negate (-)
475 #define RE_MPY 0x4003 //!< Multiplication (*)
476 #define RE_DIV 0x4004 //!< Division (/)
477 #define RE_MOD 0x4005 //!< Modulus (%)
478 #define RE_SR 0x4006 //!< Logical shift right (unsigned >>)
479 #define RE_ASR 0x4007 //!< Arithmetic shift right (signed >>)
480 #define RE_SL 0x4008 //!< Shift left (<<)
481 #define RE_AND 0x4009 //!< And (&)
482 #define RE_OR 0x400A //!< Or (|)
483 #define RE_XOR 0x400B //!< Exclusive Or (^)
484 #define RE_NOTB 0x400C //!< Not (~)
485 #define RE_ULDFLD 0x400D //!< Unsigned relocation field load
486 #define RE_SLDFLD 0x400E //!< Signed relocation field load
487 #define RE_USTFLD 0x400F //!< Unsigned relocation field store
488 #define RE_SSTFLD 0x4010 //!< Signed relocation field store
489 #define RE_PUSH 0x4011 //!< Push symbol on the stack
490 #define RE_PUSHSK 0x4012 //!< Push signed constant on the stack
491 #define RE_PUSHUK 0x4013 //!< Push unsigned constant on the stack
492 #define RE_PUSHPC 0x4014 //!< Push current section PC on the stack
493 #define RE_DUP 0x4015 //!< Duplicate top-of-stack and 0xpus // a copy
494 #define RE_XSTFLD 0x4016 //!< Relocation field store, signedness is irrelevant
495 #define RE_PUSHSV 0xC011 //!< Push symbol: SEGVALUE flag is set
496 
497 //! @}
498 
499 //! @name Texas Instruments C6000 Relocation Types (rel_entry.type)
500 //! @{
501 #define R_C60_ABS 0x0000 //!< No relocation
502 #define R_C60_RELBYTE 0x000F //!< 8-bit direct reference to symbol's address
503 #define R_C60_RELWORD 0x0010 //!< 16-bit direct reference to symbol's address
504 #define R_C60_RELLONG 0x0011 //!< 32-bit direct reference to symbol's address
505 #define R_C60_BASE 0x0050 //!< Data page pointer-based offset
506 #define R_C60_DIR15 0x0051 //!< Load or store long displacement
507 #define R_C60_PCR21 0x0052 //!< 21-bit packet, PC relative
508 #define R_C60_PCR10 0x0053 //!< 10-bit Packet PC Relative (BDEC, BPOS)
509 #define R_C60_LO16 0x0054 //!< MVK instruction low half register
510 #define R_C60_HI16 0x0055 //!< MVKH or MVKLH 0xhig // half register
511 #define R_C60_SECT 0x0056 //!< Section-based offset
512 #define R_C60_S16 0x0057 //!< Signed 16-bit offset for MVK
513 #define R_C60_PCR7 0x0070 //!< 7-bit Packet PC Relative (ADDKPC)
514 #define R_C60_PCR12 0x0071 //!< 12-bit Packet PC Relative (BNOP)
515 
516 //! @}
517 
518 //! @name Texas Instruments C2800 Relocation Types (rel_entry.type)
519 //! @{
520 #define R_C28_ABS 0x0000 //!< No relocation
521 #define R_C28_RELBYTE 0x000F //!< 8-bit direct reference to symbol's address
522 #define R_C28_RELWORD 0x0010 //!< 16-bit direct reference to symbol's address
523 #define R_C28_RELLONG 0x0011 //!< 32-bit direct reference to symbol's address
524 #define R_C28_PARTLS7 0x0028 //!< 7-bit offset of a 22-bit address
525 #define R_C28_PARTLS6 0x005D //!< 6-bit offset of a 22-bit address
526 #define R_C28_PARTMID10 0x005E //!< Middle 10 bits of a 22-bit address
527 #define R_C28_REL22 0x005F //!< 22-bit direct reference to a symbol's address
528 #define R_C28_PARTMS6 0x0060 //!< Upper 6 bits of an 22-bit address
529 #define R_C28_PARTMS16 0x0061 //!< Upper 16 bits of an 22-bit address
530 #define R_C28_PCR16 0x0062 //!< PC relative 16-bit address
531 #define R_C28_PCR8 0x0063 //!< PC relative 8-bit address
532 #define R_C28_PTR 0x0064 //!< 22-bit pointer
533 #define R_C28_HI16 0x0065 //!< High 16 bits of address data
534 #define R_C28_LOPTR 0x0066 //!< Pointer to low 64K
535 #define R_C28_NWORD 0x0067 //!< 16-bit negated relocation
536 #define R_C28_NBYTE 0x0068 //!< 8-bit negated relocation
537 #define R_C28_HIBYTE 0x0069 //!< High 8 bits of a 16-bit data
538 #define R_C28_RELS13 0x006A //!< Signed 13-bit value relocated as a 16-bit value
539 
540 //! @}
541 
542 //! @name Texas Instruments C5400 Relocation Types (rel_entry.type)
543 //! @{
544 #define R_C54_ABS 0x0000 //!< No relocation
545 #define R_C54_REL24 0x0005 //!< 24-bit reference to symbol's address
546 #define R_C54_RELBYTE 0x0017 //!< 8-bit direct reference to symbol's address
547 #define R_C54_RELWORD 0x0020 //!< 16-bit direct reference to symbol's address
548 #define R_C54_RELLONG 0x0021 //!< 32-bit direct reference to symbol's address
549 #define R_C54_PARTLS7 0x0028 //!< 7 LSBs of an address
550 #define R_C54_PARTMS9 0x0029 //!< 9 MSBs of an address
551 #define R_C54_REL13 0x002A //!< 13-bit direct reference to symbol's address
552 
553 //! @}
554 
555 //! @name Texas Instruments C5500 Relocation Types (rel_entry.type)
556 //! @{
557 #define R_C55_ABS 0x0000 //!< No relocation
558 #define R_C55_REL24 0x0005 //!< 24-bit direct reference to symbol's address
559 #define R_C55_RELBYTE 0x0017 //!< 8-bit direct reference to symbol's address
560 #define R_C55_RELWORD 0x0020 //!< 16-bit direct reference to symbol's address
561 #define R_C55_RELLONG 0x0021 //!< 32-bit direct reference to symbol's address
562 #define R_C55_LD3_DMA 0x0170 //!< 7 MSBs of a byte, unsigned; used in DMA address
563 #define R_C55_LD3_MDP 0x0172 //!< 7 bits spanning 2 bytes, unsigned; used as MDP register value
564 #define R_C55_LD3_PDP 0x0173 //!< 9 bits spanning 2 bytes, unsigned; used as PDP register value
565 #define R_C55_LD3_REL23 0x0174 //!< 23-bit unsigned value in 24-bit field
566 #define R_C55_LD3_k8 0x0210 //!< 8-bit unsigned direct reference
567 #define R_C55_LD3_k16 0x0211 //!< 16-bit unsigned direct reference
568 #define R_C55_LD3_K8 0x0212 //!< 8-bit signed direct reference
569 #define R_C55_LD3_K16 0x0213 //!< 16-bit signed direct reference
570 #define R_C55_LD3_I8 0x0214 //!< 8-bit unsigned PC-relative reference
571 #define R_C55_LD3_I16 0x0215 //!< 16-bit unsigned PC-relative reference
572 #define R_C55_LD3_L8 0x0216 //!< 8-bit signed PC-relative reference
573 #define R_C55_LD3_L16 0x0217 //!< 16-bit signed PC-relative reference
574 #define R_C55_LD3_k4 0x0220 //!< Unsigned 4-bit shift immediate
575 #define R_C55_LD3_k5 0x0221 //!< Unsigned 5-bit shift immediate
576 #define R_C55_LD3_K5 0x0222 //!< Signed 5-bit shift immediate
577 #define R_C55_LD3_k6 0x0223 //!< Unsigned 6-bit shift immediate
578 #define R_C55_LD3_k12 0x0224 //!< Unigned 12-bit shift immediate
579 
580 //! @}
581 
582 //! @name Texas Instruments MSP430 Relocation Types (rel_entry.type)
583 //! @{
584 #define R_MSP430_RELLONG 0x0011 //!< 32-bit direct reference to symbol's address
585 #define R_MSP430_PCR23H 0x0016 //!< 23-bit PC-relative reference to a symbol's address, in halfwords (divided by 2)
586 #define R_MSP430_PCR24W 0x0017 //!< 24-bit PC-relative reference to a symbol's address, in words (divided by 4)
587 
588 //! @}
589 
590 //! @name Texas Instruments Symbol Storage Classes
591 //! @{
592 #define C_NULL 0 //!< No storage class
593 #define C_AUTO 1 //!< Reserved
594 #define C_EXT 2 //!< External definition
595 #define C_STAT 3 //!< Static
596 #define C_REG 4 //!< Reserved
597 #define C_EXTREF 5 //!< External reference
598 #define C_LABEL 6 //!< Label
599 #define C_ULABEL 7 //!< Undefined label
600 #define C_MOS 8 //!< Reserved
601 #define C_ARG 9 //!< Reserved
602 #define C_STRTAG 10 //!< Reserved
603 #define C_MOU 11 //!< Reserved
604 #define C_UNTAG 12 //!< Reserved
605 #define C_TPDEF 13 //!< Reserved
606 #define C_USTATIC 14 //!< Undefined static
607 #define C_ENTAG 15 //!< Reserved
608 #define C_MOE 16 //!< Reserved
609 #define C_REGPARM 17 //!< Reserved
610 #define C_FIELD 18 //!< Reserved
611 #define C_UEXT 19 //!< Tentative external definition
612 #define C_STATLAB 20 //!< Static load time label
613 #define C_EXTLAB 21 //!< External load time label
614 #define C_VARARG 27 //!< Last declared parameter of a function with a variable number of arguments
615 #define C_BLOCK 100 //!< Reserved
616 #define C_FCN 101 //!< Reserved
617 #define C_EOS 102 //!< Reserved
618 #define C_FILE 103 //!< Reserved
619 #define C_LINE 104 //!< Used only by utility programs
620 
621 //! @}
622 
623 
624 /*! @name CEVA-X architecture
625  *
626  * Could not find any documentation.
627  * Reverse-engineered some values from the binary files.
628  */
629 //! @{
630 #define CEVA_MACHINE_XC4210_LIB 0xDCA6
631 #define CEVA_MACHINE_XC4210_OBJ 0x8CA6
632 #define CEVA_INVALID_SYMBOL_TABLE_INDEX 0xFFFFFFFF
633 #define CEVA_UNINITIALIZED_DATA 0x80
634 
635 //! @}
636 
637 //! Architectures supported by COFFI
638 typedef enum coffi_architecture_t {
639  //! Architecture unknown, or file not initialized.
641  //! Windows portable executable (PE or PE+)
643  //! Texas Instruments
645  //! CEVA Inc.
648 
649 // clang-format on
650 
651 //------------------------------------------------------------------------------
652 // Packing the structures
653 // The GCC syntax does not work for other compilers (Visual)
654 #pragma pack(1)
655 
656 //------------------------------------------------------------------------------
657 
658 //! MS-DOS file header
660 {
661  //! 0x4d, 0x5a. This is the "magic number" of an EXE file
662  uint16_t signature;
663  //! @brief The number of bytes in the last block of the program that are actually used.
664  //!
665  //! If this value is zero, that means the entire last block is used (i.e. the effective value is 512)
667  //! @brief Number of blocks in the file that are part of the EXE file.
668  //!
669  //! If [02-03] is non-zero, only that much of the last block is used
670  uint16_t blocks_in_file;
671  //! Number of relocation entries stored after the header. May be zero
672  uint16_t num_relocs;
673  //! @brief Number of paragraphs in the header.
674  //!
675  //! The program's data begins just after the header, and this field can be used to calculate the appropriate file offset.
676  //! The header includes the relocation entries.
677  //! Note that some OSs and/or programs may fail if the header is not a multiple of 512 bytes.
679  //! @brief Number of paragraphs of additional memory that the program will need.
680  //!
681  //! This is the equivalent of the BSS size in a Unix program.
682  //! The program can't be loaded if there isn't at least this much memory available to it
684  //! @brief Maximum number of paragraphs of additional memory.
685  //!
686  //! Normally, the OS reserves all the remaining conventional memory for your program, but you can limit it with this field.
688  //! @brief Relative value of the stack segment.
689  //!
690  //! This value is added to the segment the program was loaded at, and the result is used to initialize the SS register.
691  uint16_t ss;
692  //! Initial value of the SP register.
693  uint16_t sp;
694  //! @brief Word checksum.
695  //!
696  //! If set properly, the 16-bit sum of all words in the file should be zero. Usually, this isn't filled in.
697  uint16_t checksum;
698  //! Initial value of the IP register (entry point).
699  uint16_t ip;
700  //! Initial value of the CS register, relative to the segment the program was loaded at.
701  uint16_t cs;
702  //! Offset of the first relocation item in the file.
704  //! Overlay number. Normally zero, meaning that it's the main program.
705  uint16_t overlay_number;
706  uint16_t reserved1[4];
707  uint16_t oem_id;
708  uint16_t oem_info;
709  uint16_t reserved2[10];
710  //! Location of PE format signature.
712 };
713 
715 {
716  uint16_t offset;
717  uint16_t segment;
718 };
719 
720 //------------------------------------------------------------------------------
721 // COFF headers
722 
723 //! PE COFF header
725 {
726  uint16_t machine; //!< Identifies the type of target machine
727  uint16_t sections_count; //!< The size of the section table
728  uint32_t time_data_stamp; //!< A C run-time time_t value
729  uint32_t
730  symbol_table_offset; //!< The file offset of the COFF symbol table, or zero if no COFF symbol table is present
731  uint32_t symbols_count; //!< The number of entries in the symbol table
732  uint16_t
733  optional_header_size; //!< Which is required for executable files but not for object files.
734  uint16_t flags; //!< The flags that indicate the attributes of the file
735 };
736 
737 //! Texas Instruments COFF header
739 {
740  uint16_t version; //!< Indicates version of COFF file structure
741  uint16_t sections_count; //!< The size of the section table
742  uint32_t time_data_stamp; //!< A C run-time time_t value
743  uint32_t
744  symbol_table_offset; //!< The file offset of the COFF symbol table, or zero if no COFF symbol table is present
745  uint32_t symbols_count; //!< The number of entries in the symbol table
746  uint16_t
747  optional_header_size; //!< Which is required for executable files but not for object files.
748  uint16_t flags; //!< The flags that indicate the attributes of the file
749  uint16_t
750  target_id; //!< Magic number indicates the file can be executed in a specific TI system
751 };
752 
753 //------------------------------------------------------------------------------
754 // COFF optional headers
755 
756 //! PE32 COFF optional header
758 {
759  uint16_t magic; //!< State of the image file identifier
760  uint8_t major_linker_version; //!< The linker major version number
761  uint8_t minor_linker_version; //!< The linker minor version number
762  uint32_t code_size; //!< The sum of all code sections
763  uint32_t
764  initialized_data_size; //!< The sum of all initialized data sections
765  uint32_t
766  uninitialized_data_size; //!< The sum of all uninitialized data sections
767  uint32_t
768  entry_point_address; //!< The address of the entry point relative to the image base
769  uint32_t code_base; //!< base of the beginning-of-code section
770  uint32_t data_base; //!< base of the beginning-of-data section
771 };
772 
773 //! PE32+ COFF optional header
775 {
776  uint16_t magic; //!< State of the image file identifier
777  uint8_t major_linker_version; //!< The linker major version number
778  uint8_t minor_linker_version; //!< The linker minor version number
779  uint32_t code_size; //!< The sum of all code sections
780  uint32_t
781  initialized_data_size; //!< The sum of all initialized data sections
782  uint32_t
783  uninitialized_data_size; //!< The sum of all uninitialized data sections
784  uint32_t
785  entry_point_address; //!< The address of the entry point relative to the image base
786  uint32_t code_base; //!< base of the beginning-of-code section
787 };
788 
789 //! Texas Instruments COFF optional header
791 {
792  uint16_t magic; //!< State of the image file identifier
793  uint16_t linker_version; //!< The linker version number
794  uint32_t code_size; //!< The sum of all code sections
795  uint32_t
796  initialized_data_size; //!< The sum of all initialized data sections
797  uint32_t
798  uninitialized_data_size; //!< The sum of all uninitialized data sections
799  uint32_t
800  entry_point_address; //!< The address of the entry point relative to the image base
801  uint32_t code_base; //!< The address that is relative to the image
802  uint32_t data_base; //!<
803 };
804 
805 //------------------------------------------------------------------------------
806 // Windows NT headers
807 
808 //! PE32 Windows NT header
810 {
811  uint32_t image_base;
812  uint32_t section_alignment;
813  uint32_t file_alignment;
814  uint16_t major_os_version;
815  uint16_t minor_os_version;
816  uint16_t major_image_version;
817  uint16_t minor_image_version;
818  uint16_t major_subsystem_version;
819  uint16_t minor_subsystem_version;
820  uint32_t win32_version_value;
821  uint32_t image_size;
822  uint32_t headers_size;
823  uint32_t checksum;
824  uint16_t subsystem;
825  uint16_t dll_flags;
826  uint32_t stack_reserve_size;
827  uint32_t stack_commit_size;
828  uint32_t heap_reserve_size;
829  uint32_t heap_commit_size;
830  uint32_t loader_flags;
831  uint32_t number_of_rva_and_sizes;
832 };
833 
834 //! PE32+ Windows NT header
836 {
837  uint64_t image_base;
838  uint32_t section_alignment;
839  uint32_t file_alignment;
840  uint16_t major_os_version;
841  uint16_t minor_os_version;
842  uint16_t major_image_version;
843  uint16_t minor_image_version;
844  uint16_t major_subsystem_version;
845  uint16_t minor_subsystem_version;
846  uint32_t win32_version_value;
847  uint32_t image_size;
848  uint32_t headers_size;
849  uint32_t checksum;
850  uint16_t subsystem;
851  uint16_t dll_flags;
852  uint64_t stack_reserve_size;
853  uint64_t stack_commit_size;
854  uint64_t heap_reserve_size;
855  uint64_t heap_commit_size;
856  uint32_t loader_flags;
857  uint32_t number_of_rva_and_sizes;
858 };
859 
860 //------------------------------------------------------------------------------
861 // Symbol records
862 
863 //! Symbol record
865 {
866  char name[8];
867  uint32_t value;
868  uint16_t section_number;
869  uint16_t type;
870  uint8_t storage_class;
871  uint8_t aux_symbols_number;
872 };
873 
874 //! Generic auxiliary symbol record, covers any type of auxiliary symbol
876 {
877  char value[sizeof(symbol_record)];
878 };
879 
880 //! PE auxiliary format 1: Function definitions
882 {
883  uint32_t tag_index;
884  uint32_t total_size;
885  uint32_t pointer_to_linenumber;
886  uint32_t pointer_to_next_function;
887  uint16_t unused;
888 };
889 
890 //! PE auxiliary format 2: .bf and .ef symbols
892 {
893  uint32_t unused0;
894  uint16_t linenumber;
895  uint8_t unused1[6];
896  uint32_t pointer_to_next_function;
897  uint16_t unused2;
898 };
899 
900 //! PE auxiliary format 3: Weak externals
902 {
903  uint32_t tag_index;
904  uint32_t characteristics;
905  uint8_t unused1[10];
906 };
907 
908 //! PE auxiliary format 4: Files
910 {
911  char file_name[18];
912 };
913 
914 //! PE auxiliary format 5: Section definitions
916 {
917  uint32_t length;
918  uint16_t number_of_relocations;
919  uint16_t number_of_linenumbers;
920  uint32_t check_sum;
921  uint16_t number;
922  uint8_t selection;
923  uint8_t unused[3];
924 };
925 
926 //------------------------------------------------------------------------------
927 //! PE data directory
929 {
930  uint32_t virtual_address;
931  uint32_t size;
932 };
933 
934 //------------------------------------------------------------------------------
935 // Section headers
936 
937 //! PE section header
939 {
940  char name[8];
941  uint32_t virtual_size;
942  uint32_t virtual_address;
943  uint32_t data_size;
944  uint32_t data_offset;
945  uint32_t reloc_offset;
946  uint32_t line_num_offset;
947  uint16_t reloc_count;
948  uint16_t line_num_count;
949  uint32_t flags;
950 };
951 
952 //! Texas Instruments section header
954 {
955  char name[8];
956  uint32_t physical_address;
957  uint32_t virtual_address;
958  uint32_t data_size;
959  uint32_t data_offset;
960  uint32_t reloc_offset;
961  uint32_t reserved_0;
962  uint32_t reloc_count;
963  uint32_t line_num_count;
964  uint32_t flags;
965  uint16_t reserved_1;
966  uint16_t page_number;
967 };
968 
969 //------------------------------------------------------------------------------
970 // Relocation entries
971 
972 //! PE relocation entry
973 struct rel_entry
974 {
975  uint32_t virtual_address;
976  uint32_t symbol_table_index;
977  uint16_t type;
978 };
979 
980 //! Texas Instruments relocation entry
982 {
983  uint32_t virtual_address;
984  uint32_t symbol_table_index;
985  uint16_t reserved;
986  uint16_t type;
987 };
988 
989 //! CEVA relocation entry
991 {
992  uint32_t virtual_address;
993  uint32_t symbol_table_index;
994  uint32_t type;
995 };
996 
997 //! Structure capable of storing all the architecture-specific relocation entry structures
999 {
1000  uint32_t virtual_address;
1001  uint32_t symbol_table_index;
1002  uint32_t type;
1003  uint16_t reserved;
1004 };
1005 
1006 //------------------------------------------------------------------------------
1007 //! Line number structure in a COFF binary file.
1009 {
1010  //! Symbol table index or virtual address. Whether symbol table index or RVA is used depends on the value of line_number.
1011  uint32_t type;
1012  //! When nonzero, this field specifies a one-based line number. When zero, the Type field is interpreted as a symbol table index for a function.
1013  uint16_t line_number;
1014 };
1015 
1016 //------------------------------------------------------------------------------
1017 // Interfaces classes (pure virtual classes)
1018 //------------------------------------------------------------------------------
1019 class symbol;
1020 
1021 //! Interface for accessing to the string table
1023 {
1024  public:
1025  //! @brief Converts an 8-bytes symbol short name into a full name, eventually by looking into the strings table.
1026  //!
1027  //! @note Symbol short names that reference the string table start with "\x00\x00\x00\x00".
1028  virtual std::string string_to_name(const char* str) const = 0;
1029  //! @brief Converts an 8-bytes section short name into a full name, eventually by looking into the strings table.
1030  //!
1031  //! @note Section short names that reference the string table start with "/".
1032  virtual std::string section_string_to_name(const char* str) const = 0;
1033  //! Converts symbol full name into an 8-bytes short name, eventually creating an entry in the strings table.
1034  virtual void name_to_string(const std::string& name, char* str) = 0;
1035  //! Converts section full name into an 8-bytes short name, eventually creating an entry in the strings table.
1036  virtual void name_to_section_string(const std::string& name, char* str) = 0;
1037 };
1038 
1039 //------------------------------------------------------------------------------
1040 //! Interface for accessing to the symbol table
1042 {
1043  public:
1044  //! Gets a symbol from its index.
1045  virtual const symbol* get_symbol(uint32_t index) const = 0;
1046  //! Gets a symbol from its index.
1047  virtual symbol* get_symbol(uint32_t index) = 0;
1048  //! Gets a symbol from its name.
1049  virtual const symbol* get_symbol(const std::string& name) const = 0;
1050  //! Gets a symbol from its name.
1051  virtual symbol* get_symbol(const std::string& name) = 0;
1052  //! @brief Adds a symbol in the table.
1053  //!
1054  //! Eventually creates an entry in the strings table for the symbol name.
1055  virtual symbol* add_symbol(const std::string& name) = 0;
1056 };
1057 
1058 //------------------------------------------------------------------------------
1059 //! @brief Interface for architecture information
1060 //!
1061 //! This interface is implemented by the coffi class.
1063 {
1064  public:
1065  //! @brief Returns the coffi object architecture.
1066  //!
1067  //! @return #COFFI_ARCHITECTURE_NONE if the coffi object is not initialized, or in case of unrecognized architecture when loading a file.
1069 
1070  //! @brief Returns the character type size in bytes.
1071  //!
1072  //! Auto-detects the addressable unit: are the addresses in bytes or 2-bytes words?
1073  //! <br>Some targets have 2-bytes characters, this changes how offsets are computed in the file.
1074  //! @return 1 in most cases (characters are 1 byte), 2 for some specific targets (TMS320 C2000 for example).
1075  virtual int get_addressable_unit() const = 0;
1076 };
1077 
1078 //------------------------------------------------------------------------------
1079 class dos_header;
1080 class coff_header;
1081 class optional_header;
1082 class win_header;
1083 class sections;
1084 
1085 //! @brief Interface that gives the headers and sections.
1086 //!
1087 //! This interface is implemented by the coffi class.
1089 {
1090  public:
1091  //! Returns the MS-DOS header.
1092  virtual const dos_header* get_msdos_header() const = 0;
1093  //! Returns the COFF file header.
1094  virtual const coff_header* get_header() const = 0;
1095  //! Returns the COFF optional header.
1096  virtual const optional_header* get_optional_header() const = 0;
1097  //! Returns the Windows NT header.
1098  virtual const win_header* get_win_header() const = 0;
1099  //! Returns the sections.
1100  virtual const sections& get_sections() const = 0;
1101 };
1102 
1103 } // namespace COFFI
1104 
1105 #pragma pack()
1106 
1107 #endif // COFFI_TYPES_HPP
Interface for architecture information.
virtual coffi_architecture_t get_architecture() const =0
Returns the coffi object architecture.
virtual int get_addressable_unit() const =0
Returns the character type size in bytes.
Interface class for accessing the COFF file header, for all the COFF architectures.
Class for accessing the MS-DOS file header.
Interface class for accessing the COFF file optional header, for all the COFF architectures.
Interface that gives the headers and sections.
virtual const optional_header * get_optional_header() const =0
Returns the COFF optional header.
virtual const coff_header * get_header() const =0
Returns the COFF file header.
virtual const sections & get_sections() const =0
Returns the sections.
virtual const win_header * get_win_header() const =0
Returns the Windows NT header.
virtual const dos_header * get_msdos_header() const =0
Returns the MS-DOS header.
List of sections.
Interface for accessing to the string table.
virtual void name_to_section_string(const std::string &name, char *str)=0
Converts section full name into an 8-bytes short name, eventually creating an entry in the strings ta...
virtual std::string string_to_name(const char *str) const =0
Converts an 8-bytes symbol short name into a full name, eventually by looking into the strings table.
virtual std::string section_string_to_name(const char *str) const =0
Converts an 8-bytes section short name into a full name, eventually by looking into the strings table...
virtual void name_to_string(const std::string &name, char *str)=0
Converts symbol full name into an 8-bytes short name, eventually creating an entry in the strings tab...
Interface for accessing to the symbol table.
virtual symbol * add_symbol(const std::string &name)=0
Adds a symbol in the table.
virtual const symbol * get_symbol(const std::string &name) const =0
Gets a symbol from its name.
virtual symbol * get_symbol(const std::string &name)=0
Gets a symbol from its name.
virtual const symbol * get_symbol(uint32_t index) const =0
Gets a symbol from its index.
virtual symbol * get_symbol(uint32_t index)=0
Gets a symbol from its index.
Class for accessing a COFF symbol.
Interface class for accessing the Windows NT file header, for both the PE32 and PE32+ formats.
COFFI library namespace.
Definition: coffi.hpp:66
coffi_architecture_t
Architectures supported by COFFI.
@ COFFI_ARCHITECTURE_PE
Windows portable executable (PE or PE+)
@ COFFI_ARCHITECTURE_NONE
Architecture unknown, or file not initialized.
@ COFFI_ARCHITECTURE_CEVA
CEVA Inc.
@ COFFI_ARCHITECTURE_TI
Texas Instruments.
PE auxiliary format 1: Function definitions.
PE auxiliary format 2: .bf and .ef symbols.
PE auxiliary format 3: Weak externals.
PE auxiliary format 4: Files.
PE auxiliary format 5: Section definitions.
Generic auxiliary symbol record, covers any type of auxiliary symbol.
Texas Instruments COFF header.
uint16_t optional_header_size
Which is required for executable files but not for object files.
uint16_t flags
The flags that indicate the attributes of the file.
uint32_t time_data_stamp
A C run-time time_t value.
uint16_t sections_count
The size of the section table.
uint16_t version
Indicates version of COFF file structure.
uint32_t symbol_table_offset
The file offset of the COFF symbol table, or zero if no COFF symbol table is present.
uint16_t target_id
Magic number indicates the file can be executed in a specific TI system.
uint32_t symbols_count
The number of entries in the symbol table.
uint16_t optional_header_size
Which is required for executable files but not for object files.
uint16_t flags
The flags that indicate the attributes of the file.
uint16_t machine
Identifies the type of target machine.
uint32_t time_data_stamp
A C run-time time_t value.
uint16_t sections_count
The size of the section table.
uint32_t symbol_table_offset
The file offset of the COFF symbol table, or zero if no COFF symbol table is present.
uint32_t symbols_count
The number of entries in the symbol table.
PE32+ COFF optional header.
uint8_t major_linker_version
The linker major version number.
uint32_t uninitialized_data_size
The sum of all uninitialized data sections.
uint8_t minor_linker_version
The linker minor version number.
uint32_t code_size
The sum of all code sections.
uint16_t magic
State of the image file identifier.
uint32_t code_base
base of the beginning-of-code section
uint32_t entry_point_address
The address of the entry point relative to the image base.
uint32_t initialized_data_size
The sum of all initialized data sections.
PE32 COFF optional header.
uint8_t major_linker_version
The linker major version number.
uint32_t uninitialized_data_size
The sum of all uninitialized data sections.
uint8_t minor_linker_version
The linker minor version number.
uint32_t code_size
The sum of all code sections.
uint32_t data_base
base of the beginning-of-data section
uint16_t magic
State of the image file identifier.
uint32_t code_base
base of the beginning-of-code section
uint32_t entry_point_address
The address of the entry point relative to the image base.
uint32_t initialized_data_size
The sum of all initialized data sections.
Texas Instruments COFF optional header.
uint32_t uninitialized_data_size
The sum of all uninitialized data sections.
uint16_t linker_version
The linker version number.
uint32_t code_size
The sum of all code sections.
uint16_t magic
State of the image file identifier.
uint32_t code_base
The address that is relative to the image.
uint32_t entry_point_address
The address of the entry point relative to the image base.
uint32_t initialized_data_size
The sum of all initialized data sections.
Line number structure in a COFF binary file.
uint16_t line_number
When nonzero, this field specifies a one-based line number. When zero, the Type field is interpreted ...
uint32_t type
Symbol table index or virtual address. Whether symbol table index or RVA is used depends on the value...
MS-DOS file header.
uint16_t ss
Relative value of the stack segment.
uint16_t blocks_in_file
Number of blocks in the file that are part of the EXE file.
uint16_t ip
Initial value of the IP register (entry point).
uint16_t num_relocs
Number of relocation entries stored after the header. May be zero.
int32_t pe_sign_location
Location of PE format signature.
uint16_t max_extra_paragraphs
Maximum number of paragraphs of additional memory.
uint16_t cs
Initial value of the CS register, relative to the segment the program was loaded at.
uint16_t checksum
Word checksum.
uint16_t sp
Initial value of the SP register.
uint16_t bytes_in_last_block
The number of bytes in the last block of the program that are actually used.
uint16_t signature
0x4d, 0x5a. This is the "magic number" of an EXE file
uint16_t reloc_table_offset
Offset of the first relocation item in the file.
uint16_t overlay_number
Overlay number. Normally zero, meaning that it's the main program.
uint16_t header_paragraphs
Number of paragraphs in the header.
uint16_t min_extra_paragraphs
Number of paragraphs of additional memory that the program will need.
CEVA relocation entry.
Structure capable of storing all the architecture-specific relocation entry structures.
Texas Instruments relocation entry.
PE relocation entry.
Texas Instruments section header.
PE section header.
Symbol record.
PE32+ Windows NT header.
PE32 Windows NT header.