Initial push
[termux-packages] / packages / termux-tools / elf.h
1 #ifndef ELF_H_INCLUDED
2 #define ELF_H_INCLUDED
3
4 #include <stdint.h>
5
6 /* Type for a 16-bit quantity. */
7 typedef uint16_t Elf32_Half;
8 typedef uint16_t Elf64_Half;
9
10 /* Types for signed and unsigned 32-bit quantities. */
11 typedef uint32_t Elf32_Word;
12 typedef int32_t Elf32_Sword;
13 typedef uint32_t Elf64_Word;
14 typedef int32_t Elf64_Sword;
15
16 /* Types for signed and unsigned 64-bit quantities. */
17 typedef uint64_t Elf32_Xword;
18 typedef int64_t Elf32_Sxword;
19 typedef uint64_t Elf64_Xword;
20 typedef int64_t Elf64_Sxword;
21
22 /* Type of addresses. */
23 typedef uint32_t Elf32_Addr;
24 typedef uint64_t Elf64_Addr;
25
26 /* Type of file offsets. */
27 typedef uint32_t Elf32_Off;
28 typedef uint64_t Elf64_Off;
29
30 /* Type for section indices, which are 16-bit quantities. */
31 typedef uint16_t Elf32_Section;
32 typedef uint16_t Elf64_Section;
33
34 /* Type for version symbol information. */
35 typedef Elf32_Half Elf32_Versym;
36 typedef Elf64_Half Elf64_Versym;
37
38
39 /* The ELF file header. This appears at the start of every ELF file. */
40 typedef struct {
41 unsigned char e_ident[16]; /* Magic number and other info */
42 Elf32_Half e_type; /* Object file type */
43 Elf32_Half e_machine; /* Architecture */
44 Elf32_Word e_version; /* Object file version */
45 Elf32_Addr e_entry; /* Entry point virtual address */
46 Elf32_Off e_phoff; /* Program header table (usually follows elf header directly) file offset */
47 Elf32_Off e_shoff; /* Section header table (at end of file) file offset */
48 Elf32_Word e_flags; /* Processor-specific flags */
49 Elf32_Half e_ehsize; /* ELF header size in bytes */
50 Elf32_Half e_phentsize; /* Program header table entry size */
51 Elf32_Half e_phnum; /* Program header table entry count */
52 Elf32_Half e_shentsize; /* Section header table entry size */
53 Elf32_Half e_shnum; /* Section header table entry count */
54 Elf32_Half e_shstrndx; /* Section header string table index */
55 } Elf32_Ehdr;
56 typedef struct {
57 unsigned char e_ident[16]; /* Magic number and other info */
58 Elf64_Half e_type; /* Object file type */
59 Elf64_Half e_machine; /* Architecture */
60 Elf64_Word e_version; /* Object file version */
61 Elf64_Addr e_entry; /* Entry point virtual address */
62 Elf64_Off e_phoff; /* Program header table file offset */
63 Elf64_Off e_shoff; /* Section header table file offset */
64 Elf64_Word e_flags; /* Processor-specific flags */
65 Elf64_Half e_ehsize; /* ELF header size in bytes */
66 Elf64_Half e_phentsize; /* Program header table entry size */
67 Elf64_Half e_phnum; /* Program header table entry count */
68 Elf64_Half e_shentsize; /* Section header table entry size */
69 Elf64_Half e_shnum; /* Section header table entry count */
70 Elf64_Half e_shstrndx; /* Section header string table index */
71 } Elf64_Ehdr;
72
73 /* Section header entry. The number of section entries in the file are determined by the "e_shnum" field of the ELF header.*/
74 typedef struct {
75 Elf32_Word sh_name; /* Section name (string tbl index) */
76 Elf32_Word sh_type; /* Section type */
77 Elf32_Word sh_flags; /* Section flags */
78 Elf32_Addr sh_addr; /* Section virtual addr at execution */
79 Elf32_Off sh_offset; /* Section file offset */
80 Elf32_Word sh_size; /* Section size in bytes */
81 Elf32_Word sh_link; /* Link to another section */
82 Elf32_Word sh_info; /* Additional section information */
83 Elf32_Word sh_addralign; /* Section alignment */
84 Elf32_Word sh_entsize; /* Entry size if section holds table */
85 } Elf32_Shdr;
86 typedef struct {
87 Elf64_Word sh_name; /* Section name (string tbl index) */
88 Elf64_Word sh_type; /* Section type */
89 Elf64_Xword sh_flags; /* Section flags */
90 Elf64_Addr sh_addr; /* Section virtual addr at execution */
91 Elf64_Off sh_offset; /* Section file offset */
92 Elf64_Xword sh_size; /* Section size in bytes */
93 Elf64_Word sh_link; /* Link to another section */
94 Elf64_Word sh_info; /* Additional section information */
95 Elf64_Xword sh_addralign; /* Section alignment */
96 Elf64_Xword sh_entsize; /* Entry size if section holds table */
97 } Elf64_Shdr;
98
99 /* Legal values for sh_type (section type). */
100 #define SHT_NULL 0 /* Section header table entry unused */
101 #define SHT_PROGBITS 1 /* Program data */
102 #define SHT_SYMTAB 2 /* Symbol table */
103 #define SHT_STRTAB 3 /* String table */
104 #define SHT_RELA 4 /* Relocation entries with addends */
105 #define SHT_HASH 5 /* Symbol hash table */
106 #define SHT_DYNAMIC 6 /* Dynamic linking information. Contains Elf32_Dyn/Elf64_Dyn entries. */
107 #define SHT_NOTE 7 /* Notes */
108 #define SHT_NOBITS 8 /* Program space with no data (bss) */
109 #define SHT_REL 9 /* Relocation entries, no addends */
110 #define SHT_SHLIB 10 /* Reserved */
111 #define SHT_DYNSYM 11 /* Dynamic linker symbol table */
112 #define SHT_INIT_ARRAY 14 /* Array of constructors */
113 #define SHT_FINI_ARRAY 15 /* Array of destructors */
114 #define SHT_PREINIT_ARRAY 16 /* Array of pre-constructors */
115 #define SHT_GROUP 17 /* Section group */
116 #define SHT_SYMTAB_SHNDX 18 /* Extended section indeces */
117 #define SHT_NUM 19 /* Number of defined types. */
118 #define SHT_LOOS 0x60000000 /* Start OS-specific. */
119 #define SHT_GNU_ATTRIBUTES 0x6ffffff5 /* Object attributes. */
120 #define SHT_GNU_HASH 0x6ffffff6 /* GNU-style hash table. */
121 #define SHT_GNU_LIBLIST 0x6ffffff7 /* Prelink library list */
122 #define SHT_CHECKSUM 0x6ffffff8 /* Checksum for DSO content. */
123 #define SHT_LOSUNW 0x6ffffffa /* Sun-specific low bound. */
124 #define SHT_SUNW_move 0x6ffffffa
125 #define SHT_SUNW_COMDAT 0x6ffffffb
126 #define SHT_SUNW_syminfo 0x6ffffffc
127 #define SHT_GNU_verdef 0x6ffffffd /* Version definition section. */
128 #define SHT_GNU_verneed 0x6ffffffe /* Version needs section. */
129 #define SHT_GNU_versym 0x6fffffff /* Version symbol table. */
130 #define SHT_HISUNW 0x6fffffff /* Sun-specific high bound. */
131 #define SHT_HIOS 0x6fffffff /* End OS-specific type */
132 #define SHT_LOPROC 0x70000000 /* Start of processor-specific */
133 #define SHT_HIPROC 0x7fffffff /* End of processor-specific */
134 #define SHT_LOUSER 0x80000000 /* Start of application-specific */
135 #define SHT_HIUSER 0x8fffffff /* End of application-specific */
136
137 /* Dynamic section entry. */
138 typedef struct {
139 Elf32_Sword d_tag; /* Dynamic entry type */
140 union { Elf32_Word d_val; Elf32_Addr d_ptr; } d_un; /* Integer or address value */
141 } Elf32_Dyn;
142 typedef struct {
143 Elf64_Sxword d_tag; /* Dynamic entry type */
144 union { Elf64_Xword d_val; Elf64_Addr d_ptr; } d_un; /* Integer or address value */
145 } Elf64_Dyn;
146
147 /* Legal values for d_tag (dynamic entry type). */
148 #define DT_NULL 0 /* Marks end of dynamic section */
149 #define DT_NEEDED 1 /* Name of needed library */
150 #define DT_PLTRELSZ 2 /* Size in bytes of PLT relocs */
151 #define DT_PLTGOT 3 /* Processor defined value */
152 #define DT_HASH 4 /* Address of symbol hash table */
153 #define DT_STRTAB 5 /* Address of string table */
154 #define DT_SYMTAB 6 /* Address of symbol table */
155 #define DT_RELA 7 /* Address of Rela relocs */
156 #define DT_RELASZ 8 /* Total size of Rela relocs */
157 #define DT_RELAENT 9 /* Size of one Rela reloc */
158 #define DT_STRSZ 10 /* Size of string table */
159 #define DT_SYMENT 11 /* Size of one symbol table entry */
160 #define DT_INIT 12 /* Address of init function */
161 #define DT_FINI 13 /* Address of termination function */
162 #define DT_SONAME 14 /* Name of shared object */
163 #define DT_RPATH 15 /* Library search path (deprecated) */
164 #define DT_SYMBOLIC 16 /* Start symbol search here */
165 #define DT_REL 17 /* Address of Rel relocs */
166 #define DT_RELSZ 18 /* Total size of Rel relocs */
167 #define DT_RELENT 19 /* Size of one Rel reloc */
168 #define DT_PLTREL 20 /* Type of reloc in PLT */
169 #define DT_DEBUG 21 /* For debugging; unspecified */
170 #define DT_TEXTREL 22 /* Reloc might modify .text */
171 #define DT_JMPREL 23 /* Address of PLT relocs */
172 #define DT_BIND_NOW 24 /* Process relocations of object */
173 #define DT_INIT_ARRAY 25 /* Array with addresses of init fct */
174 #define DT_FINI_ARRAY 26 /* Array with addresses of fini fct */
175 #define DT_INIT_ARRAYSZ 27 /* Size in bytes of DT_INIT_ARRAY */
176 #define DT_FINI_ARRAYSZ 28 /* Size in bytes of DT_FINI_ARRAY */
177 #define DT_RUNPATH 29 /* Library search path */
178 #define DT_FLAGS 30 /* Flags for the object being loaded */
179 #define DT_ENCODING 32 /* Start of encoded range */
180 #define DT_PREINIT_ARRAY 32 /* Array with addresses of preinit fct*/
181 #define DT_PREINIT_ARRAYSZ 33 /* size in bytes of DT_PREINIT_ARRAY */
182 #define DT_NUM 34 /* Number used */
183 #define DT_LOOS 0x6000000d /* Start of OS-specific */
184 #define DT_HIOS 0x6ffff000 /* End of OS-specific */
185 #define DT_LOPROC 0x70000000 /* Start of processor-specific */
186 #define DT_HIPROC 0x7fffffff /* End of processor-specific */
187
188
189 /* Symbol table entry. */
190 typedef struct {
191 Elf32_Word st_name; /* Symbol name (string tbl index) */
192 Elf32_Addr st_value; /* Symbol value */
193 Elf32_Word st_size; /* Symbol size */
194 unsigned char st_info; /* Symbol type and binding */
195 unsigned char st_other; /* Symbol visibility */
196 Elf32_Section st_shndx; /* Section index */
197 } Elf32_Sym;
198
199 typedef struct {
200 Elf64_Word st_name; /* Symbol name (string tbl index) */
201 unsigned char st_info; /* Symbol type and binding */
202 unsigned char st_other; /* Symbol visibility */
203 Elf64_Section st_shndx; /* Section index */
204 Elf64_Addr st_value; /* Symbol value */
205 Elf64_Xword st_size; /* Symbol size */
206 } Elf64_Sym;
207
208
209 #endif