OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2008, Google Inc. | 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. |
3 * All rights reserved. | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * | 4 * found in the LICENSE file. |
5 * Redistribution and use in source and binary forms, with or without | |
6 * modification, are permitted provided that the following conditions are | |
7 * met: | |
8 * | |
9 * * Redistributions of source code must retain the above copyright | |
10 * notice, this list of conditions and the following disclaimer. | |
11 * * Redistributions in binary form must reproduce the above | |
12 * copyright notice, this list of conditions and the following disclaimer | |
13 * in the documentation and/or other materials provided with the | |
14 * distribution. | |
15 * * Neither the name of Google Inc. nor the names of its | |
16 * contributors may be used to endorse or promote products derived from | |
17 * this software without specific prior written permission. | |
18 * | |
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
30 */ | 5 */ |
31 | 6 |
32 | |
33 /* @file | 7 /* @file |
34 * | 8 * |
35 * Minimal ELF header declaration / constants. Only Elf values are | 9 * Minimal ELF header declaration / constants. Only Elf values are |
36 * handled, and constants are defined only for fields that are actualy | 10 * handled, and constants are defined only for fields that are actualy |
37 * used. (Unused constants for used fields are include only for | 11 * used. (Unused constants for used fields are include only for |
38 * "completeness", though of course in many cases there are more | 12 * "completeness", though of course in many cases there are more |
39 * values in use, e.g., the EM_* values for e_machine.) | 13 * values in use, e.g., the EM_* values for e_machine.) |
40 * | 14 * |
41 * Note: We define both 32 and 64 bit versions of the elf file in | 15 * Note: We define both 32 and 64 bit versions of the elf file in |
42 * separate files, and then unify them here so that elf readers | 16 * separate files. We define sizeless aliases here to keep most other |
43 * can process elf files without having to specify the bit format. | 17 * code width-agnostic. But in fact, we really only deal with 32-bit |
18 * formats internally. For compatibility with past practice, we recognize | |
bsy
2011/10/11 21:21:19
M-q to refill the paragraph? this line looks too l
| |
19 * the 64-bit format for x86-64, but we translate that to 32-bit format | |
20 * in our own data structures. | |
44 * | 21 * |
45 * (Re)Created from the ELF specification at | 22 * (Re)Created from the ELF specification at |
46 * http://x86.ddj.com/ftp/manuals/tools/elf.pdf which is referenced | 23 * http://x86.ddj.com/ftp/manuals/tools/elf.pdf which is referenced |
47 * from wikipedia article | 24 * from wikipedia article |
48 * http://en.wikipedia.org/wki/Executable_and_Linkable_Format | 25 * http://en.wikipedia.org/wki/Executable_and_Linkable_Format |
49 */ | 26 */ |
50 | 27 |
51 #ifndef NATIVE_CLIENT_SRC_INCLUDE_ELF_H_ | 28 #ifndef NATIVE_CLIENT_SRC_INCLUDE_ELF_H_ |
52 #define NATIVE_CLIENT_SRC_INCLUDE_ELF_H_ 1 | 29 #define NATIVE_CLIENT_SRC_INCLUDE_ELF_H_ 1 |
53 | 30 |
54 | 31 |
55 #include "native_client/src/include/elf_auxv.h" | 32 #include "native_client/src/include/elf_auxv.h" |
56 #include "native_client/src/include/portability.h" | 33 #include "native_client/src/include/portability.h" |
57 | 34 |
58 #if !defined(NACL_TARGET_SUBARCH) | 35 #if !defined(NACL_TARGET_SUBARCH) |
59 # error "NACL_TARGET_SUBARCH must be defined to be 32 or 64" | 36 # error "NACL_TARGET_SUBARCH must be defined to be 32 or 64" |
60 #endif | 37 #endif |
61 #if NACL_TARGET_SUBARCH == 64 | 38 #if NACL_TARGET_SUBARCH == 64 |
62 # include "native_client/src/include/elf64.h" | 39 # include "native_client/src/include/elf64.h" |
63 #else | |
64 # include "native_client/src/include/elf32.h" | |
65 #endif | 40 #endif |
41 #include "native_client/src/include/elf32.h" | |
66 | 42 |
67 EXTERN_C_BEGIN | 43 EXTERN_C_BEGIN |
68 | 44 |
69 | 45 |
70 /* Note: We really should include elf64.h unconditionally. However, | 46 /* Note: We really should include elf64.h unconditionally. However, |
71 * The current include file is dependent on <stdint.h> which is | 47 * The current include file is dependent on <stdint.h> which is |
72 * not supported on all Windows platforms. Until this problem | 48 * not supported on all Windows platforms. Until this problem |
73 * is fixed, we conditionally include elf64 only if needed. | 49 * is fixed, we conditionally include elf64 only if needed. |
74 */ | 50 */ |
75 | 51 |
76 #if NACL_TARGET_SUBARCH == 64 | 52 #define NACL_ELF_CLASS ELFCLASS32 |
77 # define NACL_PRI_ADDR_ALL_WIDTH "016" | |
78 # define NACL_ELF_CLASS ELFCLASS64 | |
79 #elif NACL_TARGET_SUBARCH == 32 | |
80 # define NACL_PRI_ADDR_ALL_WIDTH "08" | |
81 # define NACL_ELF_CLASS ELFCLASS32 | |
82 #else | |
83 # error "NACL_TARGET_SUBARCH must be defined to be 32 or 64" | |
84 #endif | |
85 | 53 |
86 #define NACL_PRI_ELF_DO_GLUE2(a, b) a##b | 54 #define NACL_PRIdElf_Addr NACL_PRId32 |
87 #define NACL_PRI_ELF_GLUE2(a, b) NACL_PRI_ELF_DO_GLUE2(a, b) | 55 #define NACL_PRIiElf_Addr NACL_PRIi32 |
88 #define NACL_PRI_ELF(fmt) NACL_PRI_ELF_GLUE2(fmt, NACL_TARGET_SUBARCH) | 56 #define NACL_PRIoElf_Addr NACL_PRIo32 |
57 #define NACL_PRIuElf_Addr NACL_PRIu32 | |
58 #define NACL_PRIxElf_Addr NACL_PRIx32 | |
59 #define NACL_PRIXElf_Addr NACL_PRIX32 | |
89 | 60 |
90 #define NACL_PRIdElf_Addr NACL_PRI_ELF(NACL_PRId) | 61 #define NACL_PRIxElf_AddrAll "08"NACL_PRIx32 |
91 #define NACL_PRIiElf_Addr NACL_PRI_ELF(NACL_PRIi) | 62 #define NACL_PRIXElf_AddrAll "08"NACL_PRIX32 |
92 #define NACL_PRIoElf_Addr NACL_PRI_ELF(NACL_PRIo) | |
93 #define NACL_PRIuElf_Addr NACL_PRI_ELF(NACL_PRIu) | |
94 #define NACL_PRIxElf_Addr NACL_PRI_ELF(NACL_PRIx) | |
95 #define NACL_PRIXElf_Addr NACL_PRI_ELF(NACL_PRIX) | |
96 | 63 |
97 #define NACL_PRIxElf_AddrAll NACL_PRI_ADDR_ALL_WIDTH NACL_PRI_ELF(NACL_PRIx) | 64 #define NACL_PRIdElf_Off NACL_PRId32 |
98 #define NACL_PRIXElf_AddrAll NACL_PRI_ADDR_ALL_WIDTH NACL_PRI_ELF(NACL_PRIX) | 65 #define NACL_PRIiElf_Off NACL_PRIi32 |
99 | 66 #define NACL_PRIoElf_Off NACL_PRIo32 |
100 #define NACL_PRIdElf_Off NACL_PRI_ELF(NACL_PRId) | 67 #define NACL_PRIuElf_Off NACL_PRIu32 |
101 #define NACL_PRIiElf_Off NACL_PRI_ELF(NACL_PRIi) | 68 #define NACL_PRIxElf_Off NACL_PRIx32 |
102 #define NACL_PRIoElf_Off NACL_PRI_ELF(NACL_PRIo) | 69 #define NACL_PRIXElf_Off NACL_PRIX32 |
103 #define NACL_PRIuElf_Off NACL_PRI_ELF(NACL_PRIu) | |
104 #define NACL_PRIxElf_Off NACL_PRI_ELF(NACL_PRIx) | |
105 #define NACL_PRIXElf_Off NACL_PRI_ELF(NACL_PRIX) | |
106 | 70 |
107 #define NACL_PRIdElf_Half NACL_PRId16 | 71 #define NACL_PRIdElf_Half NACL_PRId16 |
108 #define NACL_PRIiElf_Half NACL_PRIi16 | 72 #define NACL_PRIiElf_Half NACL_PRIi16 |
109 #define NACL_PRIoElf_Half NACL_PRIo16 | 73 #define NACL_PRIoElf_Half NACL_PRIo16 |
110 #define NACL_PRIuElf_Half NACL_PRIu16 | 74 #define NACL_PRIuElf_Half NACL_PRIu16 |
111 #define NACL_PRIxElf_Half NACL_PRIx16 | 75 #define NACL_PRIxElf_Half NACL_PRIx16 |
112 #define NACL_PRIXElf_Half NACL_PRIX16 | 76 #define NACL_PRIXElf_Half NACL_PRIX16 |
113 | 77 |
114 #define NACL_PRIdElf_Word NACL_PRId32 | 78 #define NACL_PRIdElf_Word NACL_PRId32 |
115 #define NACL_PRIiElf_Word NACL_PRIi32 | 79 #define NACL_PRIiElf_Word NACL_PRIi32 |
116 #define NACL_PRIoElf_Word NACL_PRIo32 | 80 #define NACL_PRIoElf_Word NACL_PRIo32 |
117 #define NACL_PRIuElf_Word NACL_PRIu32 | 81 #define NACL_PRIuElf_Word NACL_PRIu32 |
118 #define NACL_PRIxElf_Word NACL_PRIx32 | 82 #define NACL_PRIxElf_Word NACL_PRIx32 |
119 #define NACL_PRIXElf_Word NACL_PRIX32 | 83 #define NACL_PRIXElf_Word NACL_PRIX32 |
120 | 84 |
121 #define NACL_PRIdElf_Sword NACL_PRId32z | 85 #define NACL_PRIdElf_Sword NACL_PRId32z |
122 #define NACL_PRIiElf_Sword NACL_PRIi32z | 86 #define NACL_PRIiElf_Sword NACL_PRIi32z |
123 #define NACL_PRIoElf_Sword NACL_PRIo32z | 87 #define NACL_PRIoElf_Sword NACL_PRIo32z |
124 #define NACL_PRIuElf_Sword NACL_PRIu32z | 88 #define NACL_PRIuElf_Sword NACL_PRIu32z |
125 #define NACL_PRIxElf_Sword NACL_PRIx32z | 89 #define NACL_PRIxElf_Sword NACL_PRIx32z |
126 #define NACL_PRIXElf_Sword NACL_PRIX32z | 90 #define NACL_PRIXElf_Sword NACL_PRIX32z |
127 | 91 |
128 #define NACL_PRIdElf_Xword NACL_PRI_ELF(NACL_PRId) | 92 #define NACL_PRIdElf_Xword NACL_PRId32 |
129 #define NACL_PRIiElf_Xword NACL_PRI_ELF(NACL_PRIi) | 93 #define NACL_PRIiElf_Xword NACL_PRIi32 |
130 #define NACL_PRIoElf_Xword NACL_PRI_ELF(NACL_PRIo) | 94 #define NACL_PRIoElf_Xword NACL_PRIo32 |
131 #define NACL_PRIuElf_Xword NACL_PRI_ELF(NACL_PRIu) | 95 #define NACL_PRIuElf_Xword NACL_PRIu32 |
132 #define NACL_PRIxElf_Xword NACL_PRI_ELF(NACL_PRIx) | 96 #define NACL_PRIxElf_Xword NACL_PRIx32 |
133 #define NACL_PRIXElf_Xword NACL_PRI_ELF(NACL_PRIX) | 97 #define NACL_PRIXElf_Xword NACL_PRIX32 |
134 | 98 |
135 #define NACL_PRIdElf_Sxword NACL_PRI_ELF(NACL_PRId) | 99 #define NACL_PRIdElf_Sxword NACL_PRId32 |
136 #define NACL_PRIiElf_Sxword NACL_PRI_ELF(NACL_PRIi) | 100 #define NACL_PRIiElf_Sxword NACL_PRIi32 |
137 #define NACL_PRIoElf_Sxword NACL_PRI_ELF(NACL_PRIo) | 101 #define NACL_PRIoElf_Sxword NACL_PRIo32 |
138 #define NACL_PRIuElf_Sxword NACL_PRI_ELF(NACL_PRIu) | 102 #define NACL_PRIuElf_Sxword NACL_PRIu32 |
139 #define NACL_PRIxElf_Sxword NACL_PRI_ELF(NACL_PRIx) | 103 #define NACL_PRIxElf_Sxword NACL_PRIx32 |
140 #define NACL_PRIXElf_Sxword NACL_PRI_ELF(NACL_PRIX) | 104 #define NACL_PRIXElf_Sxword NACL_PRIX32 |
141 | |
142 #if NACL_TARGET_SUBARCH == 64 | |
143 | |
144 /* __WORDSIZE == 64 */ | |
145 | |
146 /* Define sub architecture neutral types */ | |
147 typedef Elf64_Addr Elf_Addr; | |
148 typedef Elf64_Off Elf_Off; | |
149 typedef Elf64_Half Elf_Half; | |
150 typedef Elf64_Word Elf_Word; | |
151 typedef Elf64_Sword Elf_Sword; | |
152 typedef Elf64_Xword Elf_Xword; | |
153 typedef Elf64_Sxword Elf_Sxword; | |
154 | |
155 /* Define ranges for elf types. */ | |
156 #define MIN_ELF_ADDR 0x0 | |
157 #define MAX_ELF_ADDR 0xffffffffffffffff | |
158 | |
159 /* Define a neutral form of the file header. */ | |
160 typedef Elf64_Ehdr Elf_Ehdr; | |
161 | |
162 /* Define a neutral form of a program header. */ | |
163 typedef Elf64_Phdr Elf_Phdr; | |
164 | |
165 /* Define neutral section headers. */ | |
166 typedef Elf64_Shdr Elf_Shdr; | |
167 | |
168 #else | |
169 | 105 |
170 /* Define sub architecture neutral types */ | 106 /* Define sub architecture neutral types */ |
171 typedef Elf32_Addr Elf_Addr; | 107 typedef Elf32_Addr Elf_Addr; |
172 typedef Elf32_Off Elf_Off; | 108 typedef Elf32_Off Elf_Off; |
173 typedef Elf32_Half Elf_Half; | 109 typedef Elf32_Half Elf_Half; |
174 typedef Elf32_Word Elf_Word; | 110 typedef Elf32_Word Elf_Word; |
175 typedef Elf32_Sword Elf_Sword; | 111 typedef Elf32_Sword Elf_Sword; |
176 typedef Elf32_Word Elf_Xword; | 112 typedef Elf32_Word Elf_Xword; |
177 typedef Elf32_Sword Elf_Xsword; | 113 typedef Elf32_Sword Elf_Xsword; |
178 | 114 |
179 /* Define ranges for elf types. */ | 115 /* Define ranges for elf types. */ |
180 #define MIN_ELF_ADDR 0x0 | 116 #define MIN_ELF_ADDR 0x0 |
181 #define MAX_ELF_ADDR 0xffffffff | 117 #define MAX_ELF_ADDR 0xffffffff |
182 | 118 |
183 /* Define a neutral form of the file header. */ | 119 /* Define a neutral form of the file header. */ |
184 typedef Elf32_Ehdr Elf_Ehdr; | 120 typedef Elf32_Ehdr Elf_Ehdr; |
185 | 121 |
186 /* Define a neutral form of a program header. */ | 122 /* Define a neutral form of a program header. */ |
187 typedef Elf32_Phdr Elf_Phdr; | 123 typedef Elf32_Phdr Elf_Phdr; |
188 | 124 |
189 /* Define neutral section headers. */ | 125 /* Define neutral section headers. */ |
190 typedef Elf32_Shdr Elf_Shdr; | 126 typedef Elf32_Shdr Elf_Shdr; |
191 | 127 |
192 #endif | |
193 | |
194 EXTERN_C_END | 128 EXTERN_C_END |
195 | 129 |
196 #endif /* NATIVE_CLIENT_SRC_INCLUDE_ELF_H_ */ | 130 #endif /* NATIVE_CLIENT_SRC_INCLUDE_ELF_H_ */ |
OLD | NEW |