blob: 5c2503a5f3e3d60cc2bfe1ffef954a06ed0dde50 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
Elliott Hughes203e13d2016-07-22 14:56:18 -070028
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080029#ifndef _ELF_H
30#define _ELF_H
31
Josh Gao16016df2016-11-07 18:27:16 -080032#include <sys/cdefs.h>
33
Elliott Hughes0446c8c2017-04-19 10:20:25 -070034#include <bits/auxvec.h>
Elliott Hughes5109bb42017-04-19 13:25:27 -070035#include <bits/elf_arm.h>
36#include <bits/elf_arm64.h>
37#include <bits/elf_mips.h>
38#include <bits/elf_x86.h>
39#include <bits/elf_x86_64.h>
Elliott Hughes0266ae52014-02-10 17:46:57 -080040#include <linux/elf.h>
41#include <linux/elf-em.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080042
Elliott Hughesa8a23f52017-10-31 17:22:41 -070043/* http://www.sco.com/developers/gabi/latest/ch4.intro.html */
Dmitriy Ivanovce16a532015-05-07 22:58:00 -070044typedef __s64 Elf32_Sxword;
45
Nick Kralevich2c5153b2013-01-11 14:43:05 -080046typedef struct {
Elliott Hughes0266ae52014-02-10 17:46:57 -080047 __u32 a_type;
Nick Kralevich2c5153b2013-01-11 14:43:05 -080048 union {
Elliott Hughes0266ae52014-02-10 17:46:57 -080049 __u32 a_val;
Nick Kralevich2c5153b2013-01-11 14:43:05 -080050 } a_un;
51} Elf32_auxv_t;
52
53typedef struct {
Elliott Hughes0266ae52014-02-10 17:46:57 -080054 __u64 a_type;
Nick Kralevich2c5153b2013-01-11 14:43:05 -080055 union {
Elliott Hughes0266ae52014-02-10 17:46:57 -080056 __u64 a_val;
Nick Kralevich2c5153b2013-01-11 14:43:05 -080057 } a_un;
58} Elf64_auxv_t;
59
Elliott Hughesa8a23f52017-10-31 17:22:41 -070060/* http://www.sco.com/developers/gabi/latest/ch4.sheader.html */
61typedef struct {
62 Elf32_Word ch_type;
63 Elf32_Word ch_size;
64 Elf32_Word ch_addralign;
65} Elf32_Chdr;
66typedef struct {
67 Elf64_Word ch_type;
68 Elf64_Word ch_reserved;
69 Elf64_Xword ch_size;
70 Elf64_Xword ch_addralign;
71} Elf64_Chdr;
72
73typedef __u16 Elf32_Section;
74typedef __u16 Elf64_Section;
75
Dmitriy Ivanovc0e7dbb2015-04-09 13:58:53 -070076typedef Elf32_Half Elf32_Versym;
77typedef Elf64_Half Elf64_Versym;
78
79typedef struct {
80 Elf32_Half vd_version;
81 Elf32_Half vd_flags;
82 Elf32_Half vd_ndx;
83 Elf32_Half vd_cnt;
84 Elf32_Word vd_hash;
85 Elf32_Word vd_aux;
86 Elf32_Word vd_next;
87} Elf32_Verdef;
88
89typedef struct {
90 Elf32_Word vda_name;
91 Elf32_Word vda_next;
92} Elf32_Verdaux;
93
94typedef struct {
95 Elf64_Half vd_version;
96 Elf64_Half vd_flags;
97 Elf64_Half vd_ndx;
98 Elf64_Half vd_cnt;
99 Elf64_Word vd_hash;
100 Elf64_Word vd_aux;
101 Elf64_Word vd_next;
102} Elf64_Verdef;
103
104typedef struct {
105 Elf64_Word vda_name;
106 Elf64_Word vda_next;
107} Elf64_Verdaux;
108
109typedef struct {
110 Elf32_Half vn_version;
111 Elf32_Half vn_cnt;
112 Elf32_Word vn_file;
113 Elf32_Word vn_aux;
114 Elf32_Word vn_next;
115} Elf32_Verneed;
116
117typedef struct {
118 Elf32_Word vna_hash;
119 Elf32_Half vna_flags;
120 Elf32_Half vna_other;
121 Elf32_Word vna_name;
122 Elf32_Word vna_next;
123} Elf32_Vernaux;
124
125typedef struct {
126 Elf64_Half vn_version;
127 Elf64_Half vn_cnt;
128 Elf64_Word vn_file;
129 Elf64_Word vn_aux;
130 Elf64_Word vn_next;
131} Elf64_Verneed;
132
133typedef struct {
134 Elf64_Word vna_hash;
135 Elf64_Half vna_flags;
136 Elf64_Half vna_other;
137 Elf64_Word vna_name;
138 Elf64_Word vna_next;
139} Elf64_Vernaux;
140
Elliott Hughesa8a23f52017-10-31 17:22:41 -0700141/* http://www.sco.com/developers/gabi/latest/ch5.dynamic.html */
Elliott Hughes0266ae52014-02-10 17:46:57 -0800142#define DF_ORIGIN 0x00000001
143#define DF_SYMBOLIC 0x00000002
144#define DF_TEXTREL 0x00000004
145#define DF_BIND_NOW 0x00000008
146#define DF_STATIC_TLS 0x00000010
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800147
Dmitriy Ivanova6bee4d2014-10-13 12:23:55 -0700148#define DF_1_NOW 0x00000001 /* Perform complete relocation processing. */
149#define DF_1_GLOBAL 0x00000002 /* implies RTLD_GLOBAL */
Dmitriy Ivanov6cdeb522014-09-29 19:14:45 -0700150#define DF_1_GROUP 0x00000004
Dmitriy Ivanova6bee4d2014-10-13 12:23:55 -0700151#define DF_1_NODELETE 0x00000008 /* implies RTLD_NODELETE */
Dmitriy Ivanov6cdeb522014-09-29 19:14:45 -0700152#define DF_1_LOADFLTR 0x00000010
153#define DF_1_INITFIRST 0x00000020
Dmitriy Ivanova6bee4d2014-10-13 12:23:55 -0700154#define DF_1_NOOPEN 0x00000040 /* Object can not be used with dlopen(3) */
Dmitriy Ivanov6cdeb522014-09-29 19:14:45 -0700155#define DF_1_ORIGIN 0x00000080
156#define DF_1_DIRECT 0x00000100
157#define DF_1_TRANS 0x00000200
158#define DF_1_INTERPOSE 0x00000400
159#define DF_1_NODEFLIB 0x00000800
Dmitriy Ivanova6bee4d2014-10-13 12:23:55 -0700160#define DF_1_NODUMP 0x00001000 /* Object cannot be dumped with dldump(3) */
Dmitriy Ivanov6cdeb522014-09-29 19:14:45 -0700161#define DF_1_CONFALT 0x00002000
162#define DF_1_ENDFILTEE 0x00004000
163#define DF_1_DISPRELDNE 0x00008000
164#define DF_1_DISPRELPND 0x00010000
165#define DF_1_NODIRECT 0x00020000
Dmitriy Ivanova6bee4d2014-10-13 12:23:55 -0700166#define DF_1_IGNMULDEF 0x00040000 /* Internal use */
167#define DF_1_NOKSYMS 0x00080000 /* Internal use */
168#define DF_1_NOHDR 0x00100000 /* Internal use */
Dmitriy Ivanov6cdeb522014-09-29 19:14:45 -0700169#define DF_1_EDITED 0x00200000
Dmitriy Ivanova6bee4d2014-10-13 12:23:55 -0700170#define DF_1_NORELOC 0x00400000 /* Internal use */
Dmitriy Ivanov6cdeb522014-09-29 19:14:45 -0700171#define DF_1_SYMINTPOSE 0x00800000
172#define DF_1_GLOBAUDIT 0x01000000
173#define DF_1_SINGLETON 0x02000000
174#define DF_1_STUB 0x04000000
175#define DF_1_PIE 0x08000000
176
Elliott Hughesa8a23f52017-10-31 17:22:41 -0700177/* http://www.sco.com/developers/gabi/latest/ch5.dynamic.html */
Elliott Hughes0266ae52014-02-10 17:46:57 -0800178#define DT_BIND_NOW 24
179#define DT_INIT_ARRAY 25
180#define DT_FINI_ARRAY 26
181#define DT_INIT_ARRAYSZ 27
182#define DT_FINI_ARRAYSZ 28
183#define DT_RUNPATH 29
184#define DT_FLAGS 30
185/* glibc and BSD disagree for DT_ENCODING; glibc looks wrong. */
186#define DT_PREINIT_ARRAY 32
187#define DT_PREINIT_ARRAYSZ 33
188
Dmitriy Ivanov18a69562015-02-04 16:05:30 -0800189/* Android compressed rel/rela sections */
190#define DT_ANDROID_REL (DT_LOOS + 2)
191#define DT_ANDROID_RELSZ (DT_LOOS + 3)
Dmitriy Ivanov18a69562015-02-04 16:05:30 -0800192#define DT_ANDROID_RELA (DT_LOOS + 4)
193#define DT_ANDROID_RELASZ (DT_LOOS + 5)
194
Dmitriy Ivanovec18ce02014-11-09 19:27:20 -0800195#define DT_GNU_HASH 0x6ffffef5
196
Elliott Hughesa8a23f52017-10-31 17:22:41 -0700197/* http://www.sco.com/developers/gabi/latest/ch4.eheader.html */
198#define EI_ABIVERSION 8
199#undef EI_PAD
200#define EI_PAD 9
201
202/* http://www.sco.com/developers/gabi/latest/ch4.sheader.html */
203#define ELFCOMPRESS_ZLIB 1
204#define ELFCOMPRESS_LOOS 0x60000000
205#define ELFCOMPRESS_HIOS 0x6fffffff
206#define ELFCOMPRESS_LOPROC 0x70000000
207#define ELFCOMPRESS_HIPROC 0x7fffffff
208
209/* http://www.sco.com/developers/gabi/latest/ch4.eheader.html */
Elliott Hughes0266ae52014-02-10 17:46:57 -0800210#define ELFOSABI_SYSV 0 /* Synonym for ELFOSABI_NONE used by valgrind. */
Elliott Hughesa8a23f52017-10-31 17:22:41 -0700211#define ELFOSABI_HPUX 1
212#define ELFOSABI_NETBSD 2
213#define ELFOSABI_GNU 3 /* Synonym for ELFOSABI_LINUX. */
214#define ELFOSABI_SOLARIS 6
215#define ELFOSABI_AIX 7
216#define ELFOSABI_IRIX 8
217#define ELFOSABI_FREEBSD 9
218#define ELFOSABI_TRU64 10
219#define ELFOSABI_MODESTO 11
220#define ELFOSABI_OPENBSD 12
221#define ELFOSABI_OPENVMS 13
222#define ELFOSABI_NSK 14
223#define ELFOSABI_AROS 15
224#define ELFOSABI_FENIXOS 16
225#define ELFOSABI_CLOUDABI 17
226#define ELFOSABI_OPENVOS 18
227#define ELFOSABI_ARM_AEABI 64
Elliott Hughes0266ae52014-02-10 17:46:57 -0800228
Elliott Hughesa8a23f52017-10-31 17:22:41 -0700229/* http://www.sco.com/developers/gabi/latest/ch4.reloc.html */
230#define ELF32_R_INFO(sym, type) ((((Elf32_Word)sym) << 8) | ((type) & 0xff))
231#define ELF64_R_INFO(sym, type) ((((Elf64_Xword)sym) << 32) | ((type) & 0xffffffff))
Elliott Hughes0266ae52014-02-10 17:46:57 -0800232
Elliott Hughesa8a23f52017-10-31 17:22:41 -0700233/* http://www.sco.com/developers/gabi/latest/ch4.symtab.html */
Elliott Hughesd390df12017-04-30 22:56:10 -0700234#undef ELF_ST_TYPE
235#define ELF_ST_TYPE(x) ((x) & 0xf)
236#define ELF_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf))
237#define ELF32_ST_INFO(b,t) ELF_ST_INFO(b,t)
238#define ELF64_ST_INFO(b,t) ELF_ST_INFO(b,t)
239
Elliott Hughesa8a23f52017-10-31 17:22:41 -0700240/* http://www.sco.com/developers/gabi/latest/ch4.eheader.html */
241#define EM_S370 9
242#define EM_VPP500 17
243#define EM_960 19
244#define EM_V800 36
245#define EM_FR20 37
246#define EM_RH32 38
247#define EM_RCE 39
248#define EM_FAKE_ALPHA 41
249#define EM_TRICORE 44
250#define EM_ARC 45
251#define EM_H8_300H 47
252#define EM_H8S 48
253#define EM_H8_500 49
254#define EM_MIPS_X 51
255#define EM_COLDFIRE 52
256#define EM_68HC12 53
257#define EM_MMA 54
258#define EM_PCP 55
259#define EM_NCPU 56
260#define EM_NDR1 57
261#define EM_STARCORE 58
262#define EM_ME16 59
263#define EM_ST100 60
264#define EM_TINYJ 61
265#define EM_PDSP 63
266#define EM_PDP10 64
267#define EM_PDP11 65
268#define EM_FX66 66
269#define EM_ST9PLUS 67
270#define EM_ST7 68
271#define EM_68HC16 69
272#define EM_68HC11 70
273#define EM_68HC08 71
274#define EM_68HC05 72
275#define EM_SVX 73
276#define EM_ST19 74
277#define EM_VAX 75
278#define EM_JAVELIN 77
279#define EM_FIREPATH 78
280#define EM_ZSP 79
281#define EM_MMIX 80
282#define EM_HUANY 81
283#define EM_PRISM 82
284#define EM_AVR 83
285#define EM_FR30 84
286#define EM_D10V 85
287#define EM_D30V 86
288#define EM_V850 87
289#define EM_MN10200 90
290#define EM_PJ 91
291#define EM_ARC_COMPACT 93
292#define EM_XTENSA 94
293#define EM_VIDEOCORE 95
294#define EM_TMM_GPP 96
295#define EM_NS32K 97
296#define EM_TPC 98
297#define EM_SNP1K 99
298#define EM_ST200 100
299#define EM_IP2K 101
300#define EM_MAX 102
301#define EM_CR 103
302#define EM_F2MC16 104
303#define EM_MSP430 105
304#define EM_SE_C33 107
305#define EM_SEP 108
306#define EM_ARCA 109
307#define EM_UNICORE 110
308#define EM_EXCESS 111
309#define EM_DXP 112
310#define EM_CRX 114
311#define EM_XGATE 115
312#define EM_C166 116
313#define EM_M16C 117
314#define EM_DSPIC30F 118
315#define EM_CE 119
316#define EM_M32C 120
317#define EM_TSK3000 131
318#define EM_RS08 132
319#define EM_SHARC 133
320#define EM_ECOG2 134
321#define EM_SCORE7 135
322#define EM_DSP24 136
323#define EM_VIDEOCORE3 137
324#define EM_LATTICEMICO32 138
325#define EM_SE_C17 139
326#define EM_TI_C2000 141
327#define EM_TI_C5500 142
328#define EM_MMDSP_PLUS 160
329#define EM_CYPRESS_M8C 161
330#define EM_R32C 162
331#define EM_TRIMEDIA 163
332#define EM_QDSP6 164
333#define EM_8051 165
334#define EM_STXP7X 166
335#define EM_NDS32 167
336#define EM_ECOG1 168
337#define EM_ECOG1X 168
338#define EM_MAXQ30 169
339#define EM_XIMO16 170
340#define EM_MANIK 171
341#define EM_CRAYNV2 172
342#define EM_RX 173
343#define EM_METAG 174
344#define EM_MCST_ELBRUS 175
345#define EM_ECOG16 176
346#define EM_CR16 177
347#define EM_ETPU 178
348#define EM_SLE9X 179
349#define EM_L10M 180
350#define EM_K10M 181
351#define EM_AVR32 185
352#define EM_STM8 186
353#define EM_TILE64 187
354#define EM_CUDA 190
355#define EM_CLOUDSHIELD 192
356#define EM_COREA_1ST 193
357#define EM_COREA_2ND 194
358#define EM_ARC_COMPACT2 195
359#define EM_OPEN8 196
360#define EM_RL78 197
361#define EM_VIDEOCORE5 198
362#define EM_78KOR 199
363#define EM_56800EX 200
364#define EM_BA1 201
365#define EM_BA2 202
366#define EM_XCORE 203
367#define EM_MCHP_PIC 204
368#define EM_INTEL205 205
369#define EM_INTEL206 206
370#define EM_INTEL207 207
371#define EM_INTEL208 208
372#define EM_INTEL209 209
373#define EM_KM32 210
374#define EM_KMX32 211
375#define EM_KMX16 212
376#define EM_KMX8 213
377#define EM_KVARC 214
378#define EM_CDP 215
379#define EM_COGE 216
380#define EM_COOL 217
381#define EM_NORC 218
382#define EM_CSR_KALIMBA 219
383#define EM_Z80 220
384#define EM_VISIUM 221
385#define EM_FT32 222
386#define EM_MOXIE 223
387#define EM_AMDGPU 224
388#define EM_RISCV 243
Elliott Hughes0266ae52014-02-10 17:46:57 -0800389
Elliott Hughesa8a23f52017-10-31 17:22:41 -0700390/* http://www.sco.com/developers/gabi/latest/ch4.eheader.html */
391#define ET_LOOS 0xfe00
392#define ET_HIOS 0xfeff
Dmitriy Ivanov13ed3f02015-02-13 16:25:43 -0800393
Elliott Hughesa8a23f52017-10-31 17:22:41 -0700394/* http://www.sco.com/developers/gabi/latest/ch4.sheader.html */
395#define GRP_COMDAT 0x1
396#define GRP_MASKOS 0x0ff00000
397#define GRP_MASKPROC 0xf0000000
Greg Hackmann8874d882017-10-31 13:25:03 -0700398
Elliott Hughesa8a23f52017-10-31 17:22:41 -0700399/* http://www.sco.com/developers/gabi/latest/ch5.pheader.html */
400#define PF_X 0x1
401#define PF_W 0x2
402#define PF_R 0x4
403#define PF_MASKOS 0x0ff00000
404#define PF_MASKPROC 0xf0000000
405
406#define PT_GNU_RELRO 0x6474e552
407
408#define STB_LOOS 10
409#define STB_HIOS 12
410#define STB_LOPROC 13
411#define STB_HIPROC 15
412
413/* http://www.sco.com/developers/gabi/latest/ch4.sheader.html */
414#define SHF_MERGE 0x10
415#define SHF_STRINGS 0x20
416#define SHF_INFO_LINK 0x40
417#define SHF_LINK_ORDER 0x80
418#define SHF_OS_NONCONFORMING 0x100
419#define SHF_GROUP 0x200
420#define SHF_TLS 0x400
421#define SHF_COMPRESSED 0x800
422#define SHF_MASKOS 0x0ff00000
423#define SHF_MASKPROC 0xf0000000
424
425/* http://www.sco.com/developers/gabi/latest/ch4.sheader.html */
426#define SHN_LOOS 0xff20
427#define SHN_HIOS 0xff3f
428#define SHN_XINDEX 0xffff
429
430/* http://www.sco.com/developers/gabi/latest/ch4.sheader.html */
431#define SHT_INIT_ARRAY 14
432#define SHT_FINI_ARRAY 15
433#define SHT_PREINIT_ARRAY 16
434#define SHT_GROUP 17
435#define SHT_SYMTAB_SHNDX 18
436#undef SHT_NUM
437#define SHT_NUM 19
438#define SHT_LOOS 0x60000000
439#define SHT_HIOS 0x6fffffff
440
441/* http://www.sco.com/developers/gabi/latest/ch4.symtab.html */
442#define STN_UNDEF 0
443
444/* http://www.sco.com/developers/gabi/latest/ch4.symtab.html */
Brigid Smithc5a13ef2014-07-23 11:22:25 -0700445#define STT_GNU_IFUNC 10
Elliott Hughesa8a23f52017-10-31 17:22:41 -0700446#define STT_LOOS 10
447#define STT_HIOS 12
448#define STT_LOPROC 13
449#define STT_HIPROC 15
Brigid Smithc5a13ef2014-07-23 11:22:25 -0700450
Elliott Hughesa8a23f52017-10-31 17:22:41 -0700451/* http://www.sco.com/developers/gabi/latest/ch4.symtab.html */
452#define STV_DEFAULT 0
453#define STV_INTERNAL 1
454#define STV_HIDDEN 2
Dmitriy Ivanovdbe26fd2015-05-04 19:30:49 -0700455#define STV_PROTECTED 3
456
Dmitriy Ivanova6bee4d2014-10-13 12:23:55 -0700457/* The kernel uses NT_PRFPREG but glibc also offers NT_FPREGSET */
458#define NT_FPREGSET NT_PRFPREG
459
Christopher Ferrisc94c7ff2015-03-13 10:32:45 -0700460#define ELF_NOTE_GNU "GNU"
461
462#define NT_GNU_BUILD_ID 3
463
Dmitriy Ivanov2a815362015-04-09 13:42:33 -0700464#define VER_FLG_BASE 0x1
465#define VER_FLG_WEAK 0x2
466
Elliott Hughesa8a23f52017-10-31 17:22:41 -0700467#define VER_NDX_LOCAL 0
Dmitriy Ivanov2a815362015-04-09 13:42:33 -0700468#define VER_NDX_GLOBAL 1
469
Elliott Hughesc6200592013-09-30 18:43:46 -0700470#endif /* _ELF_H */