]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/C/GenFw/elf64.h
BaseTools/GenFw: Add X64 GOTPCREL Support to GenFw
[mirror_edk2.git] / BaseTools / Source / C / GenFw / elf64.h
CommitLineData
f51461c8
LG
1/** @file\r
2Ported ELF include files from FreeBSD\r
3\r
4Copyright (c) 2009 - 2010, Apple Inc. All rights reserved.<BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14/*-\r
15 * Copyright (c) 1996-1998 John D. Polstra.\r
16 * All rights reserved.\r
17 *\r
18 * Redistribution and use in source and binary forms, with or without\r
19 * modification, are permitted provided that the following conditions\r
20 * are met:\r
21 * 1. Redistributions of source code must retain the above copyright\r
22 * notice, this list of conditions and the following disclaimer.\r
23 * 2. Redistributions in binary form must reproduce the above copyright\r
24 * notice, this list of conditions and the following disclaimer in the\r
25 * documentation and/or other materials provided with the distribution.\r
26 *\r
27 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
37 * SUCH DAMAGE.\r
38 *\r
39 * $FreeBSD: src/sys/sys/elf64.h,v 1.10.14.2 2007/12/03 21:30:36 marius Exp $\r
40 */\r
41\r
42#ifndef _SYS_ELF64_H_\r
43#define _SYS_ELF64_H_ 1\r
44\r
45\r
46/*\r
47 * ELF definitions common to all 64-bit architectures.\r
48 */\r
49\r
f7496d71
LG
50typedef UINT64 Elf64_Addr;\r
51typedef UINT16 Elf64_Half;\r
52typedef UINT64 Elf64_Off;\r
53typedef INT32 Elf64_Sword;\r
54typedef INT64 Elf64_Sxword;\r
55typedef UINT32 Elf64_Word;\r
56typedef UINT64 Elf64_Lword;\r
57typedef UINT64 Elf64_Xword;\r
f51461c8
LG
58\r
59/*\r
60 * Types of dynamic symbol hash table bucket and chain elements.\r
61 *\r
62 * This is inconsistent among 64 bit architectures, so a machine dependent\r
63 * typedef is required.\r
64 */\r
65\r
f7496d71 66typedef Elf64_Word Elf64_Hashelt;\r
f51461c8
LG
67\r
68/* Non-standard class-dependent datatype used for abstraction. */\r
f7496d71
LG
69typedef Elf64_Xword Elf64_Size;\r
70typedef Elf64_Sxword Elf64_Ssize;\r
f51461c8
LG
71\r
72/*\r
73 * ELF header.\r
74 */\r
75\r
76typedef struct {\r
f7496d71
LG
77 unsigned char e_ident[EI_NIDENT]; /* File identification. */\r
78 Elf64_Half e_type; /* File type. */\r
79 Elf64_Half e_machine; /* Machine architecture. */\r
80 Elf64_Word e_version; /* ELF format version. */\r
81 Elf64_Addr e_entry; /* Entry point. */\r
82 Elf64_Off e_phoff; /* Program header file offset. */\r
83 Elf64_Off e_shoff; /* Section header file offset. */\r
84 Elf64_Word e_flags; /* Architecture-specific flags. */\r
85 Elf64_Half e_ehsize; /* Size of ELF header in bytes. */\r
86 Elf64_Half e_phentsize; /* Size of program header entry. */\r
87 Elf64_Half e_phnum; /* Number of program header entries. */\r
88 Elf64_Half e_shentsize; /* Size of section header entry. */\r
89 Elf64_Half e_shnum; /* Number of section header entries. */\r
90 Elf64_Half e_shstrndx; /* Section name strings section. */\r
f51461c8
LG
91} Elf64_Ehdr;\r
92\r
93/*\r
94 * Section header.\r
95 */\r
96\r
97typedef struct {\r
f7496d71
LG
98 Elf64_Word sh_name; /* Section name (index into the\r
99 section header string table). */\r
100 Elf64_Word sh_type; /* Section type. */\r
101 Elf64_Xword sh_flags; /* Section flags. */\r
102 Elf64_Addr sh_addr; /* Address in memory image. */\r
103 Elf64_Off sh_offset; /* Offset in file. */\r
104 Elf64_Xword sh_size; /* Size in bytes. */\r
105 Elf64_Word sh_link; /* Index of a related section. */\r
106 Elf64_Word sh_info; /* Depends on section type. */\r
107 Elf64_Xword sh_addralign; /* Alignment in bytes. */\r
108 Elf64_Xword sh_entsize; /* Size of each entry in section. */\r
f51461c8
LG
109} Elf64_Shdr;\r
110\r
111/*\r
112 * Program header.\r
113 */\r
114\r
115typedef struct {\r
f7496d71
LG
116 Elf64_Word p_type; /* Entry type. */\r
117 Elf64_Word p_flags; /* Access permission flags. */\r
118 Elf64_Off p_offset; /* File offset of contents. */\r
119 Elf64_Addr p_vaddr; /* Virtual address in memory image. */\r
120 Elf64_Addr p_paddr; /* Physical address (not used). */\r
121 Elf64_Xword p_filesz; /* Size of contents in file. */\r
122 Elf64_Xword p_memsz; /* Size of contents in memory. */\r
123 Elf64_Xword p_align; /* Alignment in memory and file. */\r
f51461c8
LG
124} Elf64_Phdr;\r
125\r
126/*\r
127 * Dynamic structure. The ".dynamic" section contains an array of them.\r
128 */\r
129\r
130typedef struct {\r
f7496d71
LG
131 Elf64_Sxword d_tag; /* Entry type. */\r
132 union {\r
133 Elf64_Xword d_val; /* Integer value. */\r
134 Elf64_Addr d_ptr; /* Address value. */\r
135 } d_un;\r
f51461c8
LG
136} Elf64_Dyn;\r
137\r
138/*\r
139 * Relocation entries.\r
140 */\r
141\r
142/* Relocations that don't need an addend field. */\r
143typedef struct {\r
f7496d71
LG
144 Elf64_Addr r_offset; /* Location to be relocated. */\r
145 Elf64_Xword r_info; /* Relocation type and symbol index. */\r
f51461c8
LG
146} Elf64_Rel;\r
147\r
148/* Relocations that need an addend field. */\r
149typedef struct {\r
f7496d71
LG
150 Elf64_Addr r_offset; /* Location to be relocated. */\r
151 Elf64_Xword r_info; /* Relocation type and symbol index. */\r
152 Elf64_Sxword r_addend; /* Addend. */\r
f51461c8
LG
153} Elf64_Rela;\r
154\r
155/* Macros for accessing the fields of r_info. */\r
f7496d71
LG
156#define ELF64_R_SYM(info) ((info) >> 32)\r
157#define ELF64_R_TYPE(info) ((info) & 0xffffffffL)\r
f51461c8
LG
158\r
159/* Macro for constructing r_info from field values. */\r
f7496d71 160#define ELF64_R_INFO(sym, type) (((sym) << 32) + ((type) & 0xffffffffL))\r
f51461c8 161\r
f7496d71
LG
162#define ELF64_R_TYPE_DATA(info) (((Elf64_Xword)(info)<<32)>>40)\r
163#define ELF64_R_TYPE_ID(info) (((Elf64_Xword)(info)<<56)>>56)\r
164#define ELF64_R_TYPE_INFO(data, type) \\r
165 (((Elf64_Xword)(data)<<8)+(Elf64_Xword)(type))\r
f51461c8
LG
166\r
167/*\r
f7496d71 168 * Note entry header\r
f51461c8
LG
169 */\r
170typedef Elf_Note Elf64_Nhdr;\r
171\r
172/*\r
f7496d71 173 * Move entry\r
f51461c8
LG
174 */\r
175typedef struct {\r
f7496d71
LG
176 Elf64_Lword m_value; /* symbol value */\r
177 Elf64_Xword m_info; /* size + index */\r
178 Elf64_Xword m_poffset; /* symbol offset */\r
179 Elf64_Half m_repeat; /* repeat count */\r
180 Elf64_Half m_stride; /* stride info */\r
f51461c8
LG
181} Elf64_Move;\r
182\r
f7496d71
LG
183#define ELF64_M_SYM(info) ((info)>>8)\r
184#define ELF64_M_SIZE(info) ((unsigned char)(info))\r
185#define ELF64_M_INFO(sym, size) (((sym)<<8)+(unsigned char)(size))\r
f51461c8
LG
186\r
187/*\r
f7496d71 188 * Hardware/Software capabilities entry\r
f51461c8
LG
189 */\r
190typedef struct {\r
f7496d71
LG
191 Elf64_Xword c_tag; /* how to interpret value */\r
192 union {\r
193 Elf64_Xword c_val;\r
194 Elf64_Addr c_ptr;\r
195 } c_un;\r
f51461c8
LG
196} Elf64_Cap;\r
197\r
198/*\r
199 * Symbol table entries.\r
200 */\r
201\r
202typedef struct {\r
f7496d71
LG
203 Elf64_Word st_name; /* String table index of name. */\r
204 unsigned char st_info; /* Type and binding information. */\r
205 unsigned char st_other; /* Reserved (not used). */\r
206 Elf64_Half st_shndx; /* Section index of symbol. */\r
207 Elf64_Addr st_value; /* Symbol value. */\r
208 Elf64_Xword st_size; /* Size of associated object. */\r
f51461c8
LG
209} Elf64_Sym;\r
210\r
211/* Macros for accessing the fields of st_info. */\r
f7496d71
LG
212#define ELF64_ST_BIND(info) ((info) >> 4)\r
213#define ELF64_ST_TYPE(info) ((info) & 0xf)\r
f51461c8
LG
214\r
215/* Macro for constructing st_info from field values. */\r
f7496d71 216#define ELF64_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf))\r
f51461c8
LG
217\r
218/* Macro for accessing the fields of st_other. */\r
f7496d71 219#define ELF64_ST_VISIBILITY(oth) ((oth) & 0x3)\r
f51461c8
LG
220\r
221/* Structures used by Sun & GNU-style symbol versioning. */\r
222typedef struct {\r
f7496d71
LG
223 Elf64_Half vd_version;\r
224 Elf64_Half vd_flags;\r
225 Elf64_Half vd_ndx;\r
226 Elf64_Half vd_cnt;\r
227 Elf64_Word vd_hash;\r
228 Elf64_Word vd_aux;\r
229 Elf64_Word vd_next;\r
f51461c8
LG
230} Elf64_Verdef;\r
231\r
232typedef struct {\r
f7496d71
LG
233 Elf64_Word vda_name;\r
234 Elf64_Word vda_next;\r
f51461c8
LG
235} Elf64_Verdaux;\r
236\r
237typedef struct {\r
f7496d71
LG
238 Elf64_Half vn_version;\r
239 Elf64_Half vn_cnt;\r
240 Elf64_Word vn_file;\r
241 Elf64_Word vn_aux;\r
242 Elf64_Word vn_next;\r
f51461c8
LG
243} Elf64_Verneed;\r
244\r
245typedef struct {\r
f7496d71
LG
246 Elf64_Word vna_hash;\r
247 Elf64_Half vna_flags;\r
248 Elf64_Half vna_other;\r
249 Elf64_Word vna_name;\r
250 Elf64_Word vna_next;\r
f51461c8
LG
251} Elf64_Vernaux;\r
252\r
253typedef Elf64_Half Elf64_Versym;\r
254\r
255typedef struct {\r
f7496d71
LG
256 Elf64_Half si_boundto; /* direct bindings - symbol bound to */\r
257 Elf64_Half si_flags; /* per symbol flags */\r
f51461c8
LG
258} Elf64_Syminfo;\r
259\r
260#endif /* !_SYS_ELF64_H_ */\r