4 \brief ELF Exeutable Loader
11 typedef uint16_t Elf32_Half;
12 typedef uint32_t Elf32_Addr;
13 typedef uint32_t Elf32_Off;
14 typedef uint32_t Elf32_Word;
15 typedef int32_t Elf32_Sword;
25 \brief ELF File Header
28 uint8_t e_ident[16]; //!< Identifier Bytes
29 Elf32_Half filetype; //!< File Type
30 Elf32_Half machine; //!< Machine / Arch
31 Elf32_Word version; //!< Version (File?)
32 Elf32_Addr entrypoint; //!< Entry Point
33 Elf32_Off phoff; //!< Program Header Offset
34 Elf32_Word shoff; //!< Section Header Offset
35 Elf32_Word flags; //!< Flags
36 Elf32_Half headersize; //!< Header Size
37 Elf32_Half phentsize; //!< Program Header Entry Size
38 Elf32_Half phentcount; //!< Program Header Entry Count
39 Elf32_Half shentsize; //!< Section Header Entry Size
40 Elf32_Half shentcount; //!< Section Header Entry Count
41 Elf32_Half shstrindex; //!< Section Header String Table Index
45 \name Executable Types
48 #define ET_NONE 0 //!< NULL Type
49 #define ET_REL 1 //!< Relocatable (Object)
50 #define ET_EXEC 2 //!< Executable
51 #define ET_DYN 3 //!< Dynamic Library
52 #define ET_CORE 4 //!< Core?
53 #define ET_LOPROC 0xFF00 //!< Low Impl Defined
54 #define ET_HIPROC 0xFFFF //!< High Impl Defined
61 #define SHN_UNDEF 0 //!< Undefined Section
62 #define SHN_LORESERVE 0xFF00 //!< Low Reserved
63 #define SHN_LOPROC 0xFF00 //!< Low Impl Defined
64 #define SHN_HIPROC 0xFF1F //!< High Impl Defined
65 #define SHN_ABS 0xFFF1 //!< Absolute Address (Base: 0, Size: -1)
66 #define SHN_COMMON 0xFFF2 //!< Common
67 #define SHN_HIRESERVE 0xFFFF //!< High Reserved
71 \enum eElfSectionTypes
72 \brief ELF Section Types
74 enum eElfSectionTypes {
88 SHT_LOPROC = 0x70000000,
89 SHT_HIPROC = 0x7fffffff,
90 SHT_LOUSER = 0x80000000,
91 SHT_HIUSER = 0xffffffff
97 #define SHF_EXECINSTR 0x4
98 #define SHF_MASKPROC 0xf0000000
100 struct sElf32_Shent {
116 Elf32_Addr value; //Address
122 #define STN_UNDEF 0 // Undefined Symbol
132 PT_LOPROC = 0x70000000,
133 PT_HIPROC = 0x7fffffff
156 struct elf32_rela_s {
159 Elf32_Sword r_addend;
163 R_386_NONE=0, // none
166 R_386_GOT32, // G+A-P
167 R_386_PLT32, // L+A-P
171 R_386_RELATIVE, // B+A
172 R_386_GOTOFF, // S+A-GOT
173 R_386_GOTPC, // GOT+A-P
178 // 'T' means the thumb bit
179 // 'B(S)' Origin of a symbol
181 R_ARM_NONE, // 0 No action
182 R_ARM_PC24, // 1 ((S + A) | T) - P
183 R_ARM_ABS32, // 2 (S + A) | T
184 R_ARM_REL32, // 3 ((S + A) | T) - P
185 R_ARM_LDR_PC_G0, // 4 S + A - P
186 R_ARM_ABS16, // 5 S + A
187 R_ARM_ABS12, // 6 S + A
188 R_ARM_THM_ABS5, // 7 S + A
189 R_ARM_ABS8, // 8 S + A
190 R_ARM_SBREL32, // 9 ((S + A) | T) - B(S)
191 R_ARM_THM_CALL, // 10 ((S + A) | T) - P
192 R_ARM_THM_PC8, // 11 S + A - Pa,
193 R_ARM_BREL_ADJ, // 12 ΔB(S) + A
194 R_ARM_TLS_DESC, // 13 --
195 R_ARM_THM_SWI8, // 14 (Reserved)
196 R_ARM_XPC25, // 15 (Reserved)
197 R_ARM_THM_XPC22, // 16 (Reserved)
198 R_ARM_TLS_DTPMOD32, // 17 Module[S]
199 R_ARM_TLS_DTPOFF32, // 18 S + A - TLS
200 R_ARM_TLS_TPOFF32, // 19 S + A - tp
201 R_ARM_COPY, // 20 Misc
202 R_ARM_GLOB_DAT, // 21 (S + A) | T
203 R_ARM_JUMP_SLOT, // 22 (S + A) | T
204 R_ARM_RELATIVE, // 23 B(S) + A (extra?)
205 // ... More defined (IHI0044)
208 #define ELF32_R_SYM(i) ((i)>>8) // Takes an info value and returns a symbol index
209 #define ELF32_R_TYPE(i) ((i)&0xFF) // Takes an info value and returns a type
210 #define ELF32_R_INFO(s,t) (((s)<<8)+((t)&0xFF)) // Takes a type and symbol index and returns an info value
214 Elf32_Word d_val; //Also d_ptr
218 DT_NULL, //!< Marks End of list
219 DT_NEEDED, //!< Offset in strtab to needed library
220 DT_PLTRELSZ, //!< Size in bytes of PLT
221 DT_PLTGOT, //!< Address of PLT/GOT
222 DT_HASH, //!< Address of symbol hash table
223 DT_STRTAB, //!< String Table address
224 DT_SYMTAB, //!< Symbol Table address
225 DT_RELA, //!< Relocation table address
226 DT_RELASZ, //!< Size of relocation table
227 DT_RELAENT, //!< Size of entry in relocation table
228 DT_STRSZ, //!< Size of string table
229 DT_SYMENT, //!< Size of symbol table entry
230 DT_INIT, //!< Address of initialisation function
231 DT_FINI, //!< Address of termination function
232 DT_SONAME, //!< String table offset of so name
233 DT_RPATH, //!< String table offset of library path
234 DT_SYMBOLIC,//!< Reverse order of symbol searching for library, search libs first then executable
235 DT_REL, //!< Relocation Entries (Elf32_Rel instead of Elf32_Rela)
236 DT_RELSZ, //!< Size of above table (bytes)
237 DT_RELENT, //!< Size of entry in above table
238 DT_PLTREL, //!< Relocation entry of PLT
239 DT_DEBUG, //!< Debugging Entry - Unknown contents
240 DT_TEXTREL, //!< Indicates that modifcations to a non-writeable segment may occur
241 DT_JMPREL, //!< Address of PLT only relocation entries
242 DT_LOPROC = 0x70000000, //!< Low Definable
243 DT_HIPROC = 0x7FFFFFFF //!< High Definable
246 typedef struct sElf32_Ehdr Elf32_Ehdr;
247 typedef struct sElf32_Phdr Elf32_Phdr;
248 typedef struct sElf32_Shent Elf32_Shent;
249 typedef struct elf_sym_s elf_symtab;
250 typedef struct elf_sym_s Elf32_Sym;
251 typedef struct elf32_rel_s Elf32_Rel;
252 typedef struct elf32_rela_s Elf32_Rela;
253 typedef struct elf32_dyn_s Elf32_Dyn;
255 #endif // defined(_EXE_ELF_H)