blob: 6802428ac42a4185fddab39e6dce7610b6381ea1 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: BSD-3-Clause */
wdenka2cecab2002-09-30 20:45:01 +00002/*
3 * Copyright (c) 1995, 1996, 2001, 2002
4 * Erik Theisen. All rights reserved.
wdenka2cecab2002-09-30 20:45:01 +00005 */
6
Bin Meng4d216972018-04-11 22:02:12 -07007/* This is the ELF ABI header file formerly known as "elf_abi.h" */
wdenka2cecab2002-09-30 20:45:01 +00008
9#ifndef _ELF_H
10#define _ELF_H
11
Simon Glass631c1a22016-11-07 08:47:09 -070012#ifndef __ASSEMBLER__
Mike Frysinger4ad8e9f2009-07-02 19:23:25 -040013#include "compiler.h"
wdenka2cecab2002-09-30 20:45:01 +000014
Bin Meng4d216972018-04-11 22:02:12 -070015/* This version doesn't work for 64-bit ABIs - Erik */
wdenka2cecab2002-09-30 20:45:01 +000016
Bin Meng4d216972018-04-11 22:02:12 -070017/* These typedefs need to be handled better */
wdenka2cecab2002-09-30 20:45:01 +000018typedef uint32_t Elf32_Addr; /* Unsigned program address */
19typedef uint32_t Elf32_Off; /* Unsigned file offset */
20typedef int32_t Elf32_Sword; /* Signed large integer */
21typedef uint32_t Elf32_Word; /* Unsigned large integer */
22typedef uint16_t Elf32_Half; /* Unsigned medium integer */
23
Bin Meng4d216972018-04-11 22:02:12 -070024/* 64-bit ELF base types */
Simon Glass3ed7dda2015-07-31 09:31:21 -060025typedef uint64_t Elf64_Addr;
26typedef uint16_t Elf64_Half;
27typedef int16_t Elf64_SHalf;
28typedef uint64_t Elf64_Off;
29typedef int32_t Elf64_Sword;
30typedef uint32_t Elf64_Word;
31typedef uint64_t Elf64_Xword;
32typedef int64_t Elf64_Sxword;
33
wdenka2cecab2002-09-30 20:45:01 +000034/* e_ident[] identification indexes */
35#define EI_MAG0 0 /* file ID */
36#define EI_MAG1 1 /* file ID */
37#define EI_MAG2 2 /* file ID */
38#define EI_MAG3 3 /* file ID */
39#define EI_CLASS 4 /* file class */
40#define EI_DATA 5 /* data encoding */
41#define EI_VERSION 6 /* ELF header version */
42#define EI_OSABI 7 /* OS/ABI specific ELF extensions */
43#define EI_ABIVERSION 8 /* ABI target version */
44#define EI_PAD 9 /* start of pad bytes */
45#define EI_NIDENT 16 /* Size of e_ident[] */
46
47/* e_ident[] magic number */
48#define ELFMAG0 0x7f /* e_ident[EI_MAG0] */
49#define ELFMAG1 'E' /* e_ident[EI_MAG1] */
50#define ELFMAG2 'L' /* e_ident[EI_MAG2] */
51#define ELFMAG3 'F' /* e_ident[EI_MAG3] */
52#define ELFMAG "\177ELF" /* magic */
53#define SELFMAG 4 /* size of magic */
54
55/* e_ident[] file class */
56#define ELFCLASSNONE 0 /* invalid */
57#define ELFCLASS32 1 /* 32-bit objs */
58#define ELFCLASS64 2 /* 64-bit objs */
59#define ELFCLASSNUM 3 /* number of classes */
60
61/* e_ident[] data encoding */
62#define ELFDATANONE 0 /* invalid */
63#define ELFDATA2LSB 1 /* Little-Endian */
64#define ELFDATA2MSB 2 /* Big-Endian */
65#define ELFDATANUM 3 /* number of data encode defines */
66
67/* e_ident[] OS/ABI specific ELF extensions */
68#define ELFOSABI_NONE 0 /* No extension specified */
69#define ELFOSABI_HPUX 1 /* Hewlett-Packard HP-UX */
70#define ELFOSABI_NETBSD 2 /* NetBSD */
71#define ELFOSABI_LINUX 3 /* Linux */
72#define ELFOSABI_SOLARIS 6 /* Sun Solaris */
73#define ELFOSABI_AIX 7 /* AIX */
74#define ELFOSABI_IRIX 8 /* IRIX */
75#define ELFOSABI_FREEBSD 9 /* FreeBSD */
76#define ELFOSABI_TRU64 10 /* Compaq TRU64 UNIX */
77#define ELFOSABI_MODESTO 11 /* Novell Modesto */
78#define ELFOSABI_OPENBSD 12 /* OpenBSD */
79/* 64-255 Architecture-specific value range */
80
81/* e_ident[] ABI Version */
82#define ELFABIVERSION 0
83
84/* e_ident */
85#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
wdenk57b2d802003-06-27 21:31:46 +000086 (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
87 (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
88 (ehdr).e_ident[EI_MAG3] == ELFMAG3)
wdenka2cecab2002-09-30 20:45:01 +000089
90/* ELF Header */
Bin Meng4d216972018-04-11 22:02:12 -070091typedef struct {
wdenka2cecab2002-09-30 20:45:01 +000092 unsigned char e_ident[EI_NIDENT]; /* ELF Identification */
93 Elf32_Half e_type; /* object file type */
94 Elf32_Half e_machine; /* machine */
95 Elf32_Word e_version; /* object file version */
96 Elf32_Addr e_entry; /* virtual entry point */
97 Elf32_Off e_phoff; /* program header table offset */
98 Elf32_Off e_shoff; /* section header table offset */
99 Elf32_Word e_flags; /* processor-specific flags */
100 Elf32_Half e_ehsize; /* ELF header size */
101 Elf32_Half e_phentsize; /* program header entry size */
102 Elf32_Half e_phnum; /* number of program header entries */
103 Elf32_Half e_shentsize; /* section header entry size */
104 Elf32_Half e_shnum; /* number of section header entries */
105 Elf32_Half e_shstrndx; /* section header table's "section
106 header string table" entry offset */
107} Elf32_Ehdr;
108
Bin Meng6291ba12018-04-11 22:02:13 -0700109typedef struct {
110 unsigned char e_ident[EI_NIDENT]; /* ELF Identification */
111 Elf64_Half e_type; /* object file type */
112 Elf64_Half e_machine; /* machine */
113 Elf64_Word e_version; /* object file version */
114 Elf64_Addr e_entry; /* virtual entry point */
115 Elf64_Off e_phoff; /* program header table offset */
116 Elf64_Off e_shoff; /* section header table offset */
117 Elf64_Word e_flags; /* processor-specific flags */
118 Elf64_Half e_ehsize; /* ELF header size */
119 Elf64_Half e_phentsize; /* program header entry size */
120 Elf64_Half e_phnum; /* number of program header entries */
121 Elf64_Half e_shentsize; /* section header entry size */
122 Elf64_Half e_shnum; /* number of section header entries */
123 Elf64_Half e_shstrndx; /* section header table's "section
124 header string table" entry offset */
125} Elf64_Ehdr;
126
wdenka2cecab2002-09-30 20:45:01 +0000127/* e_type */
128#define ET_NONE 0 /* No file type */
129#define ET_REL 1 /* relocatable file */
130#define ET_EXEC 2 /* executable file */
131#define ET_DYN 3 /* shared object file */
132#define ET_CORE 4 /* core file */
133#define ET_NUM 5 /* number of types */
134#define ET_LOOS 0xfe00 /* reserved range for operating */
Bin Meng4d216972018-04-11 22:02:12 -0700135#define ET_HIOS 0xfeff /* system specific e_type */
wdenka2cecab2002-09-30 20:45:01 +0000136#define ET_LOPROC 0xff00 /* reserved range for processor */
Bin Meng4d216972018-04-11 22:02:12 -0700137#define ET_HIPROC 0xffff /* specific e_type */
wdenka2cecab2002-09-30 20:45:01 +0000138
139/* e_machine */
140#define EM_NONE 0 /* No Machine */
141#define EM_M32 1 /* AT&T WE 32100 */
142#define EM_SPARC 2 /* SPARC */
143#define EM_386 3 /* Intel 80386 */
144#define EM_68K 4 /* Motorola 68000 */
145#define EM_88K 5 /* Motorola 88000 */
146#if 0
147#define EM_486 6 /* RESERVED - was Intel 80486 */
148#endif
149#define EM_860 7 /* Intel 80860 */
150#define EM_MIPS 8 /* MIPS R3000 Big-Endian only */
151#define EM_S370 9 /* IBM System/370 Processor */
152#define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */
153#if 0
154#define EM_SPARC64 11 /* RESERVED - was SPARC v9
155 64-bit unoffical */
156#endif
157/* RESERVED 11-14 for future use */
158#define EM_PARISC 15 /* HPPA */
159/* RESERVED 16 for future use */
160#define EM_VPP500 17 /* Fujitsu VPP500 */
161#define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */
162#define EM_960 19 /* Intel 80960 */
163#define EM_PPC 20 /* PowerPC */
164#define EM_PPC64 21 /* 64-bit PowerPC */
165#define EM_S390 22 /* IBM System/390 Processor */
166/* RESERVED 23-35 for future use */
167#define EM_V800 36 /* NEC V800 */
168#define EM_FR20 37 /* Fujitsu FR20 */
169#define EM_RH32 38 /* TRW RH-32 */
170#define EM_RCE 39 /* Motorola RCE */
171#define EM_ARM 40 /* Advanced Risc Machines ARM */
172#define EM_ALPHA 41 /* Digital Alpha */
173#define EM_SH 42 /* Hitachi SH */
174#define EM_SPARCV9 43 /* SPARC Version 9 */
175#define EM_TRICORE 44 /* Siemens TriCore embedded processor */
176#define EM_ARC 45 /* Argonaut RISC Core */
177#define EM_H8_300 46 /* Hitachi H8/300 */
178#define EM_H8_300H 47 /* Hitachi H8/300H */
179#define EM_H8S 48 /* Hitachi H8S */
180#define EM_H8_500 49 /* Hitachi H8/500 */
181#define EM_IA_64 50 /* Intel Merced */
182#define EM_MIPS_X 51 /* Stanford MIPS-X */
183#define EM_COLDFIRE 52 /* Motorola Coldfire */
184#define EM_68HC12 53 /* Motorola M68HC12 */
185#define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator*/
186#define EM_PCP 55 /* Siemens PCP */
187#define EM_NCPU 56 /* Sony nCPU embeeded RISC */
188#define EM_NDR1 57 /* Denso NDR1 microprocessor */
189#define EM_STARCORE 58 /* Motorola Start*Core processor */
190#define EM_ME16 59 /* Toyota ME16 processor */
191#define EM_ST100 60 /* STMicroelectronic ST100 processor */
192#define EM_TINYJ 61 /* Advanced Logic Corp. Tinyj emb.fam*/
193#define EM_X86_64 62 /* AMD x86-64 */
194#define EM_PDSP 63 /* Sony DSP Processor */
195/* RESERVED 64,65 for future use */
196#define EM_FX66 66 /* Siemens FX66 microcontroller */
197#define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 mc */
198#define EM_ST7 68 /* STmicroelectronics ST7 8 bit mc */
199#define EM_68HC16 69 /* Motorola MC68HC16 microcontroller */
200#define EM_68HC11 70 /* Motorola MC68HC11 microcontroller */
201#define EM_68HC08 71 /* Motorola MC68HC08 microcontroller */
202#define EM_68HC05 72 /* Motorola MC68HC05 microcontroller */
203#define EM_SVX 73 /* Silicon Graphics SVx */
204#define EM_ST19 74 /* STMicroelectronics ST19 8 bit mc */
205#define EM_VAX 75 /* Digital VAX */
206#define EM_CHRIS 76 /* Axis Communications embedded proc. */
207#define EM_JAVELIN 77 /* Infineon Technologies emb. proc. */
208#define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor */
209#define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor */
210#define EM_MMIX 80 /* Donald Knuth's edu 64-bit proc. */
211#define EM_HUANY 81 /* Harvard University mach-indep objs */
212#define EM_PRISM 82 /* SiTera Prism */
213#define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */
214#define EM_FR30 84 /* Fujitsu FR30 */
215#define EM_D10V 85 /* Mitsubishi DV10V */
216#define EM_D30V 86 /* Mitsubishi DV30V */
217#define EM_V850 87 /* NEC v850 */
218#define EM_M32R 88 /* Mitsubishi M32R */
219#define EM_MN10300 89 /* Matsushita MN10200 */
220#define EM_MN10200 90 /* Matsushita MN10200 */
221#define EM_PJ 91 /* picoJava */
222#define EM_NUM 92 /* number of machine types */
223
224/* Version */
225#define EV_NONE 0 /* Invalid */
226#define EV_CURRENT 1 /* Current */
227#define EV_NUM 2 /* number of versions */
228
229/* Section Header */
230typedef struct {
231 Elf32_Word sh_name; /* name - index into section header
232 string table section */
233 Elf32_Word sh_type; /* type */
234 Elf32_Word sh_flags; /* flags */
235 Elf32_Addr sh_addr; /* address */
236 Elf32_Off sh_offset; /* file offset */
237 Elf32_Word sh_size; /* section size */
238 Elf32_Word sh_link; /* section header table index link */
239 Elf32_Word sh_info; /* extra information */
240 Elf32_Word sh_addralign; /* address alignment */
241 Elf32_Word sh_entsize; /* section entry size */
242} Elf32_Shdr;
243
Bin Meng6291ba12018-04-11 22:02:13 -0700244typedef struct {
245 Elf64_Word sh_name; /* name - index into section header
246 string table section */
247 Elf64_Word sh_type; /* type */
248 Elf64_Xword sh_flags; /* flags */
249 Elf64_Addr sh_addr; /* address */
250 Elf64_Off sh_offset; /* file offset */
251 Elf64_Xword sh_size; /* section size */
252 Elf64_Word sh_link; /* section header table index link */
253 Elf64_Word sh_info; /* extra information */
254 Elf64_Xword sh_addralign; /* address alignment */
255 Elf64_Xword sh_entsize; /* section entry size */
256} Elf64_Shdr;
257
wdenka2cecab2002-09-30 20:45:01 +0000258/* Special Section Indexes */
259#define SHN_UNDEF 0 /* undefined */
260#define SHN_LORESERVE 0xff00 /* lower bounds of reserved indexes */
261#define SHN_LOPROC 0xff00 /* reserved range for processor */
Bin Meng4d216972018-04-11 22:02:12 -0700262#define SHN_HIPROC 0xff1f /* specific section indexes */
wdenka2cecab2002-09-30 20:45:01 +0000263#define SHN_LOOS 0xff20 /* reserved range for operating */
Bin Meng4d216972018-04-11 22:02:12 -0700264#define SHN_HIOS 0xff3f /* specific semantics */
wdenka2cecab2002-09-30 20:45:01 +0000265#define SHN_ABS 0xfff1 /* absolute value */
266#define SHN_COMMON 0xfff2 /* common symbol */
267#define SHN_XINDEX 0xffff /* Index is an extra table */
268#define SHN_HIRESERVE 0xffff /* upper bounds of reserved indexes */
269
270/* sh_type */
271#define SHT_NULL 0 /* inactive */
272#define SHT_PROGBITS 1 /* program defined information */
273#define SHT_SYMTAB 2 /* symbol table section */
274#define SHT_STRTAB 3 /* string table section */
275#define SHT_RELA 4 /* relocation section with addends*/
276#define SHT_HASH 5 /* symbol hash table section */
277#define SHT_DYNAMIC 6 /* dynamic section */
278#define SHT_NOTE 7 /* note section */
279#define SHT_NOBITS 8 /* no space section */
280#define SHT_REL 9 /* relation section without addends */
281#define SHT_SHLIB 10 /* reserved - purpose unknown */
282#define SHT_DYNSYM 11 /* dynamic symbol table section */
283#define SHT_INIT_ARRAY 14 /* Array of constructors */
284#define SHT_FINI_ARRAY 15 /* Array of destructors */
285#define SHT_PREINIT_ARRAY 16 /* Array of pre-constructors */
286#define SHT_GROUP 17 /* Section group */
287#define SHT_SYMTAB_SHNDX 18 /* Extended section indeces */
288#define SHT_NUM 19 /* number of section types */
289#define SHT_LOOS 0x60000000 /* Start OS-specific */
290#define SHT_HIOS 0x6fffffff /* End OS-specific */
291#define SHT_LOPROC 0x70000000 /* reserved range for processor */
Bin Meng4d216972018-04-11 22:02:12 -0700292#define SHT_HIPROC 0x7fffffff /* specific section header types */
wdenka2cecab2002-09-30 20:45:01 +0000293#define SHT_LOUSER 0x80000000 /* reserved range for application */
Bin Meng4d216972018-04-11 22:02:12 -0700294#define SHT_HIUSER 0xffffffff /* specific indexes */
wdenka2cecab2002-09-30 20:45:01 +0000295
296/* Section names */
Bin Meng4d216972018-04-11 22:02:12 -0700297#define ELF_BSS ".bss" /* uninitialized data */
wdenka2cecab2002-09-30 20:45:01 +0000298#define ELF_COMMENT ".comment" /* version control information */
Bin Meng4d216972018-04-11 22:02:12 -0700299#define ELF_DATA ".data" /* initialized data */
300#define ELF_DATA1 ".data1" /* initialized data */
301#define ELF_DEBUG ".debug" /* debug */
302#define ELF_DYNAMIC ".dynamic" /* dynamic linking information */
303#define ELF_DYNSTR ".dynstr" /* dynamic string table */
304#define ELF_DYNSYM ".dynsym" /* dynamic symbol table */
305#define ELF_FINI ".fini" /* termination code */
wdenka2cecab2002-09-30 20:45:01 +0000306#define ELF_FINI_ARRAY ".fini_array" /* Array of destructors */
Bin Meng4d216972018-04-11 22:02:12 -0700307#define ELF_GOT ".got" /* global offset table */
308#define ELF_HASH ".hash" /* symbol hash table */
309#define ELF_INIT ".init" /* initialization code */
wdenka2cecab2002-09-30 20:45:01 +0000310#define ELF_INIT_ARRAY ".init_array" /* Array of constuctors */
311#define ELF_INTERP ".interp" /* Pathname of program interpreter */
312#define ELF_LINE ".line" /* Symbolic line numnber information */
313#define ELF_NOTE ".note" /* Contains note section */
314#define ELF_PLT ".plt" /* Procedure linkage table */
315#define ELF_PREINIT_ARRAY ".preinit_array" /* Array of pre-constructors */
Bin Meng4d216972018-04-11 22:02:12 -0700316#define ELF_REL_DATA ".rel.data" /* relocation data */
317#define ELF_REL_FINI ".rel.fini" /* relocation termination code */
318#define ELF_REL_INIT ".rel.init" /* relocation initialization code */
319#define ELF_REL_DYN ".rel.dyn" /* relocaltion dynamic link info */
320#define ELF_REL_RODATA ".rel.rodata" /* relocation read-only data */
321#define ELF_REL_TEXT ".rel.text" /* relocation code */
322#define ELF_RODATA ".rodata" /* read-only data */
323#define ELF_RODATA1 ".rodata1" /* read-only data */
324#define ELF_SHSTRTAB ".shstrtab" /* section header string table */
325#define ELF_STRTAB ".strtab" /* string table */
326#define ELF_SYMTAB ".symtab" /* symbol table */
wdenka2cecab2002-09-30 20:45:01 +0000327#define ELF_SYMTAB_SHNDX ".symtab_shndx"/* symbol table section index */
328#define ELF_TBSS ".tbss" /* thread local uninit data */
329#define ELF_TDATA ".tdata" /* thread local init data */
330#define ELF_TDATA1 ".tdata1" /* thread local init data */
Bin Meng4d216972018-04-11 22:02:12 -0700331#define ELF_TEXT ".text" /* code */
wdenka2cecab2002-09-30 20:45:01 +0000332
333/* Section Attribute Flags - sh_flags */
334#define SHF_WRITE 0x1 /* Writable */
335#define SHF_ALLOC 0x2 /* occupies memory */
336#define SHF_EXECINSTR 0x4 /* executable */
337#define SHF_MERGE 0x10 /* Might be merged */
338#define SHF_STRINGS 0x20 /* Contains NULL terminated strings */
339#define SHF_INFO_LINK 0x40 /* sh_info contains SHT index */
340#define SHF_LINK_ORDER 0x80 /* Preserve order after combining*/
341#define SHF_OS_NONCONFORMING 0x100 /* Non-standard OS specific handling */
342#define SHF_GROUP 0x200 /* Member of section group */
343#define SHF_TLS 0x400 /* Thread local storage */
344#define SHF_MASKOS 0x0ff00000 /* OS specific */
345#define SHF_MASKPROC 0xf0000000 /* reserved bits for processor */
Bin Meng4d216972018-04-11 22:02:12 -0700346 /* specific section attributes */
wdenka2cecab2002-09-30 20:45:01 +0000347
348/* Section Group Flags */
349#define GRP_COMDAT 0x1 /* COMDAT group */
350#define GRP_MASKOS 0x0ff00000 /* Mask OS specific flags */
351#define GRP_MASKPROC 0xf0000000 /* Mask processor specific flags */
352
353/* Symbol Table Entry */
Bin Meng4d216972018-04-11 22:02:12 -0700354typedef struct {
wdenka2cecab2002-09-30 20:45:01 +0000355 Elf32_Word st_name; /* name - index into string table */
356 Elf32_Addr st_value; /* symbol value */
357 Elf32_Word st_size; /* symbol size */
358 unsigned char st_info; /* type and binding */
359 unsigned char st_other; /* 0 - no defined meaning */
360 Elf32_Half st_shndx; /* section header index */
361} Elf32_Sym;
362
363/* Symbol table index */
364#define STN_UNDEF 0 /* undefined */
365
366/* Extract symbol info - st_info */
367#define ELF32_ST_BIND(x) ((x) >> 4)
368#define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf)
369#define ELF32_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf))
370#define ELF32_ST_VISIBILITY(x) ((x) & 0x3)
371
372/* Symbol Binding - ELF32_ST_BIND - st_info */
373#define STB_LOCAL 0 /* Local symbol */
374#define STB_GLOBAL 1 /* Global symbol */
375#define STB_WEAK 2 /* like global - lower precedence */
376#define STB_NUM 3 /* number of symbol bindings */
377#define STB_LOOS 10 /* reserved range for operating */
Bin Meng4d216972018-04-11 22:02:12 -0700378#define STB_HIOS 12 /* system specific symbol bindings */
wdenka2cecab2002-09-30 20:45:01 +0000379#define STB_LOPROC 13 /* reserved range for processor */
Bin Meng4d216972018-04-11 22:02:12 -0700380#define STB_HIPROC 15 /* specific symbol bindings */
wdenka2cecab2002-09-30 20:45:01 +0000381
382/* Symbol type - ELF32_ST_TYPE - st_info */
383#define STT_NOTYPE 0 /* not specified */
384#define STT_OBJECT 1 /* data object */
385#define STT_FUNC 2 /* function */
386#define STT_SECTION 3 /* section */
387#define STT_FILE 4 /* file */
388#define STT_NUM 5 /* number of symbol types */
389#define STT_TLS 6 /* Thread local storage symbol */
390#define STT_LOOS 10 /* reserved range for operating */
Bin Meng4d216972018-04-11 22:02:12 -0700391#define STT_HIOS 12 /* system specific symbol types */
wdenka2cecab2002-09-30 20:45:01 +0000392#define STT_LOPROC 13 /* reserved range for processor */
Bin Meng4d216972018-04-11 22:02:12 -0700393#define STT_HIPROC 15 /* specific symbol types */
wdenka2cecab2002-09-30 20:45:01 +0000394
395/* Symbol visibility - ELF32_ST_VISIBILITY - st_other */
396#define STV_DEFAULT 0 /* Normal visibility rules */
397#define STV_INTERNAL 1 /* Processor specific hidden class */
398#define STV_HIDDEN 2 /* Symbol unavailable in other mods */
399#define STV_PROTECTED 3 /* Not preemptible, not exported */
400
wdenka2cecab2002-09-30 20:45:01 +0000401/* Relocation entry with implicit addend */
Bin Meng4d216972018-04-11 22:02:12 -0700402typedef struct {
wdenka2cecab2002-09-30 20:45:01 +0000403 Elf32_Addr r_offset; /* offset of relocation */
404 Elf32_Word r_info; /* symbol table index and type */
405} Elf32_Rel;
406
407/* Relocation entry with explicit addend */
Bin Meng4d216972018-04-11 22:02:12 -0700408typedef struct {
wdenka2cecab2002-09-30 20:45:01 +0000409 Elf32_Addr r_offset; /* offset of relocation */
410 Elf32_Word r_info; /* symbol table index and type */
411 Elf32_Sword r_addend;
412} Elf32_Rela;
413
Simon Glass3ed7dda2015-07-31 09:31:21 -0600414typedef struct {
415 Elf64_Addr r_offset; /* Location at which to apply the action */
416 Elf64_Xword r_info; /* index and type of relocation */
417} Elf64_Rel;
418
Simon Glassd4efdff2016-09-25 21:33:09 -0600419typedef struct {
Bin Meng4d216972018-04-11 22:02:12 -0700420 Elf64_Addr r_offset; /* Location at which to apply the action */
421 Elf64_Xword r_info; /* index and type of relocation */
422 Elf64_Sxword r_addend; /* Constant addend used to compute value */
Simon Glassd4efdff2016-09-25 21:33:09 -0600423} Elf64_Rela;
424
wdenka2cecab2002-09-30 20:45:01 +0000425/* Extract relocation info - r_info */
426#define ELF32_R_SYM(i) ((i) >> 8)
427#define ELF32_R_TYPE(i) ((unsigned char) (i))
Wolfgang Denka1be4762008-05-20 16:00:29 +0200428#define ELF32_R_INFO(s,t) (((s) << 8) + (unsigned char)(t))
wdenka2cecab2002-09-30 20:45:01 +0000429
430/* Program Header */
431typedef struct {
432 Elf32_Word p_type; /* segment type */
433 Elf32_Off p_offset; /* segment offset */
434 Elf32_Addr p_vaddr; /* virtual address of segment */
Bin Meng4d216972018-04-11 22:02:12 -0700435 Elf32_Addr p_paddr; /* physical address of segment */
436 Elf32_Word p_filesz; /* number of bytes in file for seg */
437 Elf32_Word p_memsz; /* number of bytes in mem. for seg */
wdenka2cecab2002-09-30 20:45:01 +0000438 Elf32_Word p_flags; /* flags */
439 Elf32_Word p_align; /* memory alignment */
440} Elf32_Phdr;
441
Bin Meng6291ba12018-04-11 22:02:13 -0700442typedef struct {
443 Elf64_Word p_type; /* segment type */
444 Elf64_Word p_flags; /* flags */
445 Elf64_Off p_offset; /* segment offset */
446 Elf64_Addr p_vaddr; /* virtual address of segment */
447 Elf64_Addr p_paddr; /* physical address of segment */
448 Elf64_Xword p_filesz; /* number of bytes in file for seg */
449 Elf64_Xword p_memsz; /* number of bytes in mem. for seg */
450 Elf64_Xword p_align; /* memory alignment */
451} Elf64_Phdr;
452
wdenka2cecab2002-09-30 20:45:01 +0000453/* Segment types - p_type */
454#define PT_NULL 0 /* unused */
455#define PT_LOAD 1 /* loadable segment */
456#define PT_DYNAMIC 2 /* dynamic linking section */
457#define PT_INTERP 3 /* the RTLD */
458#define PT_NOTE 4 /* auxiliary information */
459#define PT_SHLIB 5 /* reserved - purpose undefined */
460#define PT_PHDR 6 /* program header */
461#define PT_TLS 7 /* Thread local storage template */
462#define PT_NUM 8 /* Number of segment types */
463#define PT_LOOS 0x60000000 /* reserved range for operating */
Bin Meng4d216972018-04-11 22:02:12 -0700464#define PT_HIOS 0x6fffffff /* system specific segment types */
wdenka2cecab2002-09-30 20:45:01 +0000465#define PT_LOPROC 0x70000000 /* reserved range for processor */
Bin Meng4d216972018-04-11 22:02:12 -0700466#define PT_HIPROC 0x7fffffff /* specific segment types */
wdenka2cecab2002-09-30 20:45:01 +0000467
468/* Segment flags - p_flags */
469#define PF_X 0x1 /* Executable */
470#define PF_W 0x2 /* Writable */
471#define PF_R 0x4 /* Readable */
472#define PF_MASKOS 0x0ff00000 /* OS specific segment flags */
473#define PF_MASKPROC 0xf0000000 /* reserved bits for processor */
Bin Meng4d216972018-04-11 22:02:12 -0700474 /* specific segment flags */
wdenka2cecab2002-09-30 20:45:01 +0000475/* Dynamic structure */
Bin Meng4d216972018-04-11 22:02:12 -0700476typedef struct {
wdenka2cecab2002-09-30 20:45:01 +0000477 Elf32_Sword d_tag; /* controls meaning of d_val */
Bin Meng4d216972018-04-11 22:02:12 -0700478 union {
wdenka2cecab2002-09-30 20:45:01 +0000479 Elf32_Word d_val; /* Multiple meanings - see d_tag */
480 Elf32_Addr d_ptr; /* program virtual address */
481 } d_un;
482} Elf32_Dyn;
483
484extern Elf32_Dyn _DYNAMIC[];
485
Simon Glass3ed7dda2015-07-31 09:31:21 -0600486typedef struct {
487 Elf64_Sxword d_tag; /* entry tag value */
488 union {
489 Elf64_Xword d_val;
490 Elf64_Addr d_ptr;
491 } d_un;
492} Elf64_Dyn;
493
494#define ELF64_R_SYM(i) ((i) >> 32)
495#define ELF64_R_TYPE(i) ((i) & 0xffffffff)
496
wdenka2cecab2002-09-30 20:45:01 +0000497/* Dynamic Array Tags - d_tag */
498#define DT_NULL 0 /* marks end of _DYNAMIC array */
499#define DT_NEEDED 1 /* string table offset of needed lib */
500#define DT_PLTRELSZ 2 /* size of relocation entries in PLT */
501#define DT_PLTGOT 3 /* address PLT/GOT */
502#define DT_HASH 4 /* address of symbol hash table */
503#define DT_STRTAB 5 /* address of string table */
504#define DT_SYMTAB 6 /* address of symbol table */
505#define DT_RELA 7 /* address of relocation table */
506#define DT_RELASZ 8 /* size of relocation table */
507#define DT_RELAENT 9 /* size of relocation entry */
508#define DT_STRSZ 10 /* size of string table */
509#define DT_SYMENT 11 /* size of symbol table entry */
Bin Meng4d216972018-04-11 22:02:12 -0700510#define DT_INIT 12 /* address of initialization func */
wdenka2cecab2002-09-30 20:45:01 +0000511#define DT_FINI 13 /* address of termination function */
512#define DT_SONAME 14 /* string table offset of shared obj */
513#define DT_RPATH 15 /* string table offset of library
514 search path */
Bin Meng4d216972018-04-11 22:02:12 -0700515#define DT_SYMBOLIC 16 /* start sym search in shared obj */
wdenka2cecab2002-09-30 20:45:01 +0000516#define DT_REL 17 /* address of rel. tbl. w addends */
517#define DT_RELSZ 18 /* size of DT_REL relocation table */
518#define DT_RELENT 19 /* size of DT_REL relocation entry */
519#define DT_PLTREL 20 /* PLT referenced relocation entry */
520#define DT_DEBUG 21 /* bugger */
521#define DT_TEXTREL 22 /* Allow rel. mod. to unwritable seg */
522#define DT_JMPREL 23 /* add. of PLT's relocation entries */
523#define DT_BIND_NOW 24 /* Process relocations of object */
524#define DT_INIT_ARRAY 25 /* Array with addresses of init fct */
525#define DT_FINI_ARRAY 26 /* Array with addresses of fini fct */
526#define DT_INIT_ARRAYSZ 27 /* Size in bytes of DT_INIT_ARRAY */
527#define DT_FINI_ARRAYSZ 28 /* Size in bytes of DT_FINI_ARRAY */
528#define DT_RUNPATH 29 /* Library search path */
529#define DT_FLAGS 30 /* Flags for the object being loaded */
530#define DT_ENCODING 32 /* Start of encoded range */
531#define DT_PREINIT_ARRAY 32 /* Array with addresses of preinit fct*/
532#define DT_PREINIT_ARRAYSZ 33 /* size in bytes of DT_PREINIT_ARRAY */
Bin Meng4d216972018-04-11 22:02:12 -0700533#define DT_NUM 34 /* Number used */
wdenka2cecab2002-09-30 20:45:01 +0000534#define DT_LOOS 0x60000000 /* reserved range for OS */
Bin Meng4d216972018-04-11 22:02:12 -0700535#define DT_HIOS 0x6fffffff /* specific dynamic array tags */
wdenka2cecab2002-09-30 20:45:01 +0000536#define DT_LOPROC 0x70000000 /* reserved range for processor */
Bin Meng4d216972018-04-11 22:02:12 -0700537#define DT_HIPROC 0x7fffffff /* specific dynamic array tags */
wdenka2cecab2002-09-30 20:45:01 +0000538
539/* Dynamic Tag Flags - d_un.d_val */
540#define DF_ORIGIN 0x01 /* Object may use DF_ORIGIN */
541#define DF_SYMBOLIC 0x02 /* Symbol resolutions starts here */
542#define DF_TEXTREL 0x04 /* Object contains text relocations */
543#define DF_BIND_NOW 0x08 /* No lazy binding for this object */
544#define DF_STATIC_TLS 0x10 /* Static thread local storage */
545
546/* Standard ELF hashing function */
547unsigned long elf_hash(const unsigned char *name);
548
549#define ELF_TARG_VER 1 /* The ver for which this code is intended */
550
Simon Glass631c1a22016-11-07 08:47:09 -0700551#endif /* __ASSEMBLER */
552
Alexander Grafaf915bf2018-06-18 17:23:10 +0200553/* ELF register definitions */
554#define R_386_NONE 0
555#define R_386_32 1
556#define R_386_PC32 2
557#define R_386_GOT32 3
558#define R_386_PLT32 4
559#define R_386_COPY 5
560#define R_386_GLOB_DAT 6
561#define R_386_JMP_SLOT 7
562#define R_386_RELATIVE 8
563#define R_386_GOTOFF 9
564#define R_386_GOTPC 10
565#define R_386_NUM 11
566
567/* x86-64 relocation types */
568#define R_X86_64_NONE 0 /* No reloc */
569#define R_X86_64_64 1 /* Direct 64 bit */
570#define R_X86_64_PC32 2 /* PC relative 32 bit signed */
571#define R_X86_64_GOT32 3 /* 32 bit GOT entry */
572#define R_X86_64_PLT32 4 /* 32 bit PLT address */
573#define R_X86_64_COPY 5 /* Copy symbol at runtime */
574#define R_X86_64_GLOB_DAT 6 /* Create GOT entry */
575#define R_X86_64_JUMP_SLOT 7 /* Create PLT entry */
576#define R_X86_64_RELATIVE 8 /* Adjust by program base */
577/* 32 bit signed pc relative offset to GOT */
578#define R_X86_64_GOTPCREL 9
579#define R_X86_64_32 10 /* Direct 32 bit zero extended */
580#define R_X86_64_32S 11 /* Direct 32 bit sign extended */
581#define R_X86_64_16 12 /* Direct 16 bit zero extended */
582#define R_X86_64_PC16 13 /* 16 bit sign extended pc relative */
583#define R_X86_64_8 14 /* Direct 8 bit sign extended */
584#define R_X86_64_PC8 15 /* 8 bit sign extended pc relative */
585
586#define R_X86_64_NUM 16
587
wdenka2cecab2002-09-30 20:45:01 +0000588/*
589 * XXX - PowerPC defines really don't belong in here,
590 * but we'll put them in for simplicity.
591 */
592
Bin Meng4d216972018-04-11 22:02:12 -0700593/* Values for Elf32/64_Ehdr.e_flags */
594#define EF_PPC_EMB 0x80000000 /* PowerPC embedded flag */
wdenka2cecab2002-09-30 20:45:01 +0000595
596/* Cygnus local bits below */
Bin Meng4d216972018-04-11 22:02:12 -0700597#define EF_PPC_RELOCATABLE 0x00010000 /* PowerPC -mrelocatable flag*/
598#define EF_PPC_RELOCATABLE_LIB 0x00008000 /* PowerPC -mrelocatable-lib
wdenk57b2d802003-06-27 21:31:46 +0000599 flag */
wdenka2cecab2002-09-30 20:45:01 +0000600
601/* PowerPC relocations defined by the ABIs */
Bin Meng4d216972018-04-11 22:02:12 -0700602#define R_PPC_NONE 0
603#define R_PPC_ADDR32 1 /* 32bit absolute address */
604#define R_PPC_ADDR24 2 /* 26bit address, 2 bits ignored */
605#define R_PPC_ADDR16 3 /* 16bit absolute address */
606#define R_PPC_ADDR16_LO 4 /* lower 16bit of absolute address */
607#define R_PPC_ADDR16_HI 5 /* high 16bit of absolute address */
608#define R_PPC_ADDR16_HA 6 /* adjusted high 16bit */
609#define R_PPC_ADDR14 7 /* 16bit address, 2 bits ignored */
610#define R_PPC_ADDR14_BRTAKEN 8
611#define R_PPC_ADDR14_BRNTAKEN 9
612#define R_PPC_REL24 10 /* PC relative 26 bit */
613#define R_PPC_REL14 11 /* PC relative 16 bit */
614#define R_PPC_REL14_BRTAKEN 12
615#define R_PPC_REL14_BRNTAKEN 13
616#define R_PPC_GOT16 14
617#define R_PPC_GOT16_LO 15
618#define R_PPC_GOT16_HI 16
619#define R_PPC_GOT16_HA 17
620#define R_PPC_PLTREL24 18
621#define R_PPC_COPY 19
622#define R_PPC_GLOB_DAT 20
623#define R_PPC_JMP_SLOT 21
624#define R_PPC_RELATIVE 22
625#define R_PPC_LOCAL24PC 23
626#define R_PPC_UADDR32 24
627#define R_PPC_UADDR16 25
628#define R_PPC_REL32 26
629#define R_PPC_PLT32 27
630#define R_PPC_PLTREL32 28
631#define R_PPC_PLT16_LO 29
632#define R_PPC_PLT16_HI 30
633#define R_PPC_PLT16_HA 31
634#define R_PPC_SDAREL16 32
635#define R_PPC_SECTOFF 33
636#define R_PPC_SECTOFF_LO 34
637#define R_PPC_SECTOFF_HI 35
638#define R_PPC_SECTOFF_HA 36
639/* Keep this the last entry */
640#define R_PPC_NUM 37
wdenka2cecab2002-09-30 20:45:01 +0000641
Bin Meng4d216972018-04-11 22:02:12 -0700642/*
643 * The remaining relocs are from the Embedded ELF ABI, and are not
644 * in the SVR4 ELF ABI.
645 */
646#define R_PPC_EMB_NADDR32 101
647#define R_PPC_EMB_NADDR16 102
648#define R_PPC_EMB_NADDR16_LO 103
649#define R_PPC_EMB_NADDR16_HI 104
650#define R_PPC_EMB_NADDR16_HA 105
651#define R_PPC_EMB_SDAI16 106
652#define R_PPC_EMB_SDA2I16 107
653#define R_PPC_EMB_SDA2REL 108
654#define R_PPC_EMB_SDA21 109 /* 16 bit offset in SDA */
655#define R_PPC_EMB_MRKREF 110
656#define R_PPC_EMB_RELSEC16 111
657#define R_PPC_EMB_RELST_LO 112
658#define R_PPC_EMB_RELST_HI 113
659#define R_PPC_EMB_RELST_HA 114
660#define R_PPC_EMB_BIT_FLD 115
661#define R_PPC_EMB_RELSDA 116 /* 16 bit relative offset in SDA */
wdenka2cecab2002-09-30 20:45:01 +0000662
Bin Meng4d216972018-04-11 22:02:12 -0700663/* Diab tool relocations */
664#define R_PPC_DIAB_SDA21_LO 180 /* like EMB_SDA21, but lower 16 bit */
665#define R_PPC_DIAB_SDA21_HI 181 /* like EMB_SDA21, but high 16 bit */
666#define R_PPC_DIAB_SDA21_HA 182 /* like EMB_SDA21, adjusted high 16 */
667#define R_PPC_DIAB_RELSDA_LO 183 /* like EMB_RELSDA, but lower 16 bit */
668#define R_PPC_DIAB_RELSDA_HI 184 /* like EMB_RELSDA, but high 16 bit */
669#define R_PPC_DIAB_RELSDA_HA 185 /* like EMB_RELSDA, adjusted high 16 */
wdenka2cecab2002-09-30 20:45:01 +0000670
Bin Meng4d216972018-04-11 22:02:12 -0700671/*
672 * This is a phony reloc to handle any old fashioned TOC16 references
673 * that may still be in object files.
674 */
675#define R_PPC_TOC16 255
wdenka2cecab2002-09-30 20:45:01 +0000676
Simon Glass631c1a22016-11-07 08:47:09 -0700677 /* ARM relocs */
678#define R_ARM_NONE 0 /* No reloc */
679#define R_ARM_RELATIVE 23 /* Adjust by program base */
680
681/* AArch64 relocs */
Bin Meng4d216972018-04-11 22:02:12 -0700682#define R_AARCH64_NONE 0 /* No relocation */
683#define R_AARCH64_RELATIVE 1027 /* Adjust by program base */
Simon Glass631c1a22016-11-07 08:47:09 -0700684
Rick Chen3301bfc2017-12-26 13:55:58 +0800685/* RISC-V relocations */
686#define R_RISCV_32 1
687#define R_RISCV_64 2
688#define R_RISCV_RELATIVE 3
689
Simon Glass631c1a22016-11-07 08:47:09 -0700690#ifndef __ASSEMBLER__
Jeroen Hofsteeb57fb1b2014-10-08 22:58:01 +0200691int valid_elf_image(unsigned long addr);
Simon Glass631c1a22016-11-07 08:47:09 -0700692#endif
Jeroen Hofsteeb57fb1b2014-10-08 22:58:01 +0200693
wdenka2cecab2002-09-30 20:45:01 +0000694#endif /* _ELF_H */