Sun Nov 8 00:57:09 2015 UTC ()
Pull up following revision(s) (requested by christos in ticket #1019):
	sys/kern/exec_elf.c: revision 1.79
	sys/sys/exec_elf.h: revision 1.150
	sys/sys/exec_elf.h: revision 1.151
	sys/kern/exec_elf.c: revision 1.80
Ignore the ancient 01.01 tag that gnuc used to put in old NetBSD binaries.
Add buildid Go note


(riz)
diff -r1.69.2.2 -r1.69.2.3 src/sys/kern/exec_elf.c
diff -r1.141 -r1.141.2.1 src/sys/sys/exec_elf.h

cvs diff -r1.69.2.2 -r1.69.2.3 src/sys/kern/exec_elf.c (switch to unified diff)

--- src/sys/kern/exec_elf.c 2015/03/29 09:07:55 1.69.2.2
+++ src/sys/kern/exec_elf.c 2015/11/08 00:57:09 1.69.2.3
@@ -1,1058 +1,1068 @@ @@ -1,1058 +1,1068 @@
1/* $NetBSD: exec_elf.c,v 1.69.2.2 2015/03/29 09:07:55 martin Exp $ */ 1/* $NetBSD: exec_elf.c,v 1.69.2.3 2015/11/08 00:57:09 riz Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1994, 2000, 2005 The NetBSD Foundation, Inc. 4 * Copyright (c) 1994, 2000, 2005 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas. 8 * by Christos Zoulas.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32/* 32/*
33 * Copyright (c) 1996 Christopher G. Demetriou 33 * Copyright (c) 1996 Christopher G. Demetriou
34 * All rights reserved. 34 * All rights reserved.
35 * 35 *
36 * Redistribution and use in source and binary forms, with or without 36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions 37 * modification, are permitted provided that the following conditions
38 * are met: 38 * are met:
39 * 1. Redistributions of source code must retain the above copyright 39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer. 40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright 41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the 42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution. 43 * documentation and/or other materials provided with the distribution.
44 * 3. The name of the author may not be used to endorse or promote products 44 * 3. The name of the author may not be used to endorse or promote products
45 * derived from this software without specific prior written permission 45 * derived from this software without specific prior written permission
46 * 46 *
47 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 47 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
48 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 48 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 49 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
50 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 50 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
51 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 51 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
52 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 52 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
53 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 53 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
54 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 54 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
55 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 55 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
56 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 56 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57 */ 57 */
58 58
59#include <sys/cdefs.h> 59#include <sys/cdefs.h>
60__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.69.2.2 2015/03/29 09:07:55 martin Exp $"); 60__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.69.2.3 2015/11/08 00:57:09 riz Exp $");
61 61
62#ifdef _KERNEL_OPT 62#ifdef _KERNEL_OPT
63#include "opt_pax.h" 63#include "opt_pax.h"
64#endif /* _KERNEL_OPT */ 64#endif /* _KERNEL_OPT */
65 65
66#include <sys/param.h> 66#include <sys/param.h>
67#include <sys/proc.h> 67#include <sys/proc.h>
68#include <sys/kmem.h> 68#include <sys/kmem.h>
69#include <sys/namei.h> 69#include <sys/namei.h>
70#include <sys/vnode.h> 70#include <sys/vnode.h>
71#include <sys/exec.h> 71#include <sys/exec.h>
72#include <sys/exec_elf.h> 72#include <sys/exec_elf.h>
73#include <sys/syscall.h> 73#include <sys/syscall.h>
74#include <sys/signalvar.h> 74#include <sys/signalvar.h>
75#include <sys/mount.h> 75#include <sys/mount.h>
76#include <sys/stat.h> 76#include <sys/stat.h>
77#include <sys/kauth.h> 77#include <sys/kauth.h>
78#include <sys/bitops.h> 78#include <sys/bitops.h>
79#include <sys/cprng.h> 79#include <sys/cprng.h>
80 80
81#include <sys/cpu.h> 81#include <sys/cpu.h>
82#include <machine/reg.h> 82#include <machine/reg.h>
83 83
84#include <compat/common/compat_util.h> 84#include <compat/common/compat_util.h>
85 85
86#include <sys/pax.h> 86#include <sys/pax.h>
87#include <uvm/uvm_param.h> 87#include <uvm/uvm_param.h>
88 88
89extern struct emul emul_netbsd; 89extern struct emul emul_netbsd;
90 90
91#define elf_check_header ELFNAME(check_header) 91#define elf_check_header ELFNAME(check_header)
92#define elf_copyargs ELFNAME(copyargs) 92#define elf_copyargs ELFNAME(copyargs)
93#define elf_load_interp ELFNAME(load_interp) 93#define elf_load_interp ELFNAME(load_interp)
94#define elf_load_psection ELFNAME(load_psection) 94#define elf_load_psection ELFNAME(load_psection)
95#define exec_elf_makecmds ELFNAME2(exec,makecmds) 95#define exec_elf_makecmds ELFNAME2(exec,makecmds)
96#define netbsd_elf_signature ELFNAME2(netbsd,signature) 96#define netbsd_elf_signature ELFNAME2(netbsd,signature)
97#define netbsd_elf_probe ELFNAME2(netbsd,probe) 97#define netbsd_elf_probe ELFNAME2(netbsd,probe)
98#define coredump ELFNAMEEND(coredump) 98#define coredump ELFNAMEEND(coredump)
99#define elf_free_emul_arg ELFNAME(free_emul_arg) 99#define elf_free_emul_arg ELFNAME(free_emul_arg)
100 100
101static int 101static int
102elf_load_interp(struct lwp *, struct exec_package *, char *, 102elf_load_interp(struct lwp *, struct exec_package *, char *,
103 struct exec_vmcmd_set *, u_long *, Elf_Addr *); 103 struct exec_vmcmd_set *, u_long *, Elf_Addr *);
104static void 104static void
105elf_load_psection(struct exec_vmcmd_set *, struct vnode *, const Elf_Phdr *, 105elf_load_psection(struct exec_vmcmd_set *, struct vnode *, const Elf_Phdr *,
106 Elf_Addr *, u_long *, int); 106 Elf_Addr *, u_long *, int);
107 107
108int netbsd_elf_signature(struct lwp *, struct exec_package *, Elf_Ehdr *); 108int netbsd_elf_signature(struct lwp *, struct exec_package *, Elf_Ehdr *);
109int netbsd_elf_probe(struct lwp *, struct exec_package *, void *, char *, 109int netbsd_elf_probe(struct lwp *, struct exec_package *, void *, char *,
110 vaddr_t *); 110 vaddr_t *);
111 111
112static void elf_free_emul_arg(void *); 112static void elf_free_emul_arg(void *);
113 113
114/* round up and down to page boundaries. */ 114/* round up and down to page boundaries. */
115#define ELF_ROUND(a, b) (((a) + (b) - 1) & ~((b) - 1)) 115#define ELF_ROUND(a, b) (((a) + (b) - 1) & ~((b) - 1))
116#define ELF_TRUNC(a, b) ((a) & ~((b) - 1)) 116#define ELF_TRUNC(a, b) ((a) & ~((b) - 1))
117 117
118static void 118static void
119elf_placedynexec(struct lwp *l, struct exec_package *epp, Elf_Ehdr *eh, 119elf_placedynexec(struct lwp *l, struct exec_package *epp, Elf_Ehdr *eh,
120 Elf_Phdr *ph) 120 Elf_Phdr *ph)
121{ 121{
122 Elf_Addr align, offset; 122 Elf_Addr align, offset;
123 int i; 123 int i;
124 124
125 for (align = i = 0; i < eh->e_phnum; i++) 125 for (align = i = 0; i < eh->e_phnum; i++)
126 if (ph[i].p_type == PT_LOAD && ph[i].p_align > align) 126 if (ph[i].p_type == PT_LOAD && ph[i].p_align > align)
127 align = ph[i].p_align; 127 align = ph[i].p_align;
128 128
129#ifdef PAX_ASLR 129#ifdef PAX_ASLR
130 if (pax_aslr_active(l)) { 130 if (pax_aslr_active(l)) {
131 size_t pax_align, l2, delta; 131 size_t pax_align, l2, delta;
132 uint32_t r; 132 uint32_t r;
133 133
134 pax_align = align; 134 pax_align = align;
135 135
136 r = cprng_fast32(); 136 r = cprng_fast32();
137 137
138 if (pax_align == 0) 138 if (pax_align == 0)
139 pax_align = PGSHIFT; 139 pax_align = PGSHIFT;
140 l2 = ilog2(pax_align); 140 l2 = ilog2(pax_align);
141 delta = PAX_ASLR_DELTA(r, l2, PAX_ASLR_DELTA_EXEC_LEN); 141 delta = PAX_ASLR_DELTA(r, l2, PAX_ASLR_DELTA_EXEC_LEN);
142 offset = ELF_TRUNC(delta, pax_align) + PAGE_SIZE; 142 offset = ELF_TRUNC(delta, pax_align) + PAGE_SIZE;
143#ifdef PAX_ASLR_DEBUG 143#ifdef PAX_ASLR_DEBUG
144 uprintf("r=0x%x l2=0x%zx PGSHIFT=0x%x Delta=0x%zx\n", r, l2, 144 uprintf("r=0x%x l2=0x%zx PGSHIFT=0x%x Delta=0x%zx\n", r, l2,
145 PGSHIFT, delta); 145 PGSHIFT, delta);
146 uprintf("pax offset=0x%llx entry=0x%llx\n", 146 uprintf("pax offset=0x%llx entry=0x%llx\n",
147 (unsigned long long)offset, 147 (unsigned long long)offset,
148 (unsigned long long)eh->e_entry); 148 (unsigned long long)eh->e_entry);
149#endif /* PAX_ASLR_DEBUG */ 149#endif /* PAX_ASLR_DEBUG */
150 } else 150 } else
151#endif /* PAX_ASLR */ 151#endif /* PAX_ASLR */
152 offset = MAX(align, PAGE_SIZE); 152 offset = MAX(align, PAGE_SIZE);
153 153
154 offset += epp->ep_vm_minaddr; 154 offset += epp->ep_vm_minaddr;
155 155
156 for (i = 0; i < eh->e_phnum; i++) 156 for (i = 0; i < eh->e_phnum; i++)
157 ph[i].p_vaddr += offset; 157 ph[i].p_vaddr += offset;
158 epp->ep_entryoffset = offset; 158 epp->ep_entryoffset = offset;
159 eh->e_entry += offset; 159 eh->e_entry += offset;
160} 160}
161 161
162/* 162/*
163 * Copy arguments onto the stack in the normal way, but add some 163 * Copy arguments onto the stack in the normal way, but add some
164 * extra information in case of dynamic binding. 164 * extra information in case of dynamic binding.
165 */ 165 */
166int 166int
167elf_copyargs(struct lwp *l, struct exec_package *pack, 167elf_copyargs(struct lwp *l, struct exec_package *pack,
168 struct ps_strings *arginfo, char **stackp, void *argp) 168 struct ps_strings *arginfo, char **stackp, void *argp)
169{ 169{
170 size_t len, vlen; 170 size_t len, vlen;
171 AuxInfo ai[ELF_AUX_ENTRIES], *a, *execname; 171 AuxInfo ai[ELF_AUX_ENTRIES], *a, *execname;
172 struct elf_args *ap; 172 struct elf_args *ap;
173 int error; 173 int error;
174 174
175 if ((error = copyargs(l, pack, arginfo, stackp, argp)) != 0) 175 if ((error = copyargs(l, pack, arginfo, stackp, argp)) != 0)
176 return error; 176 return error;
177 177
178 a = ai; 178 a = ai;
179 execname = NULL; 179 execname = NULL;
180 180
181 memset(ai, 0, sizeof(ai)); 181 memset(ai, 0, sizeof(ai));
182 182
183 /* 183 /*
184 * Push extra arguments on the stack needed by dynamically 184 * Push extra arguments on the stack needed by dynamically
185 * linked binaries 185 * linked binaries
186 */ 186 */
187 if ((ap = (struct elf_args *)pack->ep_emul_arg)) { 187 if ((ap = (struct elf_args *)pack->ep_emul_arg)) {
188 struct vattr *vap = pack->ep_vap; 188 struct vattr *vap = pack->ep_vap;
189 189
190 a->a_type = AT_PHDR; 190 a->a_type = AT_PHDR;
191 a->a_v = ap->arg_phaddr; 191 a->a_v = ap->arg_phaddr;
192 a++; 192 a++;
193 193
194 a->a_type = AT_PHENT; 194 a->a_type = AT_PHENT;
195 a->a_v = ap->arg_phentsize; 195 a->a_v = ap->arg_phentsize;
196 a++; 196 a++;
197 197
198 a->a_type = AT_PHNUM; 198 a->a_type = AT_PHNUM;
199 a->a_v = ap->arg_phnum; 199 a->a_v = ap->arg_phnum;
200 a++; 200 a++;
201 201
202 a->a_type = AT_PAGESZ; 202 a->a_type = AT_PAGESZ;
203 a->a_v = PAGE_SIZE; 203 a->a_v = PAGE_SIZE;
204 a++; 204 a++;
205 205
206 a->a_type = AT_BASE; 206 a->a_type = AT_BASE;
207 a->a_v = ap->arg_interp; 207 a->a_v = ap->arg_interp;
208 a++; 208 a++;
209 209
210 a->a_type = AT_FLAGS; 210 a->a_type = AT_FLAGS;
211 a->a_v = 0; 211 a->a_v = 0;
212 a++; 212 a++;
213 213
214 a->a_type = AT_ENTRY; 214 a->a_type = AT_ENTRY;
215 a->a_v = ap->arg_entry; 215 a->a_v = ap->arg_entry;
216 a++; 216 a++;
217 217
218 a->a_type = AT_EUID; 218 a->a_type = AT_EUID;
219 if (vap->va_mode & S_ISUID) 219 if (vap->va_mode & S_ISUID)
220 a->a_v = vap->va_uid; 220 a->a_v = vap->va_uid;
221 else 221 else
222 a->a_v = kauth_cred_geteuid(l->l_cred); 222 a->a_v = kauth_cred_geteuid(l->l_cred);
223 a++; 223 a++;
224 224
225 a->a_type = AT_RUID; 225 a->a_type = AT_RUID;
226 a->a_v = kauth_cred_getuid(l->l_cred); 226 a->a_v = kauth_cred_getuid(l->l_cred);
227 a++; 227 a++;
228 228
229 a->a_type = AT_EGID; 229 a->a_type = AT_EGID;
230 if (vap->va_mode & S_ISGID) 230 if (vap->va_mode & S_ISGID)
231 a->a_v = vap->va_gid; 231 a->a_v = vap->va_gid;
232 else 232 else
233 a->a_v = kauth_cred_getegid(l->l_cred); 233 a->a_v = kauth_cred_getegid(l->l_cred);
234 a++; 234 a++;
235 235
236 a->a_type = AT_RGID; 236 a->a_type = AT_RGID;
237 a->a_v = kauth_cred_getgid(l->l_cred); 237 a->a_v = kauth_cred_getgid(l->l_cred);
238 a++; 238 a++;
239 239
240 a->a_type = AT_STACKBASE; 240 a->a_type = AT_STACKBASE;
241 a->a_v = l->l_proc->p_stackbase; 241 a->a_v = l->l_proc->p_stackbase;
242 a++; 242 a++;
243 243
244 if (pack->ep_path) { 244 if (pack->ep_path) {
245 execname = a; 245 execname = a;
246 a->a_type = AT_SUN_EXECNAME; 246 a->a_type = AT_SUN_EXECNAME;
247 a++; 247 a++;
248 } 248 }
249 249
250 exec_free_emul_arg(pack); 250 exec_free_emul_arg(pack);
251 } 251 }
252 252
253 a->a_type = AT_NULL; 253 a->a_type = AT_NULL;
254 a->a_v = 0; 254 a->a_v = 0;
255 a++; 255 a++;
256 256
257 vlen = (a - ai) * sizeof(ai[0]); 257 vlen = (a - ai) * sizeof(ai[0]);
258 258
259 KASSERT(vlen <= sizeof(ai)); 259 KASSERT(vlen <= sizeof(ai));
260 260
261 if (execname) { 261 if (execname) {
262 char *path = pack->ep_path; 262 char *path = pack->ep_path;
263 execname->a_v = (uintptr_t)(*stackp + vlen); 263 execname->a_v = (uintptr_t)(*stackp + vlen);
264 len = strlen(path) + 1; 264 len = strlen(path) + 1;
265 if ((error = copyout(path, (*stackp + vlen), len)) != 0) 265 if ((error = copyout(path, (*stackp + vlen), len)) != 0)
266 return error; 266 return error;
267 len = ALIGN(len); 267 len = ALIGN(len);
268 } else 268 } else
269 len = 0; 269 len = 0;
270 270
271 if ((error = copyout(ai, *stackp, vlen)) != 0) 271 if ((error = copyout(ai, *stackp, vlen)) != 0)
272 return error; 272 return error;
273 *stackp += vlen + len; 273 *stackp += vlen + len;
274 274
275 return 0; 275 return 0;
276} 276}
277 277
278/* 278/*
279 * elf_check_header(): 279 * elf_check_header():
280 * 280 *
281 * Check header for validity; return 0 if ok, ENOEXEC if error 281 * Check header for validity; return 0 if ok, ENOEXEC if error
282 */ 282 */
283int 283int
284elf_check_header(Elf_Ehdr *eh) 284elf_check_header(Elf_Ehdr *eh)
285{ 285{
286 286
287 if (memcmp(eh->e_ident, ELFMAG, SELFMAG) != 0 || 287 if (memcmp(eh->e_ident, ELFMAG, SELFMAG) != 0 ||
288 eh->e_ident[EI_CLASS] != ELFCLASS) 288 eh->e_ident[EI_CLASS] != ELFCLASS)
289 return ENOEXEC; 289 return ENOEXEC;
290 290
291 switch (eh->e_machine) { 291 switch (eh->e_machine) {
292 292
293 ELFDEFNNAME(MACHDEP_ID_CASES) 293 ELFDEFNNAME(MACHDEP_ID_CASES)
294 294
295 default: 295 default:
296 return ENOEXEC; 296 return ENOEXEC;
297 } 297 }
298 298
299 if (ELF_EHDR_FLAGS_OK(eh) == 0) 299 if (ELF_EHDR_FLAGS_OK(eh) == 0)
300 return ENOEXEC; 300 return ENOEXEC;
301 301
302 if (eh->e_shnum > ELF_MAXSHNUM || eh->e_phnum > ELF_MAXPHNUM) 302 if (eh->e_shnum > ELF_MAXSHNUM || eh->e_phnum > ELF_MAXPHNUM)
303 return ENOEXEC; 303 return ENOEXEC;
304 304
305 return 0; 305 return 0;
306} 306}
307 307
308/* 308/*
309 * elf_load_psection(): 309 * elf_load_psection():
310 * 310 *
311 * Load a psection at the appropriate address 311 * Load a psection at the appropriate address
312 */ 312 */
313static void 313static void
314elf_load_psection(struct exec_vmcmd_set *vcset, struct vnode *vp, 314elf_load_psection(struct exec_vmcmd_set *vcset, struct vnode *vp,
315 const Elf_Phdr *ph, Elf_Addr *addr, u_long *size, int flags) 315 const Elf_Phdr *ph, Elf_Addr *addr, u_long *size, int flags)
316{ 316{
317 u_long msize, psize, rm, rf; 317 u_long msize, psize, rm, rf;
318 long diff, offset; 318 long diff, offset;
319 int vmprot = 0; 319 int vmprot = 0;
320 320
321 /* 321 /*
322 * If the user specified an address, then we load there. 322 * If the user specified an address, then we load there.
323 */ 323 */
324 if (*addr == ELFDEFNNAME(NO_ADDR)) 324 if (*addr == ELFDEFNNAME(NO_ADDR))
325 *addr = ph->p_vaddr; 325 *addr = ph->p_vaddr;
326 326
327 if (ph->p_align > 1) { 327 if (ph->p_align > 1) {
328 /* 328 /*
329 * Make sure we are virtually aligned as we are supposed to be. 329 * Make sure we are virtually aligned as we are supposed to be.
330 */ 330 */
331 diff = ph->p_vaddr - ELF_TRUNC(ph->p_vaddr, ph->p_align); 331 diff = ph->p_vaddr - ELF_TRUNC(ph->p_vaddr, ph->p_align);
332 KASSERT(*addr - diff == ELF_TRUNC(*addr, ph->p_align)); 332 KASSERT(*addr - diff == ELF_TRUNC(*addr, ph->p_align));
333 /* 333 /*
334 * But make sure to not map any pages before the start of the 334 * But make sure to not map any pages before the start of the
335 * psection by limiting the difference to within a page. 335 * psection by limiting the difference to within a page.
336 */ 336 */
337 diff &= PAGE_MASK; 337 diff &= PAGE_MASK;
338 } else 338 } else
339 diff = 0; 339 diff = 0;
340 340
341 vmprot |= (ph->p_flags & PF_R) ? VM_PROT_READ : 0; 341 vmprot |= (ph->p_flags & PF_R) ? VM_PROT_READ : 0;
342 vmprot |= (ph->p_flags & PF_W) ? VM_PROT_WRITE : 0; 342 vmprot |= (ph->p_flags & PF_W) ? VM_PROT_WRITE : 0;
343 vmprot |= (ph->p_flags & PF_X) ? VM_PROT_EXECUTE : 0; 343 vmprot |= (ph->p_flags & PF_X) ? VM_PROT_EXECUTE : 0;
344 344
345 /* 345 /*
346 * Adjust everything so it all starts on a page boundary. 346 * Adjust everything so it all starts on a page boundary.
347 */ 347 */
348 *addr -= diff; 348 *addr -= diff;
349 offset = ph->p_offset - diff; 349 offset = ph->p_offset - diff;
350 *size = ph->p_filesz + diff; 350 *size = ph->p_filesz + diff;
351 msize = ph->p_memsz + diff; 351 msize = ph->p_memsz + diff;
352 352
353 if (ph->p_align >= PAGE_SIZE) { 353 if (ph->p_align >= PAGE_SIZE) {
354 if ((ph->p_flags & PF_W) != 0) { 354 if ((ph->p_flags & PF_W) != 0) {
355 /* 355 /*
356 * Because the pagedvn pager can't handle zero fill 356 * Because the pagedvn pager can't handle zero fill
357 * of the last data page if it's not page aligned we 357 * of the last data page if it's not page aligned we
358 * map the last page readvn. 358 * map the last page readvn.
359 */ 359 */
360 psize = trunc_page(*size); 360 psize = trunc_page(*size);
361 } else { 361 } else {
362 psize = round_page(*size); 362 psize = round_page(*size);
363 } 363 }
364 } else { 364 } else {
365 psize = *size; 365 psize = *size;
366 } 366 }
367 367
368 if (psize > 0) { 368 if (psize > 0) {
369 NEW_VMCMD2(vcset, ph->p_align < PAGE_SIZE ? 369 NEW_VMCMD2(vcset, ph->p_align < PAGE_SIZE ?
370 vmcmd_map_readvn : vmcmd_map_pagedvn, psize, *addr, vp, 370 vmcmd_map_readvn : vmcmd_map_pagedvn, psize, *addr, vp,
371 offset, vmprot, flags); 371 offset, vmprot, flags);
372 flags &= VMCMD_RELATIVE; 372 flags &= VMCMD_RELATIVE;
373 } 373 }
374 if (psize < *size) { 374 if (psize < *size) {
375 NEW_VMCMD2(vcset, vmcmd_map_readvn, *size - psize, 375 NEW_VMCMD2(vcset, vmcmd_map_readvn, *size - psize,
376 *addr + psize, vp, offset + psize, vmprot, flags); 376 *addr + psize, vp, offset + psize, vmprot, flags);
377 } 377 }
378 378
379 /* 379 /*
380 * Check if we need to extend the size of the segment (does 380 * Check if we need to extend the size of the segment (does
381 * bss extend page the next page boundary)? 381 * bss extend page the next page boundary)?
382 */ 382 */
383 rm = round_page(*addr + msize); 383 rm = round_page(*addr + msize);
384 rf = round_page(*addr + *size); 384 rf = round_page(*addr + *size);
385 385
386 if (rm != rf) { 386 if (rm != rf) {
387 NEW_VMCMD2(vcset, vmcmd_map_zero, rm - rf, rf, NULLVP, 387 NEW_VMCMD2(vcset, vmcmd_map_zero, rm - rf, rf, NULLVP,
388 0, vmprot, flags & VMCMD_RELATIVE); 388 0, vmprot, flags & VMCMD_RELATIVE);
389 *size = msize; 389 *size = msize;
390 } 390 }
391} 391}
392 392
393/* 393/*
394 * elf_load_interp(): 394 * elf_load_interp():
395 * 395 *
396 * Load an interpreter pointed to by path. 396 * Load an interpreter pointed to by path.
397 */ 397 */
398static int 398static int
399elf_load_interp(struct lwp *l, struct exec_package *epp, char *path, 399elf_load_interp(struct lwp *l, struct exec_package *epp, char *path,
400 struct exec_vmcmd_set *vcset, u_long *entryoff, Elf_Addr *last) 400 struct exec_vmcmd_set *vcset, u_long *entryoff, Elf_Addr *last)
401{ 401{
402 int error, i; 402 int error, i;
403 struct vnode *vp; 403 struct vnode *vp;
404 struct vattr attr; 404 struct vattr attr;
405 Elf_Ehdr eh; 405 Elf_Ehdr eh;
406 Elf_Phdr *ph = NULL; 406 Elf_Phdr *ph = NULL;
407 const Elf_Phdr *base_ph; 407 const Elf_Phdr *base_ph;
408 const Elf_Phdr *last_ph; 408 const Elf_Phdr *last_ph;
409 u_long phsize; 409 u_long phsize;
410 Elf_Addr addr = *last; 410 Elf_Addr addr = *last;
411 struct proc *p; 411 struct proc *p;
412 bool use_topdown; 412 bool use_topdown;
413 413
414 p = l->l_proc; 414 p = l->l_proc;
415 415
416 KASSERT(p->p_vmspace); 416 KASSERT(p->p_vmspace);
417 if (__predict_true(p->p_vmspace != proc0.p_vmspace)) { 417 if (__predict_true(p->p_vmspace != proc0.p_vmspace)) {
418 use_topdown = p->p_vmspace->vm_map.flags & VM_MAP_TOPDOWN; 418 use_topdown = p->p_vmspace->vm_map.flags & VM_MAP_TOPDOWN;
419 } else { 419 } else {
420#ifdef __USE_TOPDOWN_VM 420#ifdef __USE_TOPDOWN_VM
421 use_topdown = epp->ep_flags & EXEC_TOPDOWN_VM; 421 use_topdown = epp->ep_flags & EXEC_TOPDOWN_VM;
422#else 422#else
423 use_topdown = false; 423 use_topdown = false;
424#endif 424#endif
425 } 425 }
426 426
427 /* 427 /*
428 * 1. open file 428 * 1. open file
429 * 2. read filehdr 429 * 2. read filehdr
430 * 3. map text, data, and bss out of it using VM_* 430 * 3. map text, data, and bss out of it using VM_*
431 */ 431 */
432 vp = epp->ep_interp; 432 vp = epp->ep_interp;
433 if (vp == NULL) { 433 if (vp == NULL) {
434 error = emul_find_interp(l, epp, path); 434 error = emul_find_interp(l, epp, path);
435 if (error != 0) 435 if (error != 0)
436 return error; 436 return error;
437 vp = epp->ep_interp; 437 vp = epp->ep_interp;
438 } 438 }
439 /* We'll tidy this ourselves - otherwise we have locking issues */ 439 /* We'll tidy this ourselves - otherwise we have locking issues */
440 epp->ep_interp = NULL; 440 epp->ep_interp = NULL;
441 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); 441 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
442 442
443 /* 443 /*
444 * Similarly, if it's not marked as executable, or it's not a regular 444 * Similarly, if it's not marked as executable, or it's not a regular
445 * file, we don't allow it to be used. 445 * file, we don't allow it to be used.
446 */ 446 */
447 if (vp->v_type != VREG) { 447 if (vp->v_type != VREG) {
448 error = EACCES; 448 error = EACCES;
449 goto badunlock; 449 goto badunlock;
450 } 450 }
451 if ((error = VOP_ACCESS(vp, VEXEC, l->l_cred)) != 0) 451 if ((error = VOP_ACCESS(vp, VEXEC, l->l_cred)) != 0)
452 goto badunlock; 452 goto badunlock;
453 453
454 /* get attributes */ 454 /* get attributes */
455 if ((error = VOP_GETATTR(vp, &attr, l->l_cred)) != 0) 455 if ((error = VOP_GETATTR(vp, &attr, l->l_cred)) != 0)
456 goto badunlock; 456 goto badunlock;
457 457
458 /* 458 /*
459 * Check mount point. Though we're not trying to exec this binary, 459 * Check mount point. Though we're not trying to exec this binary,
460 * we will be executing code from it, so if the mount point 460 * we will be executing code from it, so if the mount point
461 * disallows execution or set-id-ness, we punt or kill the set-id. 461 * disallows execution or set-id-ness, we punt or kill the set-id.
462 */ 462 */
463 if (vp->v_mount->mnt_flag & MNT_NOEXEC) { 463 if (vp->v_mount->mnt_flag & MNT_NOEXEC) {
464 error = EACCES; 464 error = EACCES;
465 goto badunlock; 465 goto badunlock;
466 } 466 }
467 if (vp->v_mount->mnt_flag & MNT_NOSUID) 467 if (vp->v_mount->mnt_flag & MNT_NOSUID)
468 epp->ep_vap->va_mode &= ~(S_ISUID | S_ISGID); 468 epp->ep_vap->va_mode &= ~(S_ISUID | S_ISGID);
469 469
470#ifdef notyet /* XXX cgd 960926 */ 470#ifdef notyet /* XXX cgd 960926 */
471 XXX cgd 960926: (maybe) VOP_OPEN it (and VOP_CLOSE in copyargs?) 471 XXX cgd 960926: (maybe) VOP_OPEN it (and VOP_CLOSE in copyargs?)
472 472
473 XXXps: this problem will make it impossible to use an interpreter 473 XXXps: this problem will make it impossible to use an interpreter
474 from a file system which actually does something in VOP_OPEN 474 from a file system which actually does something in VOP_OPEN
475#endif 475#endif
476 476
477 error = vn_marktext(vp); 477 error = vn_marktext(vp);
478 if (error) 478 if (error)
479 goto badunlock; 479 goto badunlock;
480 480
481 VOP_UNLOCK(vp); 481 VOP_UNLOCK(vp);
482 482
483 if ((error = exec_read_from(l, vp, 0, &eh, sizeof(eh))) != 0) 483 if ((error = exec_read_from(l, vp, 0, &eh, sizeof(eh))) != 0)
484 goto bad; 484 goto bad;
485 485
486 if ((error = elf_check_header(&eh)) != 0) 486 if ((error = elf_check_header(&eh)) != 0)
487 goto bad; 487 goto bad;
488 if (eh.e_type != ET_DYN || eh.e_phnum == 0) { 488 if (eh.e_type != ET_DYN || eh.e_phnum == 0) {
489 error = ENOEXEC; 489 error = ENOEXEC;
490 goto bad; 490 goto bad;
491 } 491 }
492 492
493 phsize = eh.e_phnum * sizeof(Elf_Phdr); 493 phsize = eh.e_phnum * sizeof(Elf_Phdr);
494 ph = kmem_alloc(phsize, KM_SLEEP); 494 ph = kmem_alloc(phsize, KM_SLEEP);
495 495
496 if ((error = exec_read_from(l, vp, eh.e_phoff, ph, phsize)) != 0) 496 if ((error = exec_read_from(l, vp, eh.e_phoff, ph, phsize)) != 0)
497 goto bad; 497 goto bad;
498 498
499#ifdef ELF_INTERP_NON_RELOCATABLE 499#ifdef ELF_INTERP_NON_RELOCATABLE
500 /* 500 /*
501 * Evil hack: Only MIPS should be non-relocatable, and the 501 * Evil hack: Only MIPS should be non-relocatable, and the
502 * psections should have a high address (typically 0x5ffe0000). 502 * psections should have a high address (typically 0x5ffe0000).
503 * If it's now relocatable, it should be linked at 0 and the 503 * If it's now relocatable, it should be linked at 0 and the
504 * psections should have zeros in the upper part of the address. 504 * psections should have zeros in the upper part of the address.
505 * Otherwise, force the load at the linked address. 505 * Otherwise, force the load at the linked address.
506 */ 506 */
507 if (*last == ELF_LINK_ADDR && (ph->p_vaddr & 0xffff0000) == 0) 507 if (*last == ELF_LINK_ADDR && (ph->p_vaddr & 0xffff0000) == 0)
508 *last = ELFDEFNNAME(NO_ADDR); 508 *last = ELFDEFNNAME(NO_ADDR);
509#endif 509#endif
510 510
511 /* 511 /*
512 * If no position to load the interpreter was set by a probe 512 * If no position to load the interpreter was set by a probe
513 * function, pick the same address that a non-fixed mmap(0, ..) 513 * function, pick the same address that a non-fixed mmap(0, ..)
514 * would (i.e. something safely out of the way). 514 * would (i.e. something safely out of the way).
515 */ 515 */
516 if (*last == ELFDEFNNAME(NO_ADDR)) { 516 if (*last == ELFDEFNNAME(NO_ADDR)) {
517 u_long limit = 0; 517 u_long limit = 0;
518 /* 518 /*
519 * Find the start and ending addresses of the psections to 519 * Find the start and ending addresses of the psections to
520 * be loaded. This will give us the size. 520 * be loaded. This will give us the size.
521 */ 521 */
522 for (i = 0, base_ph = NULL; i < eh.e_phnum; i++) { 522 for (i = 0, base_ph = NULL; i < eh.e_phnum; i++) {
523 if (ph[i].p_type == PT_LOAD) { 523 if (ph[i].p_type == PT_LOAD) {
524 u_long psize = ph[i].p_vaddr + ph[i].p_memsz; 524 u_long psize = ph[i].p_vaddr + ph[i].p_memsz;
525 if (base_ph == NULL) 525 if (base_ph == NULL)
526 base_ph = &ph[i]; 526 base_ph = &ph[i];
527 if (psize > limit) 527 if (psize > limit)
528 limit = psize; 528 limit = psize;
529 } 529 }
530 } 530 }
531 531
532 if (base_ph == NULL) { 532 if (base_ph == NULL) {
533 error = ENOEXEC; 533 error = ENOEXEC;
534 goto bad; 534 goto bad;
535 } 535 }
536 536
537 /* 537 /*
538 * Now compute the size and load address. 538 * Now compute the size and load address.
539 */ 539 */
540 addr = (*epp->ep_esch->es_emul->e_vm_default_addr)(p, 540 addr = (*epp->ep_esch->es_emul->e_vm_default_addr)(p,
541 epp->ep_daddr, 541 epp->ep_daddr,
542 round_page(limit) - trunc_page(base_ph->p_vaddr)); 542 round_page(limit) - trunc_page(base_ph->p_vaddr));
543 } else 543 } else
544 addr = *last; /* may be ELF_LINK_ADDR */ 544 addr = *last; /* may be ELF_LINK_ADDR */
545 545
546 /* 546 /*
547 * Load all the necessary sections 547 * Load all the necessary sections
548 */ 548 */
549 for (i = 0, base_ph = NULL, last_ph = NULL; i < eh.e_phnum; i++) { 549 for (i = 0, base_ph = NULL, last_ph = NULL; i < eh.e_phnum; i++) {
550 switch (ph[i].p_type) { 550 switch (ph[i].p_type) {
551 case PT_LOAD: { 551 case PT_LOAD: {
552 u_long size; 552 u_long size;
553 int flags; 553 int flags;
554 554
555 if (base_ph == NULL) { 555 if (base_ph == NULL) {
556 /* 556 /*
557 * First encountered psection is always the 557 * First encountered psection is always the
558 * base psection. Make sure it's aligned 558 * base psection. Make sure it's aligned
559 * properly (align down for topdown and align 559 * properly (align down for topdown and align
560 * upwards for not topdown). 560 * upwards for not topdown).
561 */ 561 */
562 base_ph = &ph[i]; 562 base_ph = &ph[i];
563 flags = VMCMD_BASE; 563 flags = VMCMD_BASE;
564 if (addr == ELF_LINK_ADDR) 564 if (addr == ELF_LINK_ADDR)
565 addr = ph[i].p_vaddr; 565 addr = ph[i].p_vaddr;
566 if (use_topdown) 566 if (use_topdown)
567 addr = ELF_TRUNC(addr, ph[i].p_align); 567 addr = ELF_TRUNC(addr, ph[i].p_align);
568 else 568 else
569 addr = ELF_ROUND(addr, ph[i].p_align); 569 addr = ELF_ROUND(addr, ph[i].p_align);
570 } else { 570 } else {
571 u_long limit = round_page(last_ph->p_vaddr 571 u_long limit = round_page(last_ph->p_vaddr
572 + last_ph->p_memsz); 572 + last_ph->p_memsz);
573 u_long base = trunc_page(ph[i].p_vaddr); 573 u_long base = trunc_page(ph[i].p_vaddr);
574 574
575 /* 575 /*
576 * If there is a gap in between the psections, 576 * If there is a gap in between the psections,
577 * map it as inaccessible so nothing else 577 * map it as inaccessible so nothing else
578 * mmap'ed will be placed there. 578 * mmap'ed will be placed there.
579 */ 579 */
580 if (limit != base) { 580 if (limit != base) {
581 NEW_VMCMD2(vcset, vmcmd_map_zero, 581 NEW_VMCMD2(vcset, vmcmd_map_zero,
582 base - limit, 582 base - limit,
583 limit - base_ph->p_vaddr, NULLVP, 583 limit - base_ph->p_vaddr, NULLVP,
584 0, VM_PROT_NONE, VMCMD_RELATIVE); 584 0, VM_PROT_NONE, VMCMD_RELATIVE);
585 } 585 }
586 586
587 addr = ph[i].p_vaddr - base_ph->p_vaddr; 587 addr = ph[i].p_vaddr - base_ph->p_vaddr;
588 flags = VMCMD_RELATIVE; 588 flags = VMCMD_RELATIVE;
589 } 589 }
590 last_ph = &ph[i]; 590 last_ph = &ph[i];
591 elf_load_psection(vcset, vp, &ph[i], &addr, 591 elf_load_psection(vcset, vp, &ph[i], &addr,
592 &size, flags); 592 &size, flags);
593 /* 593 /*
594 * If entry is within this psection then this 594 * If entry is within this psection then this
595 * must contain the .text section. *entryoff is 595 * must contain the .text section. *entryoff is
596 * relative to the base psection. 596 * relative to the base psection.
597 */ 597 */
598 if (eh.e_entry >= ph[i].p_vaddr && 598 if (eh.e_entry >= ph[i].p_vaddr &&
599 eh.e_entry < (ph[i].p_vaddr + size)) { 599 eh.e_entry < (ph[i].p_vaddr + size)) {
600 *entryoff = eh.e_entry - base_ph->p_vaddr; 600 *entryoff = eh.e_entry - base_ph->p_vaddr;
601 } 601 }
602 addr += size; 602 addr += size;
603 break; 603 break;
604 } 604 }
605 605
606 default: 606 default:
607 break; 607 break;
608 } 608 }
609 } 609 }
610 610
611 kmem_free(ph, phsize); 611 kmem_free(ph, phsize);
612 /* 612 /*
613 * This value is ignored if TOPDOWN. 613 * This value is ignored if TOPDOWN.
614 */ 614 */
615 *last = addr; 615 *last = addr;
616 vrele(vp); 616 vrele(vp);
617 return 0; 617 return 0;
618 618
619badunlock: 619badunlock:
620 VOP_UNLOCK(vp); 620 VOP_UNLOCK(vp);
621 621
622bad: 622bad:
623 if (ph != NULL) 623 if (ph != NULL)
624 kmem_free(ph, phsize); 624 kmem_free(ph, phsize);
625#ifdef notyet /* XXX cgd 960926 */ 625#ifdef notyet /* XXX cgd 960926 */
626 (maybe) VOP_CLOSE it 626 (maybe) VOP_CLOSE it
627#endif 627#endif
628 vrele(vp); 628 vrele(vp);
629 return error; 629 return error;
630} 630}
631 631
632/* 632/*
633 * exec_elf_makecmds(): Prepare an Elf binary's exec package 633 * exec_elf_makecmds(): Prepare an Elf binary's exec package
634 * 634 *
635 * First, set of the various offsets/lengths in the exec package. 635 * First, set of the various offsets/lengths in the exec package.
636 * 636 *
637 * Then, mark the text image busy (so it can be demand paged) or error 637 * Then, mark the text image busy (so it can be demand paged) or error
638 * out if this is not possible. Finally, set up vmcmds for the 638 * out if this is not possible. Finally, set up vmcmds for the
639 * text, data, bss, and stack segments. 639 * text, data, bss, and stack segments.
640 */ 640 */
641int 641int
642exec_elf_makecmds(struct lwp *l, struct exec_package *epp) 642exec_elf_makecmds(struct lwp *l, struct exec_package *epp)
643{ 643{
644 Elf_Ehdr *eh = epp->ep_hdr; 644 Elf_Ehdr *eh = epp->ep_hdr;
645 Elf_Phdr *ph, *pp; 645 Elf_Phdr *ph, *pp;
646 Elf_Addr phdr = 0, computed_phdr = 0, pos = 0, end_text = 0; 646 Elf_Addr phdr = 0, computed_phdr = 0, pos = 0, end_text = 0;
647 int error, i; 647 int error, i;
648 char *interp = NULL; 648 char *interp = NULL;
649 u_long phsize; 649 u_long phsize;
650 struct elf_args *ap; 650 struct elf_args *ap;
651 bool is_dyn = false; 651 bool is_dyn = false;
652 652
653 if (epp->ep_hdrvalid < sizeof(Elf_Ehdr)) 653 if (epp->ep_hdrvalid < sizeof(Elf_Ehdr))
654 return ENOEXEC; 654 return ENOEXEC;
655 if ((error = elf_check_header(eh)) != 0) 655 if ((error = elf_check_header(eh)) != 0)
656 return error; 656 return error;
657 657
658 if (eh->e_type == ET_DYN) 658 if (eh->e_type == ET_DYN)
659 /* 659 /*
660 * XXX allow for executing shared objects. It seems silly 660 * XXX allow for executing shared objects. It seems silly
661 * but other ELF-based systems allow it as well. 661 * but other ELF-based systems allow it as well.
662 */ 662 */
663 is_dyn = true; 663 is_dyn = true;
664 else if (eh->e_type != ET_EXEC) 664 else if (eh->e_type != ET_EXEC)
665 return ENOEXEC; 665 return ENOEXEC;
666 666
667 if (eh->e_phnum == 0) 667 if (eh->e_phnum == 0)
668 return ENOEXEC; 668 return ENOEXEC;
669 669
670 error = vn_marktext(epp->ep_vp); 670 error = vn_marktext(epp->ep_vp);
671 if (error) 671 if (error)
672 return error; 672 return error;
673 673
674 /* 674 /*
675 * Allocate space to hold all the program headers, and read them 675 * Allocate space to hold all the program headers, and read them
676 * from the file 676 * from the file
677 */ 677 */
678 phsize = eh->e_phnum * sizeof(Elf_Phdr); 678 phsize = eh->e_phnum * sizeof(Elf_Phdr);
679 ph = kmem_alloc(phsize, KM_SLEEP); 679 ph = kmem_alloc(phsize, KM_SLEEP);
680 680
681 if ((error = exec_read_from(l, epp->ep_vp, eh->e_phoff, ph, phsize)) != 681 if ((error = exec_read_from(l, epp->ep_vp, eh->e_phoff, ph, phsize)) !=
682 0) 682 0)
683 goto bad; 683 goto bad;
684 684
685 epp->ep_taddr = epp->ep_tsize = ELFDEFNNAME(NO_ADDR); 685 epp->ep_taddr = epp->ep_tsize = ELFDEFNNAME(NO_ADDR);
686 epp->ep_daddr = epp->ep_dsize = ELFDEFNNAME(NO_ADDR); 686 epp->ep_daddr = epp->ep_dsize = ELFDEFNNAME(NO_ADDR);
687 687
688 for (i = 0; i < eh->e_phnum; i++) { 688 for (i = 0; i < eh->e_phnum; i++) {
689 pp = &ph[i]; 689 pp = &ph[i];
690 if (pp->p_type == PT_INTERP) { 690 if (pp->p_type == PT_INTERP) {
691 if (pp->p_filesz < 2 || pp->p_filesz > MAXPATHLEN) { 691 if (pp->p_filesz < 2 || pp->p_filesz > MAXPATHLEN) {
692 error = ENOEXEC; 692 error = ENOEXEC;
693 goto bad; 693 goto bad;
694 } 694 }
695 interp = PNBUF_GET(); 695 interp = PNBUF_GET();
696 if ((error = exec_read_from(l, epp->ep_vp, 696 if ((error = exec_read_from(l, epp->ep_vp,
697 pp->p_offset, interp, pp->p_filesz)) != 0) 697 pp->p_offset, interp, pp->p_filesz)) != 0)
698 goto bad; 698 goto bad;
699 /* Ensure interp is NUL-terminated and of the expected length */ 699 /* Ensure interp is NUL-terminated and of the expected length */
700 if (strnlen(interp, pp->p_filesz) != pp->p_filesz - 1) { 700 if (strnlen(interp, pp->p_filesz) != pp->p_filesz - 1) {
701 error = ENOEXEC; 701 error = ENOEXEC;
702 goto bad; 702 goto bad;
703 } 703 }
704 break; 704 break;
705 } 705 }
706 } 706 }
707 707
708 /* 708 /*
709 * On the same architecture, we may be emulating different systems. 709 * On the same architecture, we may be emulating different systems.
710 * See which one will accept this executable. 710 * See which one will accept this executable.
711 * 711 *
712 * Probe functions would normally see if the interpreter (if any) 712 * Probe functions would normally see if the interpreter (if any)
713 * exists. Emulation packages may possibly replace the interpreter in 713 * exists. Emulation packages may possibly replace the interpreter in
714 * interp[] with a changed path (/emul/xxx/<path>). 714 * interp[] with a changed path (/emul/xxx/<path>).
715 */ 715 */
716 pos = ELFDEFNNAME(NO_ADDR); 716 pos = ELFDEFNNAME(NO_ADDR);
717 if (epp->ep_esch->u.elf_probe_func) { 717 if (epp->ep_esch->u.elf_probe_func) {
718 vaddr_t startp = (vaddr_t)pos; 718 vaddr_t startp = (vaddr_t)pos;
719 719
720 error = (*epp->ep_esch->u.elf_probe_func)(l, epp, eh, interp, 720 error = (*epp->ep_esch->u.elf_probe_func)(l, epp, eh, interp,
721 &startp); 721 &startp);
722 if (error) 722 if (error)
723 goto bad; 723 goto bad;
724 pos = (Elf_Addr)startp; 724 pos = (Elf_Addr)startp;
725 } 725 }
726 726
727#if defined(PAX_MPROTECT) || defined(PAX_SEGVGUARD) || defined(PAX_ASLR) 727#if defined(PAX_MPROTECT) || defined(PAX_SEGVGUARD) || defined(PAX_ASLR)
728 l->l_proc->p_pax = epp->ep_pax_flags; 728 l->l_proc->p_pax = epp->ep_pax_flags;
729#endif /* PAX_MPROTECT || PAX_SEGVGUARD || PAX_ASLR */ 729#endif /* PAX_MPROTECT || PAX_SEGVGUARD || PAX_ASLR */
730 730
731 if (is_dyn) 731 if (is_dyn)
732 elf_placedynexec(l, epp, eh, ph); 732 elf_placedynexec(l, epp, eh, ph);
733 733
734 /* 734 /*
735 * Load all the necessary sections 735 * Load all the necessary sections
736 */ 736 */
737 for (i = 0; i < eh->e_phnum; i++) { 737 for (i = 0; i < eh->e_phnum; i++) {
738 Elf_Addr addr = ELFDEFNNAME(NO_ADDR); 738 Elf_Addr addr = ELFDEFNNAME(NO_ADDR);
739 u_long size = 0; 739 u_long size = 0;
740 740
741 switch (ph[i].p_type) { 741 switch (ph[i].p_type) {
742 case PT_LOAD: 742 case PT_LOAD:
743 elf_load_psection(&epp->ep_vmcmds, epp->ep_vp, 743 elf_load_psection(&epp->ep_vmcmds, epp->ep_vp,
744 &ph[i], &addr, &size, VMCMD_FIXED); 744 &ph[i], &addr, &size, VMCMD_FIXED);
745 745
746 /* 746 /*
747 * Consider this as text segment, if it is executable. 747 * Consider this as text segment, if it is executable.
748 * If there is more than one text segment, pick the 748 * If there is more than one text segment, pick the
749 * largest. 749 * largest.
750 */ 750 */
751 if (ph[i].p_flags & PF_X) { 751 if (ph[i].p_flags & PF_X) {
752 if (epp->ep_taddr == ELFDEFNNAME(NO_ADDR) || 752 if (epp->ep_taddr == ELFDEFNNAME(NO_ADDR) ||
753 size > epp->ep_tsize) { 753 size > epp->ep_tsize) {
754 epp->ep_taddr = addr; 754 epp->ep_taddr = addr;
755 epp->ep_tsize = size; 755 epp->ep_tsize = size;
756 } 756 }
757 end_text = addr + size; 757 end_text = addr + size;
758 } else { 758 } else {
759 epp->ep_daddr = addr; 759 epp->ep_daddr = addr;
760 epp->ep_dsize = size; 760 epp->ep_dsize = size;
761 } 761 }
762 if (ph[i].p_offset == 0) { 762 if (ph[i].p_offset == 0) {
763 computed_phdr = ph[i].p_vaddr + eh->e_phoff; 763 computed_phdr = ph[i].p_vaddr + eh->e_phoff;
764 } 764 }
765 break; 765 break;
766 766
767 case PT_SHLIB: 767 case PT_SHLIB:
768 /* SCO has these sections. */ 768 /* SCO has these sections. */
769 case PT_INTERP: 769 case PT_INTERP:
770 /* Already did this one. */ 770 /* Already did this one. */
771 case PT_DYNAMIC: 771 case PT_DYNAMIC:
772 case PT_NOTE: 772 case PT_NOTE:
773 break; 773 break;
774 case PT_PHDR: 774 case PT_PHDR:
775 /* Note address of program headers (in text segment) */ 775 /* Note address of program headers (in text segment) */
776 phdr = ph[i].p_vaddr; 776 phdr = ph[i].p_vaddr;
777 break; 777 break;
778 778
779 default: 779 default:
780 /* 780 /*
781 * Not fatal; we don't need to understand everything. 781 * Not fatal; we don't need to understand everything.
782 */ 782 */
783 break; 783 break;
784 } 784 }
785 } 785 }
786 786
787 if (epp->ep_vmcmds.evs_used == 0) { 787 if (epp->ep_vmcmds.evs_used == 0) {
788 /* No VMCMD; there was no PT_LOAD section, or those 788 /* No VMCMD; there was no PT_LOAD section, or those
789 * sections were empty */ 789 * sections were empty */
790 error = ENOEXEC; 790 error = ENOEXEC;
791 goto bad; 791 goto bad;
792 } 792 }
793 793
794 if (epp->ep_daddr == ELFDEFNNAME(NO_ADDR)) { 794 if (epp->ep_daddr == ELFDEFNNAME(NO_ADDR)) {
795 epp->ep_daddr = round_page(end_text); 795 epp->ep_daddr = round_page(end_text);
796 epp->ep_dsize = 0; 796 epp->ep_dsize = 0;
797 } 797 }
798 798
799 /* 799 /*
800 * Check if we found a dynamically linked binary and arrange to load 800 * Check if we found a dynamically linked binary and arrange to load
801 * its interpreter 801 * its interpreter
802 */ 802 */
803 if (interp) { 803 if (interp) {
804 u_int nused = epp->ep_vmcmds.evs_used; 804 u_int nused = epp->ep_vmcmds.evs_used;
805 u_long interp_offset = 0; 805 u_long interp_offset = 0;
806 806
807 if ((error = elf_load_interp(l, epp, interp, 807 if ((error = elf_load_interp(l, epp, interp,
808 &epp->ep_vmcmds, &interp_offset, &pos)) != 0) { 808 &epp->ep_vmcmds, &interp_offset, &pos)) != 0) {
809 goto bad; 809 goto bad;
810 } 810 }
811 if (epp->ep_vmcmds.evs_used == nused) { 811 if (epp->ep_vmcmds.evs_used == nused) {
812 /* elf_load_interp() has not set up any new VMCMD */ 812 /* elf_load_interp() has not set up any new VMCMD */
813 error = ENOEXEC; 813 error = ENOEXEC;
814 goto bad; 814 goto bad;
815 } 815 }
816 816
817 ap = kmem_alloc(sizeof(*ap), KM_SLEEP); 817 ap = kmem_alloc(sizeof(*ap), KM_SLEEP);
818 ap->arg_interp = epp->ep_vmcmds.evs_cmds[nused].ev_addr; 818 ap->arg_interp = epp->ep_vmcmds.evs_cmds[nused].ev_addr;
819 epp->ep_entryoffset = interp_offset; 819 epp->ep_entryoffset = interp_offset;
820 epp->ep_entry = ap->arg_interp + interp_offset; 820 epp->ep_entry = ap->arg_interp + interp_offset;
821 PNBUF_PUT(interp); 821 PNBUF_PUT(interp);
822 } else { 822 } else {
823 epp->ep_entry = eh->e_entry; 823 epp->ep_entry = eh->e_entry;
824 if (epp->ep_flags & EXEC_FORCEAUX) { 824 if (epp->ep_flags & EXEC_FORCEAUX) {
825 ap = kmem_alloc(sizeof(*ap), KM_SLEEP); 825 ap = kmem_alloc(sizeof(*ap), KM_SLEEP);
826 ap->arg_interp = (vaddr_t)NULL; 826 ap->arg_interp = (vaddr_t)NULL;
827 } else 827 } else
828 ap = NULL; 828 ap = NULL;
829 } 829 }
830 830
831 if (ap) { 831 if (ap) {
832 ap->arg_phaddr = phdr ? phdr : computed_phdr; 832 ap->arg_phaddr = phdr ? phdr : computed_phdr;
833 ap->arg_phentsize = eh->e_phentsize; 833 ap->arg_phentsize = eh->e_phentsize;
834 ap->arg_phnum = eh->e_phnum; 834 ap->arg_phnum = eh->e_phnum;
835 ap->arg_entry = eh->e_entry; 835 ap->arg_entry = eh->e_entry;
836 epp->ep_emul_arg = ap; 836 epp->ep_emul_arg = ap;
837 epp->ep_emul_arg_free = elf_free_emul_arg; 837 epp->ep_emul_arg_free = elf_free_emul_arg;
838 } 838 }
839 839
840#ifdef ELF_MAP_PAGE_ZERO 840#ifdef ELF_MAP_PAGE_ZERO
841 /* Dell SVR4 maps page zero, yeuch! */ 841 /* Dell SVR4 maps page zero, yeuch! */
842 NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_readvn, PAGE_SIZE, 0, 842 NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_readvn, PAGE_SIZE, 0,
843 epp->ep_vp, 0, VM_PROT_READ); 843 epp->ep_vp, 0, VM_PROT_READ);
844#endif 844#endif
845 kmem_free(ph, phsize); 845 kmem_free(ph, phsize);
846 return (*epp->ep_esch->es_setup_stack)(l, epp); 846 return (*epp->ep_esch->es_setup_stack)(l, epp);
847 847
848bad: 848bad:
849 if (interp) 849 if (interp)
850 PNBUF_PUT(interp); 850 PNBUF_PUT(interp);
851 exec_free_emul_arg(epp); 851 exec_free_emul_arg(epp);
852 kmem_free(ph, phsize); 852 kmem_free(ph, phsize);
853 kill_vmcmds(&epp->ep_vmcmds); 853 kill_vmcmds(&epp->ep_vmcmds);
854 return error; 854 return error;
855} 855}
856 856
857int 857int
858netbsd_elf_signature(struct lwp *l, struct exec_package *epp, 858netbsd_elf_signature(struct lwp *l, struct exec_package *epp,
859 Elf_Ehdr *eh) 859 Elf_Ehdr *eh)
860{ 860{
861 size_t i; 861 size_t i;
862 Elf_Shdr *sh; 862 Elf_Shdr *sh;
863 Elf_Nhdr *np; 863 Elf_Nhdr *np;
864 size_t shsize, nsize; 864 size_t shsize, nsize;
865 int error; 865 int error;
866 int isnetbsd = 0; 866 int isnetbsd = 0;
867 char *ndata, *ndesc; 867 char *ndata, *ndesc;
868  868
869#ifdef DIAGNOSTIC 869#ifdef DIAGNOSTIC
870 const char *badnote; 870 const char *badnote;
871#define BADNOTE(n) badnote = (n) 871#define BADNOTE(n) badnote = (n)
872#else 872#else
873#define BADNOTE(n) 873#define BADNOTE(n)
874#endif 874#endif
875 875
876 epp->ep_pax_flags = 0; 876 epp->ep_pax_flags = 0;
877 if (eh->e_shnum > ELF_MAXSHNUM || eh->e_shnum == 0) 877 if (eh->e_shnum > ELF_MAXSHNUM || eh->e_shnum == 0)
878 return ENOEXEC; 878 return ENOEXEC;
879 879
880 shsize = eh->e_shnum * sizeof(Elf_Shdr); 880 shsize = eh->e_shnum * sizeof(Elf_Shdr);
881 sh = kmem_alloc(shsize, KM_SLEEP); 881 sh = kmem_alloc(shsize, KM_SLEEP);
882 error = exec_read_from(l, epp->ep_vp, eh->e_shoff, sh, shsize); 882 error = exec_read_from(l, epp->ep_vp, eh->e_shoff, sh, shsize);
883 if (error) 883 if (error)
884 goto out; 884 goto out;
885 885
886 np = kmem_alloc(ELF_MAXNOTESIZE, KM_SLEEP); 886 np = kmem_alloc(ELF_MAXNOTESIZE, KM_SLEEP);
887 for (i = 0; i < eh->e_shnum; i++) { 887 for (i = 0; i < eh->e_shnum; i++) {
888 Elf_Shdr *shp = &sh[i]; 888 Elf_Shdr *shp = &sh[i];
889 889
890 if (shp->sh_type != SHT_NOTE || 890 if (shp->sh_type != SHT_NOTE ||
891 shp->sh_size > ELF_MAXNOTESIZE || 891 shp->sh_size > ELF_MAXNOTESIZE ||
892 shp->sh_size < sizeof(Elf_Nhdr) + ELF_NOTE_NETBSD_NAMESZ) 892 shp->sh_size < sizeof(Elf_Nhdr) + ELF_NOTE_NETBSD_NAMESZ)
893 continue; 893 continue;
894 894
895 error = exec_read_from(l, epp->ep_vp, shp->sh_offset, np, 895 error = exec_read_from(l, epp->ep_vp, shp->sh_offset, np,
896 shp->sh_size); 896 shp->sh_size);
897 if (error) 897 if (error)
898 continue; 898 continue;
899 899
900 /* Point to the note, skip the header */ 900 /* Point to the note, skip the header */
901 ndata = (char *)(np + 1); 901 ndata = (char *)(np + 1);
902 902
903 /* 903 /*
904 * Padding is present if necessary to ensure 4-byte alignment. 904 * Padding is present if necessary to ensure 4-byte alignment.
905 * The actual section size is therefore: 905 * The actual section size is therefore:
906 * header size + 4-byte aligned name + 4-byte aligned desc 906 * header size + 4-byte aligned name + 4-byte aligned desc
907 * Ensure this size is consistent with what is indicated 907 * Ensure this size is consistent with what is indicated
908 * in sh_size. The first check avoids integer overflows. 908 * in sh_size. The first check avoids integer overflows.
909 * 909 *
910 * Binaries from before NetBSD 1.6 have two notes in the same 910 * Binaries from before NetBSD 1.6 have two notes in the same
911 * note section. The second note was never used, so as long as 911 * note section. The second note was never used, so as long as
912 * the section is at least as big as it should be, it's ok. 912 * the section is at least as big as it should be, it's ok.
913 * These binaries also have a second note section with a note of 913 * These binaries also have a second note section with a note of
914 * type ELF_NOTE_TYPE_NETBSD_TAG, which can be ignored as well. 914 * type ELF_NOTE_TYPE_NETBSD_TAG, which can be ignored as well.
915 */ 915 */
916 if (np->n_namesz > shp->sh_size || np->n_descsz > shp->sh_size) { 916 if (np->n_namesz > shp->sh_size || np->n_descsz > shp->sh_size) {
917 BADNOTE("note size limit"); 917 BADNOTE("note size limit");
918 goto bad; 918 goto bad;
919 } 919 }
920 nsize = sizeof(*np) + roundup(np->n_namesz, 4) + 920 nsize = sizeof(*np) + roundup(np->n_namesz, 4) +
921 roundup(np->n_descsz, 4); 921 roundup(np->n_descsz, 4);
922 if (nsize > shp->sh_size) { 922 if (nsize > shp->sh_size) {
923 BADNOTE("note size"); 923 BADNOTE("note size");
924 goto bad; 924 goto bad;
925 } 925 }
926 ndesc = ndata + roundup(np->n_namesz, 4); 926 ndesc = ndata + roundup(np->n_namesz, 4);
927 927
928 switch (np->n_type) { 928 switch (np->n_type) {
929 case ELF_NOTE_TYPE_NETBSD_TAG: 929 case ELF_NOTE_TYPE_NETBSD_TAG:
930 /* It is us */ 930 /* It is us */
931 if (np->n_namesz == ELF_NOTE_NETBSD_NAMESZ && 931 if (np->n_namesz == ELF_NOTE_NETBSD_NAMESZ &&
932 np->n_descsz == ELF_NOTE_NETBSD_DESCSZ && 932 np->n_descsz == ELF_NOTE_NETBSD_DESCSZ &&
933 memcmp(ndata, ELF_NOTE_NETBSD_NAME, 933 memcmp(ndata, ELF_NOTE_NETBSD_NAME,
934 ELF_NOTE_NETBSD_NAMESZ) == 0) { 934 ELF_NOTE_NETBSD_NAMESZ) == 0) {
935 memcpy(&epp->ep_osversion, ndesc, 935 memcpy(&epp->ep_osversion, ndesc,
936 ELF_NOTE_NETBSD_DESCSZ); 936 ELF_NOTE_NETBSD_DESCSZ);
937 isnetbsd = 1; 937 isnetbsd = 1;
938 break; 938 break;
939 } 939 }
940 940
941 /* 941 /*
942 * Ignore SuSE tags; SuSE's n_type is the same as NetBSD's 942 * Ignore SuSE tags; SuSE's n_type is the same the
943 * one. 943 * NetBSD one.
944 */ 944 */
945 if (np->n_namesz == ELF_NOTE_SUSE_NAMESZ && 945 if (np->n_namesz == ELF_NOTE_SUSE_NAMESZ &&
946 memcmp(ndata, ELF_NOTE_SUSE_NAME, 946 memcmp(ndata, ELF_NOTE_SUSE_NAME,
947 ELF_NOTE_SUSE_NAMESZ) == 0) 947 ELF_NOTE_SUSE_NAMESZ) == 0)
948 break; 948 break;
 949 /*
 950 * Ignore old GCC
 951 */
 952 if (np->n_namesz == ELF_NOTE_OGCC_NAMESZ &&
 953 memcmp(ndata, ELF_NOTE_OGCC_NAME,
 954 ELF_NOTE_OGCC_NAMESZ) == 0)
 955 break;
949 BADNOTE("NetBSD tag"); 956 BADNOTE("NetBSD tag");
950 goto bad; 957 goto bad;
951 958
952 case ELF_NOTE_TYPE_PAX_TAG: 959 case ELF_NOTE_TYPE_PAX_TAG:
953 if (np->n_namesz == ELF_NOTE_PAX_NAMESZ && 960 if (np->n_namesz == ELF_NOTE_PAX_NAMESZ &&
954 np->n_descsz == ELF_NOTE_PAX_DESCSZ && 961 np->n_descsz == ELF_NOTE_PAX_DESCSZ &&
955 memcmp(ndata, ELF_NOTE_PAX_NAME, 962 memcmp(ndata, ELF_NOTE_PAX_NAME,
956 ELF_NOTE_PAX_NAMESZ) == 0) { 963 ELF_NOTE_PAX_NAMESZ) == 0) {
957 memcpy(&epp->ep_pax_flags, ndesc, 964 memcpy(&epp->ep_pax_flags, ndesc,
958 sizeof(epp->ep_pax_flags)); 965 sizeof(epp->ep_pax_flags));
959 break; 966 break;
960 } 967 }
961 BADNOTE("PaX tag"); 968 BADNOTE("PaX tag");
962 goto bad; 969 goto bad;
963 970
964 case ELF_NOTE_TYPE_MARCH_TAG: 971 case ELF_NOTE_TYPE_MARCH_TAG:
965 /* Copy the machine arch into the package. */ 972 /* Copy the machine arch into the package. */
966 if (np->n_namesz == ELF_NOTE_MARCH_NAMESZ 973 if (np->n_namesz == ELF_NOTE_MARCH_NAMESZ
967 && memcmp(ndata, ELF_NOTE_MARCH_NAME, 974 && memcmp(ndata, ELF_NOTE_MARCH_NAME,
968 ELF_NOTE_MARCH_NAMESZ) == 0) { 975 ELF_NOTE_MARCH_NAMESZ) == 0) {
969 /* Do not truncate the buffer */ 976 /* Do not truncate the buffer */
970 if (np->n_descsz > sizeof(epp->ep_machine_arch)) { 977 if (np->n_descsz > sizeof(epp->ep_machine_arch)) {
971 BADNOTE("description size limit"); 978 BADNOTE("description size limit");
972 goto bad; 979 goto bad;
973 } 980 }
974 /* 981 /*
975 * Ensure ndesc is NUL-terminated and of the 982 * Ensure ndesc is NUL-terminated and of the
976 * expected length. 983 * expected length.
977 */ 984 */
978 if (strnlen(ndesc, np->n_descsz) + 1 != 985 if (strnlen(ndesc, np->n_descsz) + 1 !=
979 np->n_descsz) { 986 np->n_descsz) {
980 BADNOTE("description size"); 987 BADNOTE("description size");
981 goto bad; 988 goto bad;
982 } 989 }
983 strlcpy(epp->ep_machine_arch, ndesc, 990 strlcpy(epp->ep_machine_arch, ndesc,
984 sizeof(epp->ep_machine_arch)); 991 sizeof(epp->ep_machine_arch));
985 break; 992 break;
986 } 993 }
987 BADNOTE("march tag"); 994 BADNOTE("march tag");
988 goto bad; 995 goto bad;
989 996
990 case ELF_NOTE_TYPE_MCMODEL_TAG: 997 case ELF_NOTE_TYPE_MCMODEL_TAG:
991 /* arch specific check for code model */ 998 /* arch specific check for code model */
992#ifdef ELF_MD_MCMODEL_CHECK 999#ifdef ELF_MD_MCMODEL_CHECK
993 if (np->n_namesz == ELF_NOTE_MCMODEL_NAMESZ 1000 if (np->n_namesz == ELF_NOTE_MCMODEL_NAMESZ
994 && memcmp(ndata, ELF_NOTE_MCMODEL_NAME, 1001 && memcmp(ndata, ELF_NOTE_MCMODEL_NAME,
995 ELF_NOTE_MCMODEL_NAMESZ) == 0) { 1002 ELF_NOTE_MCMODEL_NAMESZ) == 0) {
996 ELF_MD_MCMODEL_CHECK(epp, ndesc, np->n_descsz); 1003 ELF_MD_MCMODEL_CHECK(epp, ndesc, np->n_descsz);
997 break; 1004 break;
998 } 1005 }
999 BADNOTE("mcmodel tag"); 1006 BADNOTE("mcmodel tag");
1000 goto bad; 1007 goto bad;
1001#endif 1008#endif
1002 break; 1009 break;
1003 1010
1004 case ELF_NOTE_TYPE_SUSE_VERSION_TAG: 1011 case ELF_NOTE_TYPE_SUSE_VERSION_TAG:
1005 break; 1012 break;
1006 1013
 1014 case ELF_NOTE_TYPE_GO_BUILDID_TAG:
 1015 break;
 1016
1007 default: 1017 default:
1008 BADNOTE("unknown tag"); 1018 BADNOTE("unknown tag");
1009bad: 1019bad:
1010#ifdef DIAGNOSTIC 1020#ifdef DIAGNOSTIC
1011 /* Ignore GNU tags */ 1021 /* Ignore GNU tags */
1012 if (np->n_namesz == ELF_NOTE_GNU_NAMESZ && 1022 if (np->n_namesz == ELF_NOTE_GNU_NAMESZ &&
1013 memcmp(ndata, ELF_NOTE_GNU_NAME, 1023 memcmp(ndata, ELF_NOTE_GNU_NAME,
1014 ELF_NOTE_GNU_NAMESZ) == 0) 1024 ELF_NOTE_GNU_NAMESZ) == 0)
1015 break; 1025 break;
1016 1026
1017 int ns = MIN(np->n_namesz, shp->sh_size - sizeof(*np)); 1027 int ns = MIN(np->n_namesz, shp->sh_size - sizeof(*np));
1018 printf("%s: Unknown elf note type %d (%s): " 1028 printf("%s: Unknown elf note type %d (%s): "
1019 "[namesz=%d, descsz=%d name=%-*.*s]\n", 1029 "[namesz=%d, descsz=%d name=%-*.*s]\n",
1020 epp->ep_kname, np->n_type, badnote, np->n_namesz, 1030 epp->ep_kname, np->n_type, badnote, np->n_namesz,
1021 np->n_descsz, ns, ns, ndata); 1031 np->n_descsz, ns, ns, ndata);
1022#endif 1032#endif
1023 break; 1033 break;
1024 } 1034 }
1025 } 1035 }
1026 kmem_free(np, ELF_MAXNOTESIZE); 1036 kmem_free(np, ELF_MAXNOTESIZE);
1027 1037
1028 error = isnetbsd ? 0 : ENOEXEC; 1038 error = isnetbsd ? 0 : ENOEXEC;
1029out: 1039out:
1030 kmem_free(sh, shsize); 1040 kmem_free(sh, shsize);
1031 return error; 1041 return error;
1032} 1042}
1033 1043
1034int 1044int
1035netbsd_elf_probe(struct lwp *l, struct exec_package *epp, void *eh, char *itp, 1045netbsd_elf_probe(struct lwp *l, struct exec_package *epp, void *eh, char *itp,
1036 vaddr_t *pos) 1046 vaddr_t *pos)
1037{ 1047{
1038 int error; 1048 int error;
1039 1049
1040 if ((error = netbsd_elf_signature(l, epp, eh)) != 0) 1050 if ((error = netbsd_elf_signature(l, epp, eh)) != 0)
1041 return error; 1051 return error;
1042#ifdef ELF_MD_PROBE_FUNC 1052#ifdef ELF_MD_PROBE_FUNC
1043 if ((error = ELF_MD_PROBE_FUNC(l, epp, eh, itp, pos)) != 0) 1053 if ((error = ELF_MD_PROBE_FUNC(l, epp, eh, itp, pos)) != 0)
1044 return error; 1054 return error;
1045#elif defined(ELF_INTERP_NON_RELOCATABLE) 1055#elif defined(ELF_INTERP_NON_RELOCATABLE)
1046 *pos = ELF_LINK_ADDR; 1056 *pos = ELF_LINK_ADDR;
1047#endif 1057#endif
1048 epp->ep_flags |= EXEC_FORCEAUX; 1058 epp->ep_flags |= EXEC_FORCEAUX;
1049 return 0; 1059 return 0;
1050} 1060}
1051 1061
1052void 1062void
1053elf_free_emul_arg(void *arg) 1063elf_free_emul_arg(void *arg)
1054{ 1064{
1055 struct elf_args *ap = arg; 1065 struct elf_args *ap = arg;
1056 KASSERT(ap != NULL); 1066 KASSERT(ap != NULL);
1057 kmem_free(ap, sizeof(*ap)); 1067 kmem_free(ap, sizeof(*ap));
1058} 1068}

cvs diff -r1.141 -r1.141.2.1 src/sys/sys/exec_elf.h (switch to unified diff)

--- src/sys/sys/exec_elf.h 2014/07/08 17:16:25 1.141
+++ src/sys/sys/exec_elf.h 2015/11/08 00:57:09 1.141.2.1
@@ -1,1307 +1,1324 @@ @@ -1,1307 +1,1324 @@
1/* $NetBSD: exec_elf.h,v 1.141 2014/07/08 17:16:25 maxv Exp $ */ 1/* $NetBSD: exec_elf.h,v 1.141.2.1 2015/11/08 00:57:09 riz Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1994 The NetBSD Foundation, Inc. 4 * Copyright (c) 1994 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas. 8 * by Christos Zoulas.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#ifndef _SYS_EXEC_ELF_H_ 32#ifndef _SYS_EXEC_ELF_H_
33#define _SYS_EXEC_ELF_H_ 33#define _SYS_EXEC_ELF_H_
34 34
35/* 35/*
36 * The current ELF ABI specification is available at: 36 * The current ELF ABI specification is available at:
37 * http://www.sco.com/developers/gabi/ 37 * http://www.sco.com/developers/gabi/
38 * 38 *
39 * Current header definitions are in: 39 * Current header definitions are in:
40 * http://www.sco.com/developers/gabi/latest/ch4.eheader.html 40 * http://www.sco.com/developers/gabi/latest/ch4.eheader.html
41 */ 41 */
42 42
43#if defined(_KERNEL) || defined(_STANDALONE) 43#if defined(_KERNEL) || defined(_STANDALONE)
44#include <sys/types.h> 44#include <sys/types.h>
45#else 45#else
46#include <inttypes.h> 46#include <inttypes.h>
47#endif /* _KERNEL || _STANDALONE */ 47#endif /* _KERNEL || _STANDALONE */
48 48
49#if HAVE_NBTOOL_CONFIG_H 49#if HAVE_NBTOOL_CONFIG_H
50#include <nbinclude/machine/elf_machdep.h> 50#include <nbinclude/machine/elf_machdep.h>
51#else 51#else
52#include <machine/elf_machdep.h> 52#include <machine/elf_machdep.h>
53#endif 53#endif
54 54
55typedef uint8_t Elf_Byte; 55typedef uint8_t Elf_Byte;
56 56
57typedef uint32_t Elf32_Addr; 57typedef uint32_t Elf32_Addr;
58#define ELF32_FSZ_ADDR 4 58#define ELF32_FSZ_ADDR 4
59typedef uint32_t Elf32_Off; 59typedef uint32_t Elf32_Off;
60typedef int32_t Elf32_SOff; 60typedef int32_t Elf32_SOff;
61#define ELF32_FSZ_OFF 4 61#define ELF32_FSZ_OFF 4
62typedef int32_t Elf32_Sword; 62typedef int32_t Elf32_Sword;
63#define ELF32_FSZ_SWORD 4 63#define ELF32_FSZ_SWORD 4
64typedef uint32_t Elf32_Word; 64typedef uint32_t Elf32_Word;
65#define ELF32_FSZ_WORD 4 65#define ELF32_FSZ_WORD 4
66typedef uint16_t Elf32_Half; 66typedef uint16_t Elf32_Half;
67#define ELF32_FSZ_HALF 2 67#define ELF32_FSZ_HALF 2
68typedef uint64_t Elf32_Lword; 68typedef uint64_t Elf32_Lword;
69#define ELF32_FSZ_LWORD 8 69#define ELF32_FSZ_LWORD 8
70 70
71typedef uint64_t Elf64_Addr; 71typedef uint64_t Elf64_Addr;
72#define ELF64_FSZ_ADDR 8 72#define ELF64_FSZ_ADDR 8
73typedef uint64_t Elf64_Off; 73typedef uint64_t Elf64_Off;
74typedef int64_t Elf64_SOff; 74typedef int64_t Elf64_SOff;
75#define ELF64_FSZ_OFF 8 75#define ELF64_FSZ_OFF 8
76 76
77typedef int32_t Elf64_Sword; 77typedef int32_t Elf64_Sword;
78#define ELF64_FSZ_SWORD 4 78#define ELF64_FSZ_SWORD 4
79typedef uint32_t Elf64_Word; 79typedef uint32_t Elf64_Word;
80#define ELF64_FSZ_WORD 4 80#define ELF64_FSZ_WORD 4
81 81
82typedef int64_t Elf64_Sxword; 82typedef int64_t Elf64_Sxword;
83#define ELF64_FSZ_SXWORD 8 83#define ELF64_FSZ_SXWORD 8
84typedef uint64_t Elf64_Xword; 84typedef uint64_t Elf64_Xword;
85#define ELF64_FSZ_XWORD 8 85#define ELF64_FSZ_XWORD 8
86typedef uint64_t Elf64_Lword; 86typedef uint64_t Elf64_Lword;
87#define ELF64_FSZ_LWORD 8 87#define ELF64_FSZ_LWORD 8
88typedef uint16_t Elf64_Half; 88typedef uint16_t Elf64_Half;
89#define ELF64_FSZ_HALF 2 89#define ELF64_FSZ_HALF 2
90 90
91/* 91/*
92 * ELF Header 92 * ELF Header
93 */ 93 */
94#define ELF_NIDENT 16 94#define ELF_NIDENT 16
95 95
96typedef struct { 96typedef struct {
97 unsigned char e_ident[ELF_NIDENT]; /* Id bytes */ 97 unsigned char e_ident[ELF_NIDENT]; /* Id bytes */
98 Elf32_Half e_type; /* file type */ 98 Elf32_Half e_type; /* file type */
99 Elf32_Half e_machine; /* machine type */ 99 Elf32_Half e_machine; /* machine type */
100 Elf32_Word e_version; /* version number */ 100 Elf32_Word e_version; /* version number */
101 Elf32_Addr e_entry; /* entry point */ 101 Elf32_Addr e_entry; /* entry point */
102 Elf32_Off e_phoff; /* Program hdr offset */ 102 Elf32_Off e_phoff; /* Program hdr offset */
103 Elf32_Off e_shoff; /* Section hdr offset */ 103 Elf32_Off e_shoff; /* Section hdr offset */
104 Elf32_Word e_flags; /* Processor flags */ 104 Elf32_Word e_flags; /* Processor flags */
105 Elf32_Half e_ehsize; /* sizeof ehdr */ 105 Elf32_Half e_ehsize; /* sizeof ehdr */
106 Elf32_Half e_phentsize; /* Program header entry size */ 106 Elf32_Half e_phentsize; /* Program header entry size */
107 Elf32_Half e_phnum; /* Number of program headers */ 107 Elf32_Half e_phnum; /* Number of program headers */
108 Elf32_Half e_shentsize; /* Section header entry size */ 108 Elf32_Half e_shentsize; /* Section header entry size */
109 Elf32_Half e_shnum; /* Number of section headers */ 109 Elf32_Half e_shnum; /* Number of section headers */
110 Elf32_Half e_shstrndx; /* String table index */ 110 Elf32_Half e_shstrndx; /* String table index */
111} Elf32_Ehdr; 111} Elf32_Ehdr;
112 112
113typedef struct { 113typedef struct {
114 unsigned char e_ident[ELF_NIDENT]; /* Id bytes */ 114 unsigned char e_ident[ELF_NIDENT]; /* Id bytes */
115 Elf64_Half e_type; /* file type */ 115 Elf64_Half e_type; /* file type */
116 Elf64_Half e_machine; /* machine type */ 116 Elf64_Half e_machine; /* machine type */
117 Elf64_Word e_version; /* version number */ 117 Elf64_Word e_version; /* version number */
118 Elf64_Addr e_entry; /* entry point */ 118 Elf64_Addr e_entry; /* entry point */
119 Elf64_Off e_phoff; /* Program hdr offset */ 119 Elf64_Off e_phoff; /* Program hdr offset */
120 Elf64_Off e_shoff; /* Section hdr offset */ 120 Elf64_Off e_shoff; /* Section hdr offset */
121 Elf64_Word e_flags; /* Processor flags */ 121 Elf64_Word e_flags; /* Processor flags */
122 Elf64_Half e_ehsize; /* sizeof ehdr */ 122 Elf64_Half e_ehsize; /* sizeof ehdr */
123 Elf64_Half e_phentsize; /* Program header entry size */ 123 Elf64_Half e_phentsize; /* Program header entry size */
124 Elf64_Half e_phnum; /* Number of program headers */ 124 Elf64_Half e_phnum; /* Number of program headers */
125 Elf64_Half e_shentsize; /* Section header entry size */ 125 Elf64_Half e_shentsize; /* Section header entry size */
126 Elf64_Half e_shnum; /* Number of section headers */ 126 Elf64_Half e_shnum; /* Number of section headers */
127 Elf64_Half e_shstrndx; /* String table index */ 127 Elf64_Half e_shstrndx; /* String table index */
128} Elf64_Ehdr; 128} Elf64_Ehdr;
129 129
130/* e_ident offsets */ 130/* e_ident offsets */
131#define EI_MAG0 0 /* '\177' */ 131#define EI_MAG0 0 /* '\177' */
132#define EI_MAG1 1 /* 'E' */ 132#define EI_MAG1 1 /* 'E' */
133#define EI_MAG2 2 /* 'L' */ 133#define EI_MAG2 2 /* 'L' */
134#define EI_MAG3 3 /* 'F' */ 134#define EI_MAG3 3 /* 'F' */
135#define EI_CLASS 4 /* File class */ 135#define EI_CLASS 4 /* File class */
136#define EI_DATA 5 /* Data encoding */ 136#define EI_DATA 5 /* Data encoding */
137#define EI_VERSION 6 /* File version */ 137#define EI_VERSION 6 /* File version */
138#define EI_OSABI 7 /* Operating system/ABI identification */ 138#define EI_OSABI 7 /* Operating system/ABI identification */
139#define EI_ABIVERSION 8 /* ABI version */ 139#define EI_ABIVERSION 8 /* ABI version */
140#define EI_PAD 9 /* Start of padding bytes up to EI_NIDENT*/ 140#define EI_PAD 9 /* Start of padding bytes up to EI_NIDENT*/
141#define EI_NIDENT 16 /* First non-ident header byte */ 141#define EI_NIDENT 16 /* First non-ident header byte */
142 142
143/* e_ident[EI_MAG0,EI_MAG3] */ 143/* e_ident[EI_MAG0,EI_MAG3] */
144#define ELFMAG0 0x7f 144#define ELFMAG0 0x7f
145#define ELFMAG1 'E' 145#define ELFMAG1 'E'
146#define ELFMAG2 'L' 146#define ELFMAG2 'L'
147#define ELFMAG3 'F' 147#define ELFMAG3 'F'
148#define ELFMAG "\177ELF" 148#define ELFMAG "\177ELF"
149#define SELFMAG 4 149#define SELFMAG 4
150 150
151/* e_ident[EI_CLASS] */ 151/* e_ident[EI_CLASS] */
152#define ELFCLASSNONE 0 /* Invalid class */ 152#define ELFCLASSNONE 0 /* Invalid class */
153#define ELFCLASS32 1 /* 32-bit objects */ 153#define ELFCLASS32 1 /* 32-bit objects */
154#define ELFCLASS64 2 /* 64-bit objects */ 154#define ELFCLASS64 2 /* 64-bit objects */
155#define ELFCLASSNUM 3 155#define ELFCLASSNUM 3
156 156
157/* e_ident[EI_DATA] */ 157/* e_ident[EI_DATA] */
158#define ELFDATANONE 0 /* Invalid data encoding */ 158#define ELFDATANONE 0 /* Invalid data encoding */
159#define ELFDATA2LSB 1 /* 2's complement values, LSB first */ 159#define ELFDATA2LSB 1 /* 2's complement values, LSB first */
160#define ELFDATA2MSB 2 /* 2's complement values, MSB first */ 160#define ELFDATA2MSB 2 /* 2's complement values, MSB first */
161 161
162/* e_ident[EI_VERSION] */ 162/* e_ident[EI_VERSION] */
163#define EV_NONE 0 /* Invalid version */ 163#define EV_NONE 0 /* Invalid version */
164#define EV_CURRENT 1 /* Current version */ 164#define EV_CURRENT 1 /* Current version */
165#define EV_NUM 2 165#define EV_NUM 2
166 166
167/* e_ident[EI_OSABI] */ 167/* e_ident[EI_OSABI] */
168#define ELFOSABI_SYSV 0 /* UNIX System V ABI */ 168#define ELFOSABI_SYSV 0 /* UNIX System V ABI */
169#define ELFOSABI_HPUX 1 /* HP-UX operating system */ 169#define ELFOSABI_HPUX 1 /* HP-UX operating system */
170#define ELFOSABI_NETBSD 2 /* NetBSD */ 170#define ELFOSABI_NETBSD 2 /* NetBSD */
171#define ELFOSABI_LINUX 3 /* GNU/Linux */ 171#define ELFOSABI_LINUX 3 /* GNU/Linux */
172#define ELFOSABI_HURD 4 /* GNU/Hurd */ 172#define ELFOSABI_HURD 4 /* GNU/Hurd */
173#define ELFOSABI_86OPEN 5 /* 86Open */ 173#define ELFOSABI_86OPEN 5 /* 86Open */
174#define ELFOSABI_SOLARIS 6 /* Solaris */ 174#define ELFOSABI_SOLARIS 6 /* Solaris */
175#define ELFOSABI_MONTEREY 7 /* Monterey */ 175#define ELFOSABI_MONTEREY 7 /* Monterey */
176#define ELFOSABI_IRIX 8 /* IRIX */ 176#define ELFOSABI_IRIX 8 /* IRIX */
177#define ELFOSABI_FREEBSD 9 /* FreeBSD */ 177#define ELFOSABI_FREEBSD 9 /* FreeBSD */
178#define ELFOSABI_TRU64 10 /* TRU64 UNIX */ 178#define ELFOSABI_TRU64 10 /* TRU64 UNIX */
179#define ELFOSABI_MODESTO 11 /* Novell Modesto */ 179#define ELFOSABI_MODESTO 11 /* Novell Modesto */
180#define ELFOSABI_OPENBSD 12 /* OpenBSD */ 180#define ELFOSABI_OPENBSD 12 /* OpenBSD */
181#define ELFOSABI_OPENVMS 13 /* OpenVMS */ 181#define ELFOSABI_OPENVMS 13 /* OpenVMS */
182#define ELFOSABI_NSK 14 /* HP Non-Stop Kernel */ 182#define ELFOSABI_NSK 14 /* HP Non-Stop Kernel */
183#define ELFOSABI_AROS 15 /* Amiga Research OS */ 183#define ELFOSABI_AROS 15 /* Amiga Research OS */
184/* Unofficial OSABIs follow */ 184/* Unofficial OSABIs follow */
185#define ELFOSABI_ARM 97 /* ARM */ 185#define ELFOSABI_ARM 97 /* ARM */
186#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */ 186#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */
187 187
188#define ELFOSABI_NONE ELFOSABI_SYSV 188#define ELFOSABI_NONE ELFOSABI_SYSV
189#define ELFOSABI_AIX ELFOSABI_MONTEREY 189#define ELFOSABI_AIX ELFOSABI_MONTEREY
190 190
191/* e_type */ 191/* e_type */
192#define ET_NONE 0 /* No file type */ 192#define ET_NONE 0 /* No file type */
193#define ET_REL 1 /* Relocatable file */ 193#define ET_REL 1 /* Relocatable file */
194#define ET_EXEC 2 /* Executable file */ 194#define ET_EXEC 2 /* Executable file */
195#define ET_DYN 3 /* Shared object file */ 195#define ET_DYN 3 /* Shared object file */
196#define ET_CORE 4 /* Core file */ 196#define ET_CORE 4 /* Core file */
197#define ET_NUM 5 197#define ET_NUM 5
198 198
199#define ET_LOOS 0xfe00 /* Operating system specific range */ 199#define ET_LOOS 0xfe00 /* Operating system specific range */
200#define ET_HIOS 0xfeff 200#define ET_HIOS 0xfeff
201#define ET_LOPROC 0xff00 /* Processor-specific range */ 201#define ET_LOPROC 0xff00 /* Processor-specific range */
202#define ET_HIPROC 0xffff 202#define ET_HIPROC 0xffff
203 203
204/* e_machine */ 204/* e_machine */
205#define EM_NONE 0 /* No machine */ 205#define EM_NONE 0 /* No machine */
206#define EM_M32 1 /* AT&T WE 32100 */ 206#define EM_M32 1 /* AT&T WE 32100 */
207#define EM_SPARC 2 /* SPARC */ 207#define EM_SPARC 2 /* SPARC */
208#define EM_386 3 /* Intel 80386 */ 208#define EM_386 3 /* Intel 80386 */
209#define EM_68K 4 /* Motorola 68000 */ 209#define EM_68K 4 /* Motorola 68000 */
210#define EM_88K 5 /* Motorola 88000 */ 210#define EM_88K 5 /* Motorola 88000 */
211#define EM_486 6 /* Intel 80486 */ 211#define EM_486 6 /* Intel 80486 */
212#define EM_860 7 /* Intel 80860 */ 212#define EM_860 7 /* Intel 80860 */
213#define EM_MIPS 8 /* MIPS I Architecture */ 213#define EM_MIPS 8 /* MIPS I Architecture */
214#define EM_S370 9 /* Amdahl UTS on System/370 */ 214#define EM_S370 9 /* Amdahl UTS on System/370 */
215#define EM_MIPS_RS3_LE 10 /* MIPS RS3000 Little-endian */ 215#define EM_MIPS_RS3_LE 10 /* MIPS RS3000 Little-endian */
216 /* 11-14 - Reserved */ 216 /* 11-14 - Reserved */
217#define EM_RS6000 11 /* IBM RS/6000 XXX reserved */ 217#define EM_RS6000 11 /* IBM RS/6000 XXX reserved */
218#define EM_PARISC 15 /* Hewlett-Packard PA-RISC */ 218#define EM_PARISC 15 /* Hewlett-Packard PA-RISC */
219#define EM_NCUBE 16 /* NCube XXX reserved */ 219#define EM_NCUBE 16 /* NCube XXX reserved */
220#define EM_VPP500 17 /* Fujitsu VPP500 */ 220#define EM_VPP500 17 /* Fujitsu VPP500 */
221#define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */ 221#define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */
222#define EM_960 19 /* Intel 80960 */ 222#define EM_960 19 /* Intel 80960 */
223#define EM_PPC 20 /* PowerPC */ 223#define EM_PPC 20 /* PowerPC */
224#define EM_PPC64 21 /* 64-bit PowerPC */ 224#define EM_PPC64 21 /* 64-bit PowerPC */
225 /* 22-35 - Reserved */ 225 /* 22-35 - Reserved */
226#define EM_S390 22 /* System/390 XXX reserved */ 226#define EM_S390 22 /* System/390 XXX reserved */
227#define EM_V800 36 /* NEC V800 */ 227#define EM_V800 36 /* NEC V800 */
228#define EM_FR20 37 /* Fujitsu FR20 */ 228#define EM_FR20 37 /* Fujitsu FR20 */
229#define EM_RH32 38 /* TRW RH-32 */ 229#define EM_RH32 38 /* TRW RH-32 */
230#define EM_RCE 39 /* Motorola RCE */ 230#define EM_RCE 39 /* Motorola RCE */
231#define EM_ARM 40 /* Advanced RISC Machines ARM */ 231#define EM_ARM 40 /* Advanced RISC Machines ARM */
232#define EM_ALPHA 41 /* DIGITAL Alpha */ 232#define EM_ALPHA 41 /* DIGITAL Alpha */
233#define EM_SH 42 /* Hitachi Super-H */ 233#define EM_SH 42 /* Hitachi Super-H */
234#define EM_SPARCV9 43 /* SPARC Version 9 */ 234#define EM_SPARCV9 43 /* SPARC Version 9 */
235#define EM_TRICORE 44 /* Siemens Tricore */ 235#define EM_TRICORE 44 /* Siemens Tricore */
236#define EM_ARC 45 /* Argonaut RISC Core */ 236#define EM_ARC 45 /* Argonaut RISC Core */
237#define EM_H8_300 46 /* Hitachi H8/300 */ 237#define EM_H8_300 46 /* Hitachi H8/300 */
238#define EM_H8_300H 47 /* Hitachi H8/300H */ 238#define EM_H8_300H 47 /* Hitachi H8/300H */
239#define EM_H8S 48 /* Hitachi H8S */ 239#define EM_H8S 48 /* Hitachi H8S */
240#define EM_H8_500 49 /* Hitachi H8/500 */ 240#define EM_H8_500 49 /* Hitachi H8/500 */
241#define EM_IA_64 50 /* Intel Merced Processor */ 241#define EM_IA_64 50 /* Intel Merced Processor */
242#define EM_MIPS_X 51 /* Stanford MIPS-X */ 242#define EM_MIPS_X 51 /* Stanford MIPS-X */
243#define EM_COLDFIRE 52 /* Motorola Coldfire */ 243#define EM_COLDFIRE 52 /* Motorola Coldfire */
244#define EM_68HC12 53 /* Motorola MC68HC12 */ 244#define EM_68HC12 53 /* Motorola MC68HC12 */
245#define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator */ 245#define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator */
246#define EM_PCP 55 /* Siemens PCP */ 246#define EM_PCP 55 /* Siemens PCP */
247#define EM_NCPU 56 /* Sony nCPU embedded RISC processor */ 247#define EM_NCPU 56 /* Sony nCPU embedded RISC processor */
248#define EM_NDR1 57 /* Denso NDR1 microprocessor */ 248#define EM_NDR1 57 /* Denso NDR1 microprocessor */
249#define EM_STARCORE 58 /* Motorola Star*Core processor */ 249#define EM_STARCORE 58 /* Motorola Star*Core processor */
250#define EM_ME16 59 /* Toyota ME16 processor */ 250#define EM_ME16 59 /* Toyota ME16 processor */
251#define EM_ST100 60 /* STMicroelectronics ST100 processor */ 251#define EM_ST100 60 /* STMicroelectronics ST100 processor */
252#define EM_TINYJ 61 /* Advanced Logic Corp. TinyJ embedded family processor */ 252#define EM_TINYJ 61 /* Advanced Logic Corp. TinyJ embedded family processor */
253#define EM_X86_64 62 /* AMD x86-64 architecture */ 253#define EM_X86_64 62 /* AMD x86-64 architecture */
254#define EM_PDSP 63 /* Sony DSP Processor */ 254#define EM_PDSP 63 /* Sony DSP Processor */
255#define EM_PDP10 64 /* Digital Equipment Corp. PDP-10 */ 255#define EM_PDP10 64 /* Digital Equipment Corp. PDP-10 */
256#define EM_PDP11 65 /* Digital Equipment Corp. PDP-11 */ 256#define EM_PDP11 65 /* Digital Equipment Corp. PDP-11 */
257#define EM_FX66 66 /* Siemens FX66 microcontroller */ 257#define EM_FX66 66 /* Siemens FX66 microcontroller */
258#define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 bit microcontroller */ 258#define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 bit microcontroller */
259#define EM_ST7 68 /* STMicroelectronics ST7 8-bit microcontroller */ 259#define EM_ST7 68 /* STMicroelectronics ST7 8-bit microcontroller */
260#define EM_68HC16 69 /* Motorola MC68HC16 Microcontroller */ 260#define EM_68HC16 69 /* Motorola MC68HC16 Microcontroller */
261#define EM_68HC11 70 /* Motorola MC68HC11 Microcontroller */ 261#define EM_68HC11 70 /* Motorola MC68HC11 Microcontroller */
262#define EM_68HC08 71 /* Motorola MC68HC08 Microcontroller */ 262#define EM_68HC08 71 /* Motorola MC68HC08 Microcontroller */
263#define EM_68HC05 72 /* Motorola MC68HC05 Microcontroller */ 263#define EM_68HC05 72 /* Motorola MC68HC05 Microcontroller */
264#define EM_SVX 73 /* Silicon Graphics SVx */ 264#define EM_SVX 73 /* Silicon Graphics SVx */
265#define EM_ST19 74 /* STMicroelectronics ST19 8-bit CPU */ 265#define EM_ST19 74 /* STMicroelectronics ST19 8-bit CPU */
266#define EM_VAX 75 /* Digital VAX */ 266#define EM_VAX 75 /* Digital VAX */
267#define EM_CRIS 76 /* Axis Communications 32-bit embedded processor */ 267#define EM_CRIS 76 /* Axis Communications 32-bit embedded processor */
268#define EM_JAVELIN 77 /* Infineon Technologies 32-bit embedded CPU */ 268#define EM_JAVELIN 77 /* Infineon Technologies 32-bit embedded CPU */
269#define EM_FIREPATH 78 /* Element 14 64-bit DSP processor */ 269#define EM_FIREPATH 78 /* Element 14 64-bit DSP processor */
270#define EM_ZSP 79 /* LSI Logic's 16-bit DSP processor */ 270#define EM_ZSP 79 /* LSI Logic's 16-bit DSP processor */
271#define EM_MMIX 80 /* Donald Knuth's educational 64-bit processor */ 271#define EM_MMIX 80 /* Donald Knuth's educational 64-bit processor */
272#define EM_HUANY 81 /* Harvard's machine-independent format */ 272#define EM_HUANY 81 /* Harvard's machine-independent format */
273#define EM_PRISM 82 /* SiTera Prism */ 273#define EM_PRISM 82 /* SiTera Prism */
274#define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */ 274#define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */
275#define EM_FR30 84 /* Fujitsu FR30 */ 275#define EM_FR30 84 /* Fujitsu FR30 */
276#define EM_D10V 85 /* Mitsubishi D10V */ 276#define EM_D10V 85 /* Mitsubishi D10V */
277#define EM_D30V 86 /* Mitsubishi D30V */ 277#define EM_D30V 86 /* Mitsubishi D30V */
278#define EM_V850 87 /* NEC v850 */ 278#define EM_V850 87 /* NEC v850 */
279#define EM_M32R 88 /* Mitsubishi M32R */ 279#define EM_M32R 88 /* Mitsubishi M32R */
280#define EM_MN10300 89 /* Matsushita MN10300 */ 280#define EM_MN10300 89 /* Matsushita MN10300 */
281#define EM_MN10200 90 /* Matsushita MN10200 */ 281#define EM_MN10200 90 /* Matsushita MN10200 */
282#define EM_PJ 91 /* picoJava */ 282#define EM_PJ 91 /* picoJava */
283#define EM_OPENRISC 92 /* OpenRISC 32-bit embedded processor */ 283#define EM_OPENRISC 92 /* OpenRISC 32-bit embedded processor */
284#define EM_ARC_A5 93 /* ARC Cores Tangent-A5 */ 284#define EM_ARC_A5 93 /* ARC Cores Tangent-A5 */
285#define EM_XTENSA 94 /* Tensilica Xtensa Architecture */ 285#define EM_XTENSA 94 /* Tensilica Xtensa Architecture */
286#define EM_VIDEOCORE 95 /* Alphamosaic VideoCore processor */ 286#define EM_VIDEOCORE 95 /* Alphamosaic VideoCore processor */
287#define EM_TMM_GPP 96 /* Thompson Multimedia General Purpose Processor */ 287#define EM_TMM_GPP 96 /* Thompson Multimedia General Purpose Processor */
288#define EM_NS32K 97 /* National Semiconductor 32000 series */ 288#define EM_NS32K 97 /* National Semiconductor 32000 series */
289#define EM_TPC 98 /* Tenor Network TPC processor */ 289#define EM_TPC 98 /* Tenor Network TPC processor */
290#define EM_SNP1K 99 /* Trebia SNP 1000 processor */ 290#define EM_SNP1K 99 /* Trebia SNP 1000 processor */
291#define EM_ST200 100 /* STMicroelectronics ST200 microcontroller */ 291#define EM_ST200 100 /* STMicroelectronics ST200 microcontroller */
292#define EM_IP2K 101 /* Ubicom IP2xxx microcontroller family */ 292#define EM_IP2K 101 /* Ubicom IP2xxx microcontroller family */
293#define EM_MAX 102 /* MAX processor */ 293#define EM_MAX 102 /* MAX processor */
294#define EM_CR 103 /* National Semiconductor CompactRISC micorprocessor */ 294#define EM_CR 103 /* National Semiconductor CompactRISC micorprocessor */
295#define EM_F2MC16 104 /* Fujitsu F2MC16 */ 295#define EM_F2MC16 104 /* Fujitsu F2MC16 */
296#define EM_MSP430 105 /* Texas Instruments MSP430 */ 296#define EM_MSP430 105 /* Texas Instruments MSP430 */
297#define EM_BLACKFIN 106 /* Analog Devices Blackfin DSP */ 297#define EM_BLACKFIN 106 /* Analog Devices Blackfin DSP */
298#define EM_SE_C33 107 /* Seiko Epson S1C33 family */ 298#define EM_SE_C33 107 /* Seiko Epson S1C33 family */
299#define EM_SEP 108 /* Sharp embedded microprocessor */ 299#define EM_SEP 108 /* Sharp embedded microprocessor */
300#define EM_ARCA 109 /* Arca RISC microprocessor */ 300#define EM_ARCA 109 /* Arca RISC microprocessor */
301#define EM_UNICORE 110 /* UNICORE from PKU-Unity Ltd. and MPRC Peking University */ 301#define EM_UNICORE 110 /* UNICORE from PKU-Unity Ltd. and MPRC Peking University */
302#define EM_AARCH64 183 /* AArch64 64-bit ARM microprocessor */ 302#define EM_AARCH64 183 /* AArch64 64-bit ARM microprocessor */
303 303
304/* Unofficial machine types follow */ 304/* Unofficial machine types follow */
305#define EM_AVR32 6317 /* used by NetBSD/avr32 */ 305#define EM_AVR32 6317 /* used by NetBSD/avr32 */
306#define EM_ALPHA_EXP 36902 /* used by NetBSD/alpha; obsolete */ 306#define EM_ALPHA_EXP 36902 /* used by NetBSD/alpha; obsolete */
307#define EM_NUM 36903 307#define EM_NUM 36903
308 308
309/* 309/*
310 * Program Header 310 * Program Header
311 */ 311 */
312typedef struct { 312typedef struct {
313 Elf32_Word p_type; /* entry type */ 313 Elf32_Word p_type; /* entry type */
314 Elf32_Off p_offset; /* offset */ 314 Elf32_Off p_offset; /* offset */
315 Elf32_Addr p_vaddr; /* virtual address */ 315 Elf32_Addr p_vaddr; /* virtual address */
316 Elf32_Addr p_paddr; /* physical address */ 316 Elf32_Addr p_paddr; /* physical address */
317 Elf32_Word p_filesz; /* file size */ 317 Elf32_Word p_filesz; /* file size */
318 Elf32_Word p_memsz; /* memory size */ 318 Elf32_Word p_memsz; /* memory size */
319 Elf32_Word p_flags; /* flags */ 319 Elf32_Word p_flags; /* flags */
320 Elf32_Word p_align; /* memory & file alignment */ 320 Elf32_Word p_align; /* memory & file alignment */
321} Elf32_Phdr; 321} Elf32_Phdr;
322 322
323typedef struct { 323typedef struct {
324 Elf64_Word p_type; /* entry type */ 324 Elf64_Word p_type; /* entry type */
325 Elf64_Word p_flags; /* flags */ 325 Elf64_Word p_flags; /* flags */
326 Elf64_Off p_offset; /* offset */ 326 Elf64_Off p_offset; /* offset */
327 Elf64_Addr p_vaddr; /* virtual address */ 327 Elf64_Addr p_vaddr; /* virtual address */
328 Elf64_Addr p_paddr; /* physical address */ 328 Elf64_Addr p_paddr; /* physical address */
329 Elf64_Xword p_filesz; /* file size */ 329 Elf64_Xword p_filesz; /* file size */
330 Elf64_Xword p_memsz; /* memory size */ 330 Elf64_Xword p_memsz; /* memory size */
331 Elf64_Xword p_align; /* memory & file alignment */ 331 Elf64_Xword p_align; /* memory & file alignment */
332} Elf64_Phdr; 332} Elf64_Phdr;
333 333
334/* p_type */ 334/* p_type */
335#define PT_NULL 0 /* Program header table entry unused */ 335#define PT_NULL 0 /* Program header table entry unused */
336#define PT_LOAD 1 /* Loadable program segment */ 336#define PT_LOAD 1 /* Loadable program segment */
337#define PT_DYNAMIC 2 /* Dynamic linking information */ 337#define PT_DYNAMIC 2 /* Dynamic linking information */
338#define PT_INTERP 3 /* Program interpreter */ 338#define PT_INTERP 3 /* Program interpreter */
339#define PT_NOTE 4 /* Auxiliary information */ 339#define PT_NOTE 4 /* Auxiliary information */
340#define PT_SHLIB 5 /* Reserved, unspecified semantics */ 340#define PT_SHLIB 5 /* Reserved, unspecified semantics */
341#define PT_PHDR 6 /* Entry for header table itself */ 341#define PT_PHDR 6 /* Entry for header table itself */
342#define PT_TLS 7 /* TLS initialisation image */ 342#define PT_TLS 7 /* TLS initialisation image */
343#define PT_NUM 8 343#define PT_NUM 8
344 344
345#define PT_LOOS 0x60000000 /* OS-specific range */ 345#define PT_LOOS 0x60000000 /* OS-specific range */
346 346
347/* GNU-specific */ 347/* GNU-specific */
348#define PT_GNU_EH_FRAME 0x6474e550 /* EH frame segment */ 348#define PT_GNU_EH_FRAME 0x6474e550 /* EH frame segment */
349#define PT_GNU_STACK 0x6474e551 /* Indicate executable stack */ 349#define PT_GNU_STACK 0x6474e551 /* Indicate executable stack */
350#define PT_GNU_RELRO 0x6474e552 /* Make read-only after relocation */ 350#define PT_GNU_RELRO 0x6474e552 /* Make read-only after relocation */
351 351
352#define PT_HIOS 0x6fffffff 352#define PT_HIOS 0x6fffffff
353#define PT_LOPROC 0x70000000 /* Processor-specific range */ 353#define PT_LOPROC 0x70000000 /* Processor-specific range */
354#define PT_HIPROC 0x7fffffff 354#define PT_HIPROC 0x7fffffff
355 355
356#define PT_MIPS_REGINFO 0x70000000 356#define PT_MIPS_REGINFO 0x70000000
357 357
358/* p_flags */ 358/* p_flags */
359#define PF_R 0x4 /* Segment is readable */ 359#define PF_R 0x4 /* Segment is readable */
360#define PF_W 0x2 /* Segment is writable */ 360#define PF_W 0x2 /* Segment is writable */
361#define PF_X 0x1 /* Segment is executable */ 361#define PF_X 0x1 /* Segment is executable */
362 362
363#define PF_MASKOS 0x0ff00000 /* Operating system specific values */ 363#define PF_MASKOS 0x0ff00000 /* Operating system specific values */
364#define PF_MASKPROC 0xf0000000 /* Processor-specific values */ 364#define PF_MASKPROC 0xf0000000 /* Processor-specific values */
365 365
366/* Extended program header index. */ 366/* Extended program header index. */
367#define PN_XNUM 0xffff 367#define PN_XNUM 0xffff
368 368
369/* 369/*
370 * Section Headers 370 * Section Headers
371 */ 371 */
372typedef struct { 372typedef struct {
373 Elf32_Word sh_name; /* section name (.shstrtab index) */ 373 Elf32_Word sh_name; /* section name (.shstrtab index) */
374 Elf32_Word sh_type; /* section type */ 374 Elf32_Word sh_type; /* section type */
375 Elf32_Word sh_flags; /* section flags */ 375 Elf32_Word sh_flags; /* section flags */
376 Elf32_Addr sh_addr; /* virtual address */ 376 Elf32_Addr sh_addr; /* virtual address */
377 Elf32_Off sh_offset; /* file offset */ 377 Elf32_Off sh_offset; /* file offset */
378 Elf32_Word sh_size; /* section size */ 378 Elf32_Word sh_size; /* section size */
379 Elf32_Word sh_link; /* link to another */ 379 Elf32_Word sh_link; /* link to another */
380 Elf32_Word sh_info; /* misc info */ 380 Elf32_Word sh_info; /* misc info */
381 Elf32_Word sh_addralign; /* memory alignment */ 381 Elf32_Word sh_addralign; /* memory alignment */
382 Elf32_Word sh_entsize; /* table entry size */ 382 Elf32_Word sh_entsize; /* table entry size */
383} Elf32_Shdr; 383} Elf32_Shdr;
384 384
385typedef struct { 385typedef struct {
386 Elf64_Word sh_name; /* section name (.shstrtab index) */ 386 Elf64_Word sh_name; /* section name (.shstrtab index) */
387 Elf64_Word sh_type; /* section type */ 387 Elf64_Word sh_type; /* section type */
388 Elf64_Xword sh_flags; /* section flags */ 388 Elf64_Xword sh_flags; /* section flags */
389 Elf64_Addr sh_addr; /* virtual address */ 389 Elf64_Addr sh_addr; /* virtual address */
390 Elf64_Off sh_offset; /* file offset */ 390 Elf64_Off sh_offset; /* file offset */
391 Elf64_Xword sh_size; /* section size */ 391 Elf64_Xword sh_size; /* section size */
392 Elf64_Word sh_link; /* link to another */ 392 Elf64_Word sh_link; /* link to another */
393 Elf64_Word sh_info; /* misc info */ 393 Elf64_Word sh_info; /* misc info */
394 Elf64_Xword sh_addralign; /* memory alignment */ 394 Elf64_Xword sh_addralign; /* memory alignment */
395 Elf64_Xword sh_entsize; /* table entry size */ 395 Elf64_Xword sh_entsize; /* table entry size */
396} Elf64_Shdr; 396} Elf64_Shdr;
397 397
398/* sh_type */ 398/* sh_type */
399#define SHT_NULL 0 /* Section header table entry unused */ 399#define SHT_NULL 0 /* Section header table entry unused */
400#define SHT_PROGBITS 1 /* Program information */ 400#define SHT_PROGBITS 1 /* Program information */
401#define SHT_SYMTAB 2 /* Symbol table */ 401#define SHT_SYMTAB 2 /* Symbol table */
402#define SHT_STRTAB 3 /* String table */ 402#define SHT_STRTAB 3 /* String table */
403#define SHT_RELA 4 /* Relocation information w/ addend */ 403#define SHT_RELA 4 /* Relocation information w/ addend */
404#define SHT_HASH 5 /* Symbol hash table */ 404#define SHT_HASH 5 /* Symbol hash table */
405#define SHT_DYNAMIC 6 /* Dynamic linking information */ 405#define SHT_DYNAMIC 6 /* Dynamic linking information */
406#define SHT_NOTE 7 /* Auxiliary information */ 406#define SHT_NOTE 7 /* Auxiliary information */
407#define SHT_NOBITS 8 /* No space allocated in file image */ 407#define SHT_NOBITS 8 /* No space allocated in file image */
408#define SHT_REL 9 /* Relocation information w/o addend */ 408#define SHT_REL 9 /* Relocation information w/o addend */
409#define SHT_SHLIB 10 /* Reserved, unspecified semantics */ 409#define SHT_SHLIB 10 /* Reserved, unspecified semantics */
410#define SHT_DYNSYM 11 /* Symbol table for dynamic linker */ 410#define SHT_DYNSYM 11 /* Symbol table for dynamic linker */
411#define SHT_INIT_ARRAY 14 /* Initialization function pointers */ 411#define SHT_INIT_ARRAY 14 /* Initialization function pointers */
412#define SHT_FINI_ARRAY 15 /* Termination function pointers */ 412#define SHT_FINI_ARRAY 15 /* Termination function pointers */
413#define SHT_PREINIT_ARRAY 16 /* Pre-initialization function ptrs */ 413#define SHT_PREINIT_ARRAY 16 /* Pre-initialization function ptrs */
414#define SHT_GROUP 17 /* Section group */ 414#define SHT_GROUP 17 /* Section group */
415#define SHT_SYMTAB_SHNDX 18 /* Section indexes (see SHN_XINDEX) */ 415#define SHT_SYMTAB_SHNDX 18 /* Section indexes (see SHN_XINDEX) */
416#define SHT_NUM 19 416#define SHT_NUM 19
417 417
418#define SHT_LOOS 0x60000000 /* Operating system specific range */ 418#define SHT_LOOS 0x60000000 /* Operating system specific range */
419#define SHT_GNU_INCREMENTAL_INPUTS 0x6fff4700 /* GNU incremental build data */ 419#define SHT_GNU_INCREMENTAL_INPUTS 0x6fff4700 /* GNU incremental build data */
420#define SHT_LOSUNW 0x6ffffff4 420#define SHT_LOSUNW 0x6ffffff4
421#define SHT_SUNW_dof 0x6ffffff4 421#define SHT_SUNW_dof 0x6ffffff4
422#define SHT_GNU_ATTRIBUTES 0x6ffffff5 /* GNU object attributes */ 422#define SHT_GNU_ATTRIBUTES 0x6ffffff5 /* GNU object attributes */
423#define SHT_SUNW_cap 0x6ffffff5 423#define SHT_SUNW_cap 0x6ffffff5
424#define SHT_SUNW_SIGNATURE 0x6ffffff6 424#define SHT_SUNW_SIGNATURE 0x6ffffff6
425#define SHT_GNU_HASH 0x6ffffff6 /* GNU style symbol hash table */ 425#define SHT_GNU_HASH 0x6ffffff6 /* GNU style symbol hash table */
426#define SHT_GNU_LIBLIST 0x6ffffff7 /* GNU list of prelink dependencies */ 426#define SHT_GNU_LIBLIST 0x6ffffff7 /* GNU list of prelink dependencies */
427#define SHT_SUNW_move 0x6ffffffa 427#define SHT_SUNW_move 0x6ffffffa
428#define SHT_SUNW_COMDAT 0x6ffffffb 428#define SHT_SUNW_COMDAT 0x6ffffffb
429#define SHT_SUNW_syminfo 0x6ffffffc 429#define SHT_SUNW_syminfo 0x6ffffffc
430#define SHT_SUNW_verdef 0x6ffffffd /* Versions defined by file */ 430#define SHT_SUNW_verdef 0x6ffffffd /* Versions defined by file */
431#define SHT_GNU_verdef SHT_SUNW_verdef 431#define SHT_GNU_verdef SHT_SUNW_verdef
432#define SHT_SUNW_verneed 0x6ffffffe /* Versions needed by file */ 432#define SHT_SUNW_verneed 0x6ffffffe /* Versions needed by file */
433#define SHT_GNU_verneed SHT_SUNW_verneed 433#define SHT_GNU_verneed SHT_SUNW_verneed
434#define SHT_SUNW_versym 0x6fffffff /* Symbol versions */ 434#define SHT_SUNW_versym 0x6fffffff /* Symbol versions */
435#define SHT_GNU_versym SHT_SUNW_versym 435#define SHT_GNU_versym SHT_SUNW_versym
436#define SHT_HISUNW 0x6fffffff 436#define SHT_HISUNW 0x6fffffff
437#define SHT_HIOS 0x6fffffff 437#define SHT_HIOS 0x6fffffff
438#define SHT_LOPROC 0x70000000 /* Processor-specific range */ 438#define SHT_LOPROC 0x70000000 /* Processor-specific range */
439#define SHT_AMD64_UNWIND 0x70000001 /* unwind information */ 439#define SHT_AMD64_UNWIND 0x70000001 /* unwind information */
440#define SHT_ARM_EXIDX 0x70000001 /* exception index table */ 440#define SHT_ARM_EXIDX 0x70000001 /* exception index table */
441#define SHT_ARM_PREEMPTMAP 0x70000002 /* BPABI DLL dynamic linking  441#define SHT_ARM_PREEMPTMAP 0x70000002 /* BPABI DLL dynamic linking
442 * pre-emption map */ 442 * pre-emption map */
443#define SHT_ARM_ATTRIBUTES 0x70000003 /* Object file compatibility  443#define SHT_ARM_ATTRIBUTES 0x70000003 /* Object file compatibility
444 * attributes */ 444 * attributes */
445#define SHT_ARM_DEBUGOVERLAY 0x70000004 /* See DBGOVL for details */ 445#define SHT_ARM_DEBUGOVERLAY 0x70000004 /* See DBGOVL for details */
446#define SHT_ARM_OVERLAYSECTION 0x70000005 446#define SHT_ARM_OVERLAYSECTION 0x70000005
447#define SHT_MIPS_REGINFO 0x70000006 447#define SHT_MIPS_REGINFO 0x70000006
448#define SHT_MIPS_OPTIONS 0x7000000d 448#define SHT_MIPS_OPTIONS 0x7000000d
449#define SHT_MIPS_DWARF 0x7000001e /* MIPS gcc uses MIPS_DWARF */ 449#define SHT_MIPS_DWARF 0x7000001e /* MIPS gcc uses MIPS_DWARF */
450#define SHT_HIPROC 0x7fffffff 450#define SHT_HIPROC 0x7fffffff
451#define SHT_LOUSER 0x80000000 /* Application-specific range */ 451#define SHT_LOUSER 0x80000000 /* Application-specific range */
452#define SHT_HIUSER 0xffffffff 452#define SHT_HIUSER 0xffffffff
453 453
454/* sh_flags */ 454/* sh_flags */
455#define SHF_WRITE 0x00000001 /* Contains writable data */ 455#define SHF_WRITE 0x00000001 /* Contains writable data */
456#define SHF_ALLOC 0x00000002 /* Occupies memory */ 456#define SHF_ALLOC 0x00000002 /* Occupies memory */
457#define SHF_EXECINSTR 0x00000004 /* Contains executable insns */ 457#define SHF_EXECINSTR 0x00000004 /* Contains executable insns */
458#define SHF_MERGE 0x00000010 /* Might be merged */ 458#define SHF_MERGE 0x00000010 /* Might be merged */
459#define SHF_STRINGS 0x00000020 /* Contains nul terminated strings */ 459#define SHF_STRINGS 0x00000020 /* Contains nul terminated strings */
460#define SHF_INFO_LINK 0x00000040 /* "sh_info" contains SHT index */ 460#define SHF_INFO_LINK 0x00000040 /* "sh_info" contains SHT index */
461#define SHF_LINK_ORDER 0x00000080 /* Preserve order after combining */ 461#define SHF_LINK_ORDER 0x00000080 /* Preserve order after combining */
462#define SHF_OS_NONCONFORMING 0x00000100 /* OS specific handling required */ 462#define SHF_OS_NONCONFORMING 0x00000100 /* OS specific handling required */
463#define SHF_GROUP 0x00000200 /* Is member of a group */ 463#define SHF_GROUP 0x00000200 /* Is member of a group */
464#define SHF_TLS 0x00000400 /* Holds thread-local data */ 464#define SHF_TLS 0x00000400 /* Holds thread-local data */
465#define SHF_MASKOS 0x0ff00000 /* Operating system specific values */ 465#define SHF_MASKOS 0x0ff00000 /* Operating system specific values */
466#define SHF_MASKPROC 0xf0000000 /* Processor-specific values */ 466#define SHF_MASKPROC 0xf0000000 /* Processor-specific values */
467#define SHF_ORDERED 0x40000000 /* Ordering requirement (Solaris) */ 467#define SHF_ORDERED 0x40000000 /* Ordering requirement (Solaris) */
468#define SHF_EXCLUDE 0x80000000 /* Excluded unless unles ref/alloc 468#define SHF_EXCLUDE 0x80000000 /* Excluded unless unles ref/alloc
469 (Solaris).*/ 469 (Solaris).*/
470/* 470/*
471 * Symbol Table 471 * Symbol Table
472 */ 472 */
473typedef struct { 473typedef struct {
474 Elf32_Word st_name; /* Symbol name (.strtab index) */ 474 Elf32_Word st_name; /* Symbol name (.strtab index) */
475 Elf32_Word st_value; /* value of symbol */ 475 Elf32_Word st_value; /* value of symbol */
476 Elf32_Word st_size; /* size of symbol */ 476 Elf32_Word st_size; /* size of symbol */
477 Elf_Byte st_info; /* type / binding attrs */ 477 Elf_Byte st_info; /* type / binding attrs */
478 Elf_Byte st_other; /* unused */ 478 Elf_Byte st_other; /* unused */
479 Elf32_Half st_shndx; /* section index of symbol */ 479 Elf32_Half st_shndx; /* section index of symbol */
480} Elf32_Sym; 480} Elf32_Sym;
481 481
482typedef struct { 482typedef struct {
483 Elf64_Word st_name; /* Symbol name (.strtab index) */ 483 Elf64_Word st_name; /* Symbol name (.strtab index) */
484 Elf_Byte st_info; /* type / binding attrs */ 484 Elf_Byte st_info; /* type / binding attrs */
485 Elf_Byte st_other; /* unused */ 485 Elf_Byte st_other; /* unused */
486 Elf64_Half st_shndx; /* section index of symbol */ 486 Elf64_Half st_shndx; /* section index of symbol */
487 Elf64_Addr st_value; /* value of symbol */ 487 Elf64_Addr st_value; /* value of symbol */
488 Elf64_Xword st_size; /* size of symbol */ 488 Elf64_Xword st_size; /* size of symbol */
489} Elf64_Sym; 489} Elf64_Sym;
490 490
491/* Symbol Table index of the undefined symbol */ 491/* Symbol Table index of the undefined symbol */
492#define ELF_SYM_UNDEFINED 0 492#define ELF_SYM_UNDEFINED 0
493 493
494#define STN_UNDEF 0 /* undefined index */ 494#define STN_UNDEF 0 /* undefined index */
495 495
496/* st_info: Symbol Bindings */ 496/* st_info: Symbol Bindings */
497#define STB_LOCAL 0 /* local symbol */ 497#define STB_LOCAL 0 /* local symbol */
498#define STB_GLOBAL 1 /* global symbol */ 498#define STB_GLOBAL 1 /* global symbol */
499#define STB_WEAK 2 /* weakly defined global symbol */ 499#define STB_WEAK 2 /* weakly defined global symbol */
500#define STB_NUM 3 500#define STB_NUM 3
501 501
502#define STB_LOOS 10 /* Operating system specific range */ 502#define STB_LOOS 10 /* Operating system specific range */
503#define STB_HIOS 12 503#define STB_HIOS 12
504#define STB_LOPROC 13 /* Processor-specific range */ 504#define STB_LOPROC 13 /* Processor-specific range */
505#define STB_HIPROC 15 505#define STB_HIPROC 15
506 506
507/* st_info: Symbol Types */ 507/* st_info: Symbol Types */
508#define STT_NOTYPE 0 /* Type not specified */ 508#define STT_NOTYPE 0 /* Type not specified */
509#define STT_OBJECT 1 /* Associated with a data object */ 509#define STT_OBJECT 1 /* Associated with a data object */
510#define STT_FUNC 2 /* Associated with a function */ 510#define STT_FUNC 2 /* Associated with a function */
511#define STT_SECTION 3 /* Associated with a section */ 511#define STT_SECTION 3 /* Associated with a section */
512#define STT_FILE 4 /* Associated with a file name */ 512#define STT_FILE 4 /* Associated with a file name */
513#define STT_COMMON 5 /* Uninitialised common block */ 513#define STT_COMMON 5 /* Uninitialised common block */
514#define STT_TLS 6 /* Thread local data object */ 514#define STT_TLS 6 /* Thread local data object */
515#define STT_NUM 7 515#define STT_NUM 7
516 516
517#define STT_LOOS 10 /* Operating system specific range */ 517#define STT_LOOS 10 /* Operating system specific range */
518#define STT_HIOS 12 518#define STT_HIOS 12
519#define STT_LOPROC 13 /* Processor-specific range */ 519#define STT_LOPROC 13 /* Processor-specific range */
520#define STT_HIPROC 15 520#define STT_HIPROC 15
521 521
522/* st_other: Visibility Types */ 522/* st_other: Visibility Types */
523#define STV_DEFAULT 0 /* use binding type */ 523#define STV_DEFAULT 0 /* use binding type */
524#define STV_INTERNAL 1 /* not referenced from outside */ 524#define STV_INTERNAL 1 /* not referenced from outside */
525#define STV_HIDDEN 2 /* not visible, may be used via ptr */ 525#define STV_HIDDEN 2 /* not visible, may be used via ptr */
526#define STV_PROTECTED 3 /* visible, not preemptible */ 526#define STV_PROTECTED 3 /* visible, not preemptible */
527#define STV_EXPORTED 4 527#define STV_EXPORTED 4
528#define STV_SINGLETON 5 528#define STV_SINGLETON 5
529#define STV_ELIMINATE 6 529#define STV_ELIMINATE 6
530 530
531/* st_info/st_other utility macros */ 531/* st_info/st_other utility macros */
532#define ELF_ST_BIND(info) ((uint32_t)(info) >> 4) 532#define ELF_ST_BIND(info) ((uint32_t)(info) >> 4)
533#define ELF_ST_TYPE(info) ((uint32_t)(info) & 0xf) 533#define ELF_ST_TYPE(info) ((uint32_t)(info) & 0xf)
534#define ELF_ST_INFO(bind,type) ((Elf_Byte)(((bind) << 4) | \ 534#define ELF_ST_INFO(bind,type) ((Elf_Byte)(((bind) << 4) | \
535 ((type) & 0xf))) 535 ((type) & 0xf)))
536#define ELF_ST_VISIBILITY(other) ((uint32_t)(other) & 3) 536#define ELF_ST_VISIBILITY(other) ((uint32_t)(other) & 3)
537 537
538/* 538/*
539 * Special section indexes 539 * Special section indexes
540 */ 540 */
541#define SHN_UNDEF 0 /* Undefined section */ 541#define SHN_UNDEF 0 /* Undefined section */
542 542
543#define SHN_LORESERVE 0xff00 /* Reserved range */ 543#define SHN_LORESERVE 0xff00 /* Reserved range */
544#define SHN_ABS 0xfff1 /* Absolute symbols */ 544#define SHN_ABS 0xfff1 /* Absolute symbols */
545#define SHN_COMMON 0xfff2 /* Common symbols */ 545#define SHN_COMMON 0xfff2 /* Common symbols */
546#define SHN_XINDEX 0xffff /* Escape -- index stored elsewhere */ 546#define SHN_XINDEX 0xffff /* Escape -- index stored elsewhere */
547#define SHN_HIRESERVE 0xffff 547#define SHN_HIRESERVE 0xffff
548 548
549#define SHN_LOPROC 0xff00 /* Processor-specific range */ 549#define SHN_LOPROC 0xff00 /* Processor-specific range */
550#define SHN_HIPROC 0xff1f 550#define SHN_HIPROC 0xff1f
551#define SHN_LOOS 0xff20 /* Operating system specific range */ 551#define SHN_LOOS 0xff20 /* Operating system specific range */
552#define SHN_HIOS 0xff3f 552#define SHN_HIOS 0xff3f
553 553
554#define SHN_MIPS_ACOMMON 0xff00 554#define SHN_MIPS_ACOMMON 0xff00
555#define SHN_MIPS_TEXT 0xff01 555#define SHN_MIPS_TEXT 0xff01
556#define SHN_MIPS_DATA 0xff02 556#define SHN_MIPS_DATA 0xff02
557#define SHN_MIPS_SCOMMON 0xff03 557#define SHN_MIPS_SCOMMON 0xff03
558 558
559/* 559/*
560 * Relocation Entries 560 * Relocation Entries
561 */ 561 */
562typedef struct { 562typedef struct {
563 Elf32_Word r_offset; /* where to do it */ 563 Elf32_Word r_offset; /* where to do it */
564 Elf32_Word r_info; /* index & type of relocation */ 564 Elf32_Word r_info; /* index & type of relocation */
565} Elf32_Rel; 565} Elf32_Rel;
566 566
567typedef struct { 567typedef struct {
568 Elf32_Word r_offset; /* where to do it */ 568 Elf32_Word r_offset; /* where to do it */
569 Elf32_Word r_info; /* index & type of relocation */ 569 Elf32_Word r_info; /* index & type of relocation */
570 Elf32_Sword r_addend; /* adjustment value */ 570 Elf32_Sword r_addend; /* adjustment value */
571} Elf32_Rela; 571} Elf32_Rela;
572 572
573/* r_info utility macros */ 573/* r_info utility macros */
574#define ELF32_R_SYM(info) ((info) >> 8) 574#define ELF32_R_SYM(info) ((info) >> 8)
575#define ELF32_R_TYPE(info) ((info) & 0xff) 575#define ELF32_R_TYPE(info) ((info) & 0xff)
576#define ELF32_R_INFO(sym, type) (((sym) << 8) + (unsigned char)(type)) 576#define ELF32_R_INFO(sym, type) (((sym) << 8) + (unsigned char)(type))
577 577
578typedef struct { 578typedef struct {
579 Elf64_Addr r_offset; /* where to do it */ 579 Elf64_Addr r_offset; /* where to do it */
580 Elf64_Xword r_info; /* index & type of relocation */ 580 Elf64_Xword r_info; /* index & type of relocation */
581} Elf64_Rel; 581} Elf64_Rel;
582 582
583typedef struct { 583typedef struct {
584 Elf64_Addr r_offset; /* where to do it */ 584 Elf64_Addr r_offset; /* where to do it */
585 Elf64_Xword r_info; /* index & type of relocation */ 585 Elf64_Xword r_info; /* index & type of relocation */
586 Elf64_Sxword r_addend; /* adjustment value */ 586 Elf64_Sxword r_addend; /* adjustment value */
587} Elf64_Rela; 587} Elf64_Rela;
588 588
589/* r_info utility macros */ 589/* r_info utility macros */
590#define ELF64_R_SYM(info) ((info) >> 32) 590#define ELF64_R_SYM(info) ((info) >> 32)
591#define ELF64_R_TYPE(info) ((info) & 0xffffffff) 591#define ELF64_R_TYPE(info) ((info) & 0xffffffff)
592#define ELF64_R_INFO(sym,type) (((sym) << 32) + (type)) 592#define ELF64_R_INFO(sym,type) (((sym) << 32) + (type))
593 593
594/* 594/*
595 * Move entries 595 * Move entries
596 */ 596 */
597typedef struct { 597typedef struct {
598 Elf32_Lword m_value; /* symbol value */ 598 Elf32_Lword m_value; /* symbol value */
599 Elf32_Word m_info; /* size + index */ 599 Elf32_Word m_info; /* size + index */
600 Elf32_Word m_poffset; /* symbol offset */ 600 Elf32_Word m_poffset; /* symbol offset */
601 Elf32_Half m_repeat; /* repeat count */ 601 Elf32_Half m_repeat; /* repeat count */
602 Elf32_Half m_stride; /* stride info */ 602 Elf32_Half m_stride; /* stride info */
603} Elf32_Move; 603} Elf32_Move;
604 604
605#define ELF32_M_SYM(info) ((info) >> 8) 605#define ELF32_M_SYM(info) ((info) >> 8)
606#define ELF32_M_SIZE(info) ((info) & 0xff) 606#define ELF32_M_SIZE(info) ((info) & 0xff)
607#define ELF32_M_INFO(sym, size) (((sym) << 8) + (unsigned char)(size)) 607#define ELF32_M_INFO(sym, size) (((sym) << 8) + (unsigned char)(size))
608 608
609typedef struct { 609typedef struct {
610 Elf64_Lword m_value; /* symbol value */ 610 Elf64_Lword m_value; /* symbol value */
611 Elf64_Xword m_info; /* size + index */ 611 Elf64_Xword m_info; /* size + index */
612 Elf64_Xword m_poffset; /* symbol offset */ 612 Elf64_Xword m_poffset; /* symbol offset */
613 Elf64_Word m_repeat; /* repeat count */ 613 Elf64_Word m_repeat; /* repeat count */
614 Elf64_Word m_stride; /* stride info */ 614 Elf64_Word m_stride; /* stride info */
615} Elf64_Move; 615} Elf64_Move;
616 616
617#define ELF64_M_SYM(info) ((info) >> 8) 617#define ELF64_M_SYM(info) ((info) >> 8)
618#define ELF64_M_SIZE(info) ((info) & 0xff) 618#define ELF64_M_SIZE(info) ((info) & 0xff)
619#define ELF64_M_INFO(sym, size) (((sym) << 8) + (unsigned char)(size)) 619#define ELF64_M_INFO(sym, size) (((sym) << 8) + (unsigned char)(size))
620 620
621/* 621/*
622 * Hardware/software capabilities entry 622 * Hardware/software capabilities entry
623 */ 623 */
624typedef struct { 624typedef struct {
625 Elf32_Word c_tag; /* entry tag value */ 625 Elf32_Word c_tag; /* entry tag value */
626 union { 626 union {
627 Elf32_Addr c_ptr; 627 Elf32_Addr c_ptr;
628 Elf32_Word c_val; 628 Elf32_Word c_val;
629 } c_un; 629 } c_un;
630} Elf32_Cap; 630} Elf32_Cap;
631 631
632typedef struct { 632typedef struct {
633 Elf64_Xword c_tag; /* entry tag value */ 633 Elf64_Xword c_tag; /* entry tag value */
634 union { 634 union {
635 Elf64_Addr c_ptr; 635 Elf64_Addr c_ptr;
636 Elf64_Xword c_val; 636 Elf64_Xword c_val;
637 } c_un; 637 } c_un;
638} Elf64_Cap; 638} Elf64_Cap;
639 639
640/* 640/*
641 * Dynamic Section structure array 641 * Dynamic Section structure array
642 */ 642 */
643typedef struct { 643typedef struct {
644 Elf32_Word d_tag; /* entry tag value */ 644 Elf32_Word d_tag; /* entry tag value */
645 union { 645 union {
646 Elf32_Addr d_ptr; 646 Elf32_Addr d_ptr;
647 Elf32_Word d_val; 647 Elf32_Word d_val;
648 } d_un; 648 } d_un;
649} Elf32_Dyn; 649} Elf32_Dyn;
650 650
651typedef struct { 651typedef struct {
652 Elf64_Xword d_tag; /* entry tag value */ 652 Elf64_Xword d_tag; /* entry tag value */
653 union { 653 union {
654 Elf64_Addr d_ptr; 654 Elf64_Addr d_ptr;
655 Elf64_Xword d_val; 655 Elf64_Xword d_val;
656 } d_un; 656 } d_un;
657} Elf64_Dyn; 657} Elf64_Dyn;
658 658
659/* d_tag */ 659/* d_tag */
660#define DT_NULL 0 /* Marks end of dynamic array */ 660#define DT_NULL 0 /* Marks end of dynamic array */
661#define DT_NEEDED 1 /* Name of needed library (DT_STRTAB offset) */ 661#define DT_NEEDED 1 /* Name of needed library (DT_STRTAB offset) */
662#define DT_PLTRELSZ 2 /* Size, in bytes, of relocations in PLT */ 662#define DT_PLTRELSZ 2 /* Size, in bytes, of relocations in PLT */
663#define DT_PLTGOT 3 /* Address of PLT and/or GOT */ 663#define DT_PLTGOT 3 /* Address of PLT and/or GOT */
664#define DT_HASH 4 /* Address of symbol hash table */ 664#define DT_HASH 4 /* Address of symbol hash table */
665#define DT_STRTAB 5 /* Address of string table */ 665#define DT_STRTAB 5 /* Address of string table */
666#define DT_SYMTAB 6 /* Address of symbol table */ 666#define DT_SYMTAB 6 /* Address of symbol table */
667#define DT_RELA 7 /* Address of Rela relocation table */ 667#define DT_RELA 7 /* Address of Rela relocation table */
668#define DT_RELASZ 8 /* Size, in bytes, of DT_RELA table */ 668#define DT_RELASZ 8 /* Size, in bytes, of DT_RELA table */
669#define DT_RELAENT 9 /* Size, in bytes, of one DT_RELA entry */ 669#define DT_RELAENT 9 /* Size, in bytes, of one DT_RELA entry */
670#define DT_STRSZ 10 /* Size, in bytes, of DT_STRTAB table */ 670#define DT_STRSZ 10 /* Size, in bytes, of DT_STRTAB table */
671#define DT_SYMENT 11 /* Size, in bytes, of one DT_SYMTAB entry */ 671#define DT_SYMENT 11 /* Size, in bytes, of one DT_SYMTAB entry */
672#define DT_INIT 12 /* Address of initialization function */ 672#define DT_INIT 12 /* Address of initialization function */
673#define DT_FINI 13 /* Address of termination function */ 673#define DT_FINI 13 /* Address of termination function */
674#define DT_SONAME 14 /* Shared object name (DT_STRTAB offset) */ 674#define DT_SONAME 14 /* Shared object name (DT_STRTAB offset) */
675#define DT_RPATH 15 /* Library search path (DT_STRTAB offset) */ 675#define DT_RPATH 15 /* Library search path (DT_STRTAB offset) */
676#define DT_SYMBOLIC 16 /* Start symbol search within local object */ 676#define DT_SYMBOLIC 16 /* Start symbol search within local object */
677#define DT_REL 17 /* Address of Rel relocation table */ 677#define DT_REL 17 /* Address of Rel relocation table */
678#define DT_RELSZ 18 /* Size, in bytes, of DT_REL table */ 678#define DT_RELSZ 18 /* Size, in bytes, of DT_REL table */
679#define DT_RELENT 19 /* Size, in bytes, of one DT_REL entry */ 679#define DT_RELENT 19 /* Size, in bytes, of one DT_REL entry */
680#define DT_PLTREL 20 /* Type of PLT relocation entries */ 680#define DT_PLTREL 20 /* Type of PLT relocation entries */
681#define DT_DEBUG 21 /* Used for debugging; unspecified */ 681#define DT_DEBUG 21 /* Used for debugging; unspecified */
682#define DT_TEXTREL 22 /* Relocations might modify non-writable seg */ 682#define DT_TEXTREL 22 /* Relocations might modify non-writable seg */
683#define DT_JMPREL 23 /* Address of relocations associated with PLT */ 683#define DT_JMPREL 23 /* Address of relocations associated with PLT */
684#define DT_BIND_NOW 24 /* Process all relocations at load-time */ 684#define DT_BIND_NOW 24 /* Process all relocations at load-time */
685#define DT_INIT_ARRAY 25 /* Address of initialization function array */ 685#define DT_INIT_ARRAY 25 /* Address of initialization function array */
686#define DT_FINI_ARRAY 26 /* Size, in bytes, of DT_INIT_ARRAY array */ 686#define DT_FINI_ARRAY 26 /* Size, in bytes, of DT_INIT_ARRAY array */
687#define DT_INIT_ARRAYSZ 27 /* Address of termination function array */ 687#define DT_INIT_ARRAYSZ 27 /* Address of termination function array */
688#define DT_FINI_ARRAYSZ 28 /* Size, in bytes, of DT_FINI_ARRAY array*/ 688#define DT_FINI_ARRAYSZ 28 /* Size, in bytes, of DT_FINI_ARRAY array*/
689#define DT_RUNPATH 29 /* overrides DT_RPATH */ 689#define DT_RUNPATH 29 /* overrides DT_RPATH */
690#define DT_FLAGS 30 /* Encodes ORIGIN, SYMBOLIC, TEXTREL, BIND_NOW, STATIC_TLS */ 690#define DT_FLAGS 30 /* Encodes ORIGIN, SYMBOLIC, TEXTREL, BIND_NOW, STATIC_TLS */
691#define DT_ENCODING 31 /* ??? */ 691#define DT_ENCODING 31 /* ??? */
692#define DT_PREINIT_ARRAY 32 /* Address of pre-init function array */ 692#define DT_PREINIT_ARRAY 32 /* Address of pre-init function array */
693#define DT_PREINIT_ARRAYSZ 33 /* Size, in bytes, of DT_PREINIT_ARRAY array */ 693#define DT_PREINIT_ARRAYSZ 33 /* Size, in bytes, of DT_PREINIT_ARRAY array */
694#define DT_NUM 34 694#define DT_NUM 34
695 695
696#define DT_LOOS 0x60000000 /* Operating system specific range */ 696#define DT_LOOS 0x60000000 /* Operating system specific range */
697#define DT_VERSYM 0x6ffffff0 /* Symbol versions */ 697#define DT_VERSYM 0x6ffffff0 /* Symbol versions */
698#define DT_FLAGS_1 0x6ffffffb /* ELF dynamic flags */ 698#define DT_FLAGS_1 0x6ffffffb /* ELF dynamic flags */
699#define DT_VERDEF 0x6ffffffc /* Versions defined by file */ 699#define DT_VERDEF 0x6ffffffc /* Versions defined by file */
700#define DT_VERDEFNUM 0x6ffffffd /* Number of versions defined by file */ 700#define DT_VERDEFNUM 0x6ffffffd /* Number of versions defined by file */
701#define DT_VERNEED 0x6ffffffe /* Versions needed by file */ 701#define DT_VERNEED 0x6ffffffe /* Versions needed by file */
702#define DT_VERNEEDNUM 0x6fffffff /* Number of versions needed by file */ 702#define DT_VERNEEDNUM 0x6fffffff /* Number of versions needed by file */
703#define DT_HIOS 0x6fffffff 703#define DT_HIOS 0x6fffffff
704#define DT_LOPROC 0x70000000 /* Processor-specific range */ 704#define DT_LOPROC 0x70000000 /* Processor-specific range */
705#define DT_HIPROC 0x7fffffff 705#define DT_HIPROC 0x7fffffff
706 706
707/* Flag values for DT_FLAGS */ 707/* Flag values for DT_FLAGS */
708#define DF_ORIGIN 0x00000001 /* uses $ORIGIN */ 708#define DF_ORIGIN 0x00000001 /* uses $ORIGIN */
709#define DF_SYMBOLIC 0x00000002 /* */ 709#define DF_SYMBOLIC 0x00000002 /* */
710#define DF_TEXTREL 0x00000004 /* */ 710#define DF_TEXTREL 0x00000004 /* */
711#define DF_BIND_NOW 0x00000008 /* */ 711#define DF_BIND_NOW 0x00000008 /* */
712#define DF_STATIC_TLS 0x00000010 /* */ 712#define DF_STATIC_TLS 0x00000010 /* */
713 713
714/* Flag values for DT_FLAGS_1 (incomplete) */ 714/* Flag values for DT_FLAGS_1 (incomplete) */
715#define DF_1_BIND_NOW 0x00000001 /* Same as DF_BIND_NOW */ 715#define DF_1_BIND_NOW 0x00000001 /* Same as DF_BIND_NOW */
716#define DF_1_NODELETE 0x00000008 /* Set the RTLD_NODELETE for object */ 716#define DF_1_NODELETE 0x00000008 /* Set the RTLD_NODELETE for object */
717#define DF_1_INITFIRST 0x00000020 /* Object's init/fini take priority */ 717#define DF_1_INITFIRST 0x00000020 /* Object's init/fini take priority */
718#define DF_1_NOOPEN 0x00000040 /* Do not allow loading on dlopen() */ 718#define DF_1_NOOPEN 0x00000040 /* Do not allow loading on dlopen() */
719 719
720/* 720/*
721 * Auxiliary Vectors 721 * Auxiliary Vectors
722 */ 722 */
723typedef struct { 723typedef struct {
724 Elf32_Word a_type; /* 32-bit id */ 724 Elf32_Word a_type; /* 32-bit id */
725 Elf32_Word a_v; /* 32-bit id */ 725 Elf32_Word a_v; /* 32-bit id */
726} Aux32Info; 726} Aux32Info;
727 727
728typedef struct { 728typedef struct {
729 Elf64_Word a_type; /* 32-bit id */ 729 Elf64_Word a_type; /* 32-bit id */
730 Elf64_Xword a_v; /* 64-bit id */ 730 Elf64_Xword a_v; /* 64-bit id */
731} Aux64Info; 731} Aux64Info;
732 732
733/* a_type */ 733/* a_type */
734#define AT_NULL 0 /* Marks end of array */ 734#define AT_NULL 0 /* Marks end of array */
735#define AT_IGNORE 1 /* No meaning, a_un is undefined */ 735#define AT_IGNORE 1 /* No meaning, a_un is undefined */
736#define AT_EXECFD 2 /* Open file descriptor of object file */ 736#define AT_EXECFD 2 /* Open file descriptor of object file */
737#define AT_PHDR 3 /* &phdr[0] */ 737#define AT_PHDR 3 /* &phdr[0] */
738#define AT_PHENT 4 /* sizeof(phdr[0]) */ 738#define AT_PHENT 4 /* sizeof(phdr[0]) */
739#define AT_PHNUM 5 /* # phdr entries */ 739#define AT_PHNUM 5 /* # phdr entries */
740#define AT_PAGESZ 6 /* PAGESIZE */ 740#define AT_PAGESZ 6 /* PAGESIZE */
741#define AT_BASE 7 /* Interpreter base addr */ 741#define AT_BASE 7 /* Interpreter base addr */
742#define AT_FLAGS 8 /* Processor flags */ 742#define AT_FLAGS 8 /* Processor flags */
743#define AT_ENTRY 9 /* Entry address of executable */ 743#define AT_ENTRY 9 /* Entry address of executable */
744#define AT_DCACHEBSIZE 10 /* Data cache block size */ 744#define AT_DCACHEBSIZE 10 /* Data cache block size */
745#define AT_ICACHEBSIZE 11 /* Instruction cache block size */ 745#define AT_ICACHEBSIZE 11 /* Instruction cache block size */
746#define AT_UCACHEBSIZE 12 /* Unified cache block size */ 746#define AT_UCACHEBSIZE 12 /* Unified cache block size */
747#define AT_STACKBASE 13 /* Base address of the main thread */ 747#define AT_STACKBASE 13 /* Base address of the main thread */
748 748
749 /* Vendor specific */ 749 /* Vendor specific */
750#define AT_MIPS_NOTELF 10 /* XXX a_val != 0 -> MIPS XCOFF executable */ 750#define AT_MIPS_NOTELF 10 /* XXX a_val != 0 -> MIPS XCOFF executable */
751 751
752#define AT_EUID 2000 /* euid (solaris compatible numbers) */ 752#define AT_EUID 2000 /* euid (solaris compatible numbers) */
753#define AT_RUID 2001 /* ruid (solaris compatible numbers) */ 753#define AT_RUID 2001 /* ruid (solaris compatible numbers) */
754#define AT_EGID 2002 /* egid (solaris compatible numbers) */ 754#define AT_EGID 2002 /* egid (solaris compatible numbers) */
755#define AT_RGID 2003 /* rgid (solaris compatible numbers) */ 755#define AT_RGID 2003 /* rgid (solaris compatible numbers) */
756 756
757 /* Solaris kernel specific */ 757 /* Solaris kernel specific */
758#define AT_SUN_LDELF 2004 /* dynamic linker's ELF header */ 758#define AT_SUN_LDELF 2004 /* dynamic linker's ELF header */
759#define AT_SUN_LDSHDR 2005 /* dynamic linker's section header */ 759#define AT_SUN_LDSHDR 2005 /* dynamic linker's section header */
760#define AT_SUN_LDNAME 2006 /* dynamic linker's name */ 760#define AT_SUN_LDNAME 2006 /* dynamic linker's name */
761#define AT_SUN_LPGSIZE 2007 /* large pagesize */ 761#define AT_SUN_LPGSIZE 2007 /* large pagesize */
762 762
763 /* Other information */ 763 /* Other information */
764#define AT_SUN_PLATFORM 2008 /* sysinfo(SI_PLATFORM) */ 764#define AT_SUN_PLATFORM 2008 /* sysinfo(SI_PLATFORM) */
765#define AT_SUN_HWCAP 2009 /* process hardware capabilities */ 765#define AT_SUN_HWCAP 2009 /* process hardware capabilities */
766#define AT_SUN_IFLUSH 2010 /* do we need to flush the instruction cache? */ 766#define AT_SUN_IFLUSH 2010 /* do we need to flush the instruction cache? */
767#define AT_SUN_CPU 2011 /* CPU name */ 767#define AT_SUN_CPU 2011 /* CPU name */
768 /* ibcs2 emulation band aid */ 768 /* ibcs2 emulation band aid */
769#define AT_SUN_EMUL_ENTRY 2012 /* coff entry point */ 769#define AT_SUN_EMUL_ENTRY 2012 /* coff entry point */
770#define AT_SUN_EMUL_EXECFD 2013 /* coff file descriptor */ 770#define AT_SUN_EMUL_EXECFD 2013 /* coff file descriptor */
771 /* Executable's fully resolved name */ 771 /* Executable's fully resolved name */
772#define AT_SUN_EXECNAME 2014 772#define AT_SUN_EXECNAME 2014
773 773
774/* 774/*
775 * The header for GNU-style hash sections. 775 * The header for GNU-style hash sections.
776 */ 776 */
777typedef struct { 777typedef struct {
778 uint32_t gh_nbuckets; /* Number of hash buckets. */ 778 uint32_t gh_nbuckets; /* Number of hash buckets. */
779 uint32_t gh_symndx; /* First visible symbol in .dynsym. */ 779 uint32_t gh_symndx; /* First visible symbol in .dynsym. */
780 uint32_t gh_maskwords; /* #maskwords used in bloom filter. */ 780 uint32_t gh_maskwords; /* #maskwords used in bloom filter. */
781 uint32_t gh_shift2; /* Bloom filter shift count. */ 781 uint32_t gh_shift2; /* Bloom filter shift count. */
782} Elf_GNU_Hash_Header; 782} Elf_GNU_Hash_Header;
783 783
784/* 784/*
785 * Note Headers 785 * Note Headers
786 */ 786 */
787typedef struct { 787typedef struct {
788 Elf32_Word n_namesz; 788 Elf32_Word n_namesz;
789 Elf32_Word n_descsz; 789 Elf32_Word n_descsz;
790 Elf32_Word n_type; 790 Elf32_Word n_type;
791} Elf32_Nhdr; 791} Elf32_Nhdr;
792 792
793typedef struct { 793typedef struct {
794 Elf64_Word n_namesz; 794 Elf64_Word n_namesz;
795 Elf64_Word n_descsz; 795 Elf64_Word n_descsz;
796 Elf64_Word n_type; 796 Elf64_Word n_type;
797} Elf64_Nhdr; 797} Elf64_Nhdr;
798 798
799#define ELF_NOTE_GNU_NAMESZ 4 799#define ELF_NOTE_GNU_NAMESZ 4
800#define ELF_NOTE_GNU_NAME "GNU\0" 800#define ELF_NOTE_GNU_NAME "GNU\0"
801 801
802/* 802/*
803 * GNU-specific note type: ABI tag 803 * GNU-specific note type: ABI tag
804 * name: GNU\0 804 * name: GNU\0
805 * namesz: 4 805 * namesz: 4
806 * desc: 806 * desc:
807 * word[0]: OS tag 807 * word[0]: OS tag
808 * word[1]: major version 808 * word[1]: major version
809 * word[2]: minor version 809 * word[2]: minor version
810 * word[3]: teeny version 810 * word[3]: teeny version
811 * descsz: 16 811 * descsz: 16
812 */ 812 */
813/* GNU-specific note name and description sizes */ 813/* GNU-specific note name and description sizes */
814#define ELF_NOTE_TYPE_ABI_TAG 1 814#define ELF_NOTE_TYPE_ABI_TAG 1
815#define ELF_NOTE_ABI_NAME ELF_NOTE_GNU_NAME 815#define ELF_NOTE_ABI_NAME ELF_NOTE_GNU_NAME
816#define ELF_NOTE_ABI_NAMESZ ELF_NOTE_GNU_NAMESZ 816#define ELF_NOTE_ABI_NAMESZ ELF_NOTE_GNU_NAMESZ
817#define ELF_NOTE_ABI_DESCSZ 16 817#define ELF_NOTE_ABI_DESCSZ 16
818/* GNU-specific OS/version value stuff */ 818/* GNU-specific OS/version value stuff */
819#define ELF_NOTE_ABI_OS_LINUX 0 819#define ELF_NOTE_ABI_OS_LINUX 0
820#define ELF_NOTE_ABI_OS_HURD 1 820#define ELF_NOTE_ABI_OS_HURD 1
821#define ELF_NOTE_ABI_OS_SOLARIS 2 821#define ELF_NOTE_ABI_OS_SOLARIS 2
822#define ELF_NOTE_ABI_OS_KFREEBSD 3 822#define ELF_NOTE_ABI_OS_KFREEBSD 3
823#define ELF_NOTE_ABI_OS_KNETBSD 4 823#define ELF_NOTE_ABI_OS_KNETBSD 4
824 824
 825/* Old gcc style, under the ABI tag */
 826#define ELF_NOTE_OGCC_NAMESZ 8
 827#define ELF_NOTE_OGCC_NAME "01.01\0\0\0\0"
 828#define ELF_NOTE_OGCC_DESCSZ 0
 829
825/* 830/*
826 * GNU-specific note type: Hardware capabilities 831 * GNU-specific note type: Hardware capabilities
827 * name: GNU\0 832 * name: GNU\0
828 * namesz: 4 833 * namesz: 4
829 * desc: 834 * desc:
830 * word[0]: Number of entries 835 * word[0]: Number of entries
831 * word[1]: Bitmask of enabled entries 836 * word[1]: Bitmask of enabled entries
832 * Followed by a byte id, and a NUL terminated string per entry 837 * Followed by a byte id, and a NUL terminated string per entry
833 * descsz: variable 838 * descsz: variable
834 */ 839 */
835#define ELF_NOTE_TYPE_GNU_HWCAP 2 840#define ELF_NOTE_TYPE_GNU_HWCAP 2
836 841
837/* 842/*
838 * GNU-specific note type: Build ID generated by ld 843 * GNU-specific note type: Build ID generated by ld
839 * name: GNU\0 844 * name: GNU\0
840 * desc: 845 * desc:
841 * word[0..4] SHA1 [default]  846 * word[0..4] SHA1 [default]
842 * or 847 * or
843 * word[0..3] md5 or uuid 848 * word[0..3] md5 or uuid
844 * descsz: 16 or 20 849 * descsz: 16 or 20
845 */ 850 */
846#define ELF_NOTE_TYPE_GNU_BUILD_ID 3 851#define ELF_NOTE_TYPE_GNU_BUILD_ID 3
847 852
848/* SuSE-specific note type: ABI 853/* SuSE-specific note type: ABI
849 * name: SuSE\0 854 * name: SuSE\0
850 * namesz: 5 855 * namesz: 5
851 * desc: 856 * desc:
852 * half[0] = MMmm 857 * half[0] = MMmm
853 * 858 *
854 * M = product major version 859 * M = product major version
855 * m = product minor version 860 * m = product minor version
856 * descsz: 2 861 * descsz: 2
857 */ 862 */
858#define ELF_NOTE_TYPE_SUSE_TAG 1 863#define ELF_NOTE_TYPE_SUSE_TAG 1
859/* SuSE-specific note name and description sizes */ 864/* SuSE-specific note name and description sizes */
860#define ELF_NOTE_SUSE_NAMESZ 5 865#define ELF_NOTE_SUSE_NAMESZ 5
861#define ELF_NOTE_SUSE_DESCSZ 2 866#define ELF_NOTE_SUSE_DESCSZ 2
862/* SuSE-specific note name */ 867/* SuSE-specific note name */
863#define ELF_NOTE_SUSE_NAME "SuSE\0" 868#define ELF_NOTE_SUSE_NAME "SuSE\0"
864 869
865/* SuSE-specific note type: version 870/* SuSE-specific note type: version
866 * name: SuSE\0\0\0\0 871 * name: SuSE\0\0\0\0
867 * namesz: 8 872 * namesz: 8
868 * desc:  873 * desc:
869 * word[0] = VVTTMMmm 874 * word[0] = VVTTMMmm
870 * 875 *
871 * V = version of following data 876 * V = version of following data
872 * T = product type: [box, sles, nld, whatever] 877 * T = product type: [box, sles, nld, whatever]
873 * M = product major version 878 * M = product major version
874 * m = product minor version 879 * m = product minor version
875 * descsz: 8 880 * descsz: 8
876 */ 881 */
877#define ELF_NOTE_TYPE_SUSE_VERSION_TAG 0x45537553 /* SuSE in LE */ 882#define ELF_NOTE_TYPE_SUSE_VERSION_TAG 0x45537553 /* SuSE in LE */
878/* SuSE-specific note name and description sizes */ 883/* SuSE-specific note name and description sizes */
879#define ELF_NOTE_SUSE_VERSION_NAMESZ 8 884#define ELF_NOTE_SUSE_VERSION_NAMESZ 8
880#define ELF_NOTE_SUSE_VERSION_DESCSZ 8 885#define ELF_NOTE_SUSE_VERSION_DESCSZ 8
881/* SuSE-specific note name */ 886/* SuSE-specific note name */
882#define ELF_NOTE_SUSE_VERSION_NAME "SuSE\0\0\0\0" 887#define ELF_NOTE_SUSE_VERSION_NAME "SuSE\0\0\0\0"
883 888
 889/* Go-specific note type: buildid
 890 * name: Go\0\0
 891 * namesz: 4
 892 * desc:
 893 * words[10]
 894 * descsz: 40
 895 */
 896#define ELF_NOTE_TYPE_GO_BUILDID_TAG 4
 897#define ELF_NOTE_GO_BUILDID_NAMESZ 4
 898#define ELF_NOTE_GO_BUILDID_DESCSZ 40
 899#define ELF_NOTE_GO_BUILDID_NAME "Go\0\0"
 900
884/* NetBSD-specific note type: Emulation name. 901/* NetBSD-specific note type: Emulation name.
885 * name: NetBSD\0\0 902 * name: NetBSD\0\0
886 * namesz: 8 903 * namesz: 8
887 * desc:  904 * desc:
888 * word[0]: MMmmrrpp00 905 * word[0]: MMmmrrpp00
889 * 906 *
890 * M = major version 907 * M = major version
891 * m = minor version 908 * m = minor version
892 * r = release ["",A-Z,Z[A-Z] but numeric] 909 * r = release ["",A-Z,Z[A-Z] but numeric]
893 * p = patchlevel 910 * p = patchlevel
894 * descsz: 4 911 * descsz: 4
895 */ 912 */
896#define ELF_NOTE_TYPE_NETBSD_TAG 1 913#define ELF_NOTE_TYPE_NETBSD_TAG 1
897/* NetBSD-specific note name and description sizes */ 914/* NetBSD-specific note name and description sizes */
898#define ELF_NOTE_NETBSD_NAMESZ 7 915#define ELF_NOTE_NETBSD_NAMESZ 7
899#define ELF_NOTE_NETBSD_DESCSZ 4 916#define ELF_NOTE_NETBSD_DESCSZ 4
900/* NetBSD-specific note name */ 917/* NetBSD-specific note name */
901#define ELF_NOTE_NETBSD_NAME "NetBSD\0\0" 918#define ELF_NOTE_NETBSD_NAME "NetBSD\0\0"
902 919
903/* NetBSD-specific note type: Checksum.  920/* NetBSD-specific note type: Checksum.
904 * There should be 1 NOTE per PT_LOAD section. 921 * There should be 1 NOTE per PT_LOAD section.
905 * name: ??? 922 * name: ???
906 * namesz: ??? 923 * namesz: ???
907 * desc: 924 * desc:
908 * a tuple of <phnum>(16),<chk-type>(16),<chk-value>. 925 * a tuple of <phnum>(16),<chk-type>(16),<chk-value>.
909 * descsz: ??? 926 * descsz: ???
910 */ 927 */
911#define ELF_NOTE_TYPE_CHECKSUM_TAG 2 928#define ELF_NOTE_TYPE_CHECKSUM_TAG 2
912#define ELF_NOTE_CHECKSUM_CRC32 1 929#define ELF_NOTE_CHECKSUM_CRC32 1
913#define ELF_NOTE_CHECKSUM_MD5 2 930#define ELF_NOTE_CHECKSUM_MD5 2
914#define ELF_NOTE_CHECKSUM_SHA1 3 931#define ELF_NOTE_CHECKSUM_SHA1 3
915#define ELF_NOTE_CHECKSUM_SHA256 4 932#define ELF_NOTE_CHECKSUM_SHA256 4
916 933
917/* 934/*
918 * NetBSD-specific note type: PaX. 935 * NetBSD-specific note type: PaX.
919 * There should be 1 NOTE per executable. 936 * There should be 1 NOTE per executable.
920 * name: PaX\0 937 * name: PaX\0
921 * namesz: 4 938 * namesz: 4
922 * desc: 939 * desc:
923 * word[0]: capability bitmask 940 * word[0]: capability bitmask
924 * descsz: 4 941 * descsz: 4
925 */ 942 */
926#define ELF_NOTE_TYPE_PAX_TAG 3 943#define ELF_NOTE_TYPE_PAX_TAG 3
927#define ELF_NOTE_PAX_MPROTECT 0x01 /* Force enable Mprotect */ 944#define ELF_NOTE_PAX_MPROTECT 0x01 /* Force enable Mprotect */
928#define ELF_NOTE_PAX_NOMPROTECT 0x02 /* Force disable Mprotect */ 945#define ELF_NOTE_PAX_NOMPROTECT 0x02 /* Force disable Mprotect */
929#define ELF_NOTE_PAX_GUARD 0x04 /* Force enable Segvguard */ 946#define ELF_NOTE_PAX_GUARD 0x04 /* Force enable Segvguard */
930#define ELF_NOTE_PAX_NOGUARD 0x08 /* Force disable Servguard */ 947#define ELF_NOTE_PAX_NOGUARD 0x08 /* Force disable Servguard */
931#define ELF_NOTE_PAX_ASLR 0x10 /* Force enable ASLR */ 948#define ELF_NOTE_PAX_ASLR 0x10 /* Force enable ASLR */
932#define ELF_NOTE_PAX_NOASLR 0x20 /* Force disable ASLR */ 949#define ELF_NOTE_PAX_NOASLR 0x20 /* Force disable ASLR */
933#define ELF_NOTE_PAX_NAMESZ 4 950#define ELF_NOTE_PAX_NAMESZ 4
934#define ELF_NOTE_PAX_NAME "PaX\0" 951#define ELF_NOTE_PAX_NAME "PaX\0"
935#define ELF_NOTE_PAX_DESCSZ 4 952#define ELF_NOTE_PAX_DESCSZ 4
936 953
937/* 954/*
938 * NetBSD-specific core file information. 955 * NetBSD-specific core file information.
939 * 956 *
940 * NetBSD ELF core files use notes to provide information about 957 * NetBSD ELF core files use notes to provide information about
941 * the process's state. The note name is "NetBSD-CORE" for 958 * the process's state. The note name is "NetBSD-CORE" for
942 * information that is global to the process, and "NetBSD-CORE@nn", 959 * information that is global to the process, and "NetBSD-CORE@nn",
943 * where "nn" is the lwpid of the LWP that the information belongs 960 * where "nn" is the lwpid of the LWP that the information belongs
944 * to (such as register state). 961 * to (such as register state).
945 * 962 *
946 * We use the following note identifiers: 963 * We use the following note identifiers:
947 * 964 *
948 * ELF_NOTE_NETBSD_CORE_PROCINFO 965 * ELF_NOTE_NETBSD_CORE_PROCINFO
949 * Note is a "netbsd_elfcore_procinfo" structure. 966 * Note is a "netbsd_elfcore_procinfo" structure.
950 * 967 *
951 * We also use ptrace(2) request numbers (the ones that exist in 968 * We also use ptrace(2) request numbers (the ones that exist in
952 * machine-dependent space) to identify register info notes. The 969 * machine-dependent space) to identify register info notes. The
953 * info in such notes is in the same format that ptrace(2) would 970 * info in such notes is in the same format that ptrace(2) would
954 * export that information. 971 * export that information.
955 * 972 *
956 * Please try to keep the members of this structure nicely aligned, 973 * Please try to keep the members of this structure nicely aligned,
957 * and if you add elements, add them to the end and bump the version. 974 * and if you add elements, add them to the end and bump the version.
958 */ 975 */
959 976
960#define ELF_NOTE_NETBSD_CORE_NAME "NetBSD-CORE" 977#define ELF_NOTE_NETBSD_CORE_NAME "NetBSD-CORE"
961 978
962#define ELF_NOTE_NETBSD_CORE_PROCINFO 1 979#define ELF_NOTE_NETBSD_CORE_PROCINFO 1
963 980
964#define NETBSD_ELFCORE_PROCINFO_VERSION 1 981#define NETBSD_ELFCORE_PROCINFO_VERSION 1
965 982
966struct netbsd_elfcore_procinfo { 983struct netbsd_elfcore_procinfo {
967 /* Version 1 fields start here. */ 984 /* Version 1 fields start here. */
968 uint32_t cpi_version; /* our version */ 985 uint32_t cpi_version; /* our version */
969 uint32_t cpi_cpisize; /* sizeof(this struct) */ 986 uint32_t cpi_cpisize; /* sizeof(this struct) */
970 uint32_t cpi_signo; /* killing signal */ 987 uint32_t cpi_signo; /* killing signal */
971 uint32_t cpi_sigcode; /* signal code */ 988 uint32_t cpi_sigcode; /* signal code */
972 uint32_t cpi_sigpend[4]; /* pending signals */ 989 uint32_t cpi_sigpend[4]; /* pending signals */
973 uint32_t cpi_sigmask[4]; /* blocked signals */ 990 uint32_t cpi_sigmask[4]; /* blocked signals */
974 uint32_t cpi_sigignore[4]; /* ignored signals */ 991 uint32_t cpi_sigignore[4]; /* ignored signals */
975 uint32_t cpi_sigcatch[4]; /* caught signals */ 992 uint32_t cpi_sigcatch[4]; /* caught signals */
976 int32_t cpi_pid; /* process ID */ 993 int32_t cpi_pid; /* process ID */
977 int32_t cpi_ppid; /* parent process ID */ 994 int32_t cpi_ppid; /* parent process ID */
978 int32_t cpi_pgrp; /* process group ID */ 995 int32_t cpi_pgrp; /* process group ID */
979 int32_t cpi_sid; /* session ID */ 996 int32_t cpi_sid; /* session ID */
980 uint32_t cpi_ruid; /* real user ID */ 997 uint32_t cpi_ruid; /* real user ID */
981 uint32_t cpi_euid; /* effective user ID */ 998 uint32_t cpi_euid; /* effective user ID */
982 uint32_t cpi_svuid; /* saved user ID */ 999 uint32_t cpi_svuid; /* saved user ID */
983 uint32_t cpi_rgid; /* real group ID */ 1000 uint32_t cpi_rgid; /* real group ID */
984 uint32_t cpi_egid; /* effective group ID */ 1001 uint32_t cpi_egid; /* effective group ID */
985 uint32_t cpi_svgid; /* saved group ID */ 1002 uint32_t cpi_svgid; /* saved group ID */
986 uint32_t cpi_nlwps; /* number of LWPs */ 1003 uint32_t cpi_nlwps; /* number of LWPs */
987 int8_t cpi_name[32]; /* copy of p->p_comm */ 1004 int8_t cpi_name[32]; /* copy of p->p_comm */
988 /* Add version 2 fields below here. */ 1005 /* Add version 2 fields below here. */
989 int32_t cpi_siglwp; /* LWP target of killing signal */ 1006 int32_t cpi_siglwp; /* LWP target of killing signal */
990}; 1007};
991 1008
992/* 1009/*
993 * NetBSD-specific note type: MACHINE_ARCH. 1010 * NetBSD-specific note type: MACHINE_ARCH.
994 * There should be 1 NOTE per executable. 1011 * There should be 1 NOTE per executable.
995 * name: NetBSD\0 1012 * name: NetBSD\0
996 * namesz: 7 1013 * namesz: 7
997 * desc: string 1014 * desc: string
998 * descsz: variable 1015 * descsz: variable
999 */ 1016 */
1000#define ELF_NOTE_TYPE_MARCH_TAG 5 1017#define ELF_NOTE_TYPE_MARCH_TAG 5
1001/* NetBSD-specific note name and description sizes */ 1018/* NetBSD-specific note name and description sizes */
1002#define ELF_NOTE_MARCH_NAMESZ ELF_NOTE_NETBSD_NAMESZ 1019#define ELF_NOTE_MARCH_NAMESZ ELF_NOTE_NETBSD_NAMESZ
1003/* NetBSD-specific note name */ 1020/* NetBSD-specific note name */
1004#define ELF_NOTE_MARCH_NAME ELF_NOTE_NETBSD_NAME 1021#define ELF_NOTE_MARCH_NAME ELF_NOTE_NETBSD_NAME
1005 1022
1006/* 1023/*
1007 * NetBSD-specific note type: MCMODEL 1024 * NetBSD-specific note type: MCMODEL
1008 * There should be 1 NOTE per executable. 1025 * There should be 1 NOTE per executable.
1009 * name: NetBSD\0 1026 * name: NetBSD\0
1010 * namesz: 7 1027 * namesz: 7
1011 * code model: string 1028 * code model: string
1012 */ 1029 */
1013 1030
1014#define ELF_NOTE_TYPE_MCMODEL_TAG 6 1031#define ELF_NOTE_TYPE_MCMODEL_TAG 6
1015/* NetBSD-specific note name and description sizes */ 1032/* NetBSD-specific note name and description sizes */
1016#define ELF_NOTE_MCMODEL_NAMESZ ELF_NOTE_NETBSD_NAMESZ 1033#define ELF_NOTE_MCMODEL_NAMESZ ELF_NOTE_NETBSD_NAMESZ
1017/* NetBSD-specific note name */ 1034/* NetBSD-specific note name */
1018#define ELF_NOTE_MCMODEL_NAME ELF_NOTE_NETBSD_NAME 1035#define ELF_NOTE_MCMODEL_NAME ELF_NOTE_NETBSD_NAME
1019 1036
1020 1037
1021#if !defined(ELFSIZE) && defined(ARCH_ELFSIZE) 1038#if !defined(ELFSIZE) && defined(ARCH_ELFSIZE)
1022#define ELFSIZE ARCH_ELFSIZE 1039#define ELFSIZE ARCH_ELFSIZE
1023#endif 1040#endif
1024 1041
1025#if defined(ELFSIZE) 1042#if defined(ELFSIZE)
1026#define CONCAT(x,y) __CONCAT(x,y) 1043#define CONCAT(x,y) __CONCAT(x,y)
1027#define ELFNAME(x) CONCAT(elf,CONCAT(ELFSIZE,CONCAT(_,x))) 1044#define ELFNAME(x) CONCAT(elf,CONCAT(ELFSIZE,CONCAT(_,x)))
1028#define ELFNAME2(x,y) CONCAT(x,CONCAT(_elf,CONCAT(ELFSIZE,CONCAT(_,y)))) 1045#define ELFNAME2(x,y) CONCAT(x,CONCAT(_elf,CONCAT(ELFSIZE,CONCAT(_,y))))
1029#define ELFNAMEEND(x) CONCAT(x,CONCAT(_elf,ELFSIZE)) 1046#define ELFNAMEEND(x) CONCAT(x,CONCAT(_elf,ELFSIZE))
1030#define ELFDEFNNAME(x) CONCAT(ELF,CONCAT(ELFSIZE,CONCAT(_,x))) 1047#define ELFDEFNNAME(x) CONCAT(ELF,CONCAT(ELFSIZE,CONCAT(_,x)))
1031#endif 1048#endif
1032 1049
1033#if defined(ELFSIZE) && (ELFSIZE == 32) 1050#if defined(ELFSIZE) && (ELFSIZE == 32)
1034#define Elf_Ehdr Elf32_Ehdr 1051#define Elf_Ehdr Elf32_Ehdr
1035#define Elf_Phdr Elf32_Phdr 1052#define Elf_Phdr Elf32_Phdr
1036#define Elf_Shdr Elf32_Shdr 1053#define Elf_Shdr Elf32_Shdr
1037#define Elf_Sym Elf32_Sym 1054#define Elf_Sym Elf32_Sym
1038#define Elf_Rel Elf32_Rel 1055#define Elf_Rel Elf32_Rel
1039#define Elf_Rela Elf32_Rela 1056#define Elf_Rela Elf32_Rela
1040#define Elf_Dyn Elf32_Dyn 1057#define Elf_Dyn Elf32_Dyn
1041#define Elf_Word Elf32_Word 1058#define Elf_Word Elf32_Word
1042#define Elf_Sword Elf32_Sword 1059#define Elf_Sword Elf32_Sword
1043#define Elf_Half Elf32_Half 1060#define Elf_Half Elf32_Half
1044#define Elf_Addr Elf32_Addr 1061#define Elf_Addr Elf32_Addr
1045#define Elf_Off Elf32_Off 1062#define Elf_Off Elf32_Off
1046#define Elf_SOff Elf32_SOff 1063#define Elf_SOff Elf32_SOff
1047#define Elf_Nhdr Elf32_Nhdr 1064#define Elf_Nhdr Elf32_Nhdr
1048#define Elf_Verdef Elf32_Verdef 1065#define Elf_Verdef Elf32_Verdef
1049#define Elf_Verdaux Elf32_Verdaux 1066#define Elf_Verdaux Elf32_Verdaux
1050#define Elf_Verneed Elf32_Verneed 1067#define Elf_Verneed Elf32_Verneed
1051#define Elf_Vernaux Elf32_Vernaux 1068#define Elf_Vernaux Elf32_Vernaux
1052#define Elf_Versym Elf32_Versym 1069#define Elf_Versym Elf32_Versym
1053 1070
1054#define ELF_R_SYM ELF32_R_SYM 1071#define ELF_R_SYM ELF32_R_SYM
1055#define ELF_R_TYPE ELF32_R_TYPE 1072#define ELF_R_TYPE ELF32_R_TYPE
1056#define ELFCLASS ELFCLASS32 1073#define ELFCLASS ELFCLASS32
1057 1074
1058#define AuxInfo Aux32Info 1075#define AuxInfo Aux32Info
1059#elif defined(ELFSIZE) && (ELFSIZE == 64) 1076#elif defined(ELFSIZE) && (ELFSIZE == 64)
1060#define Elf_Ehdr Elf64_Ehdr 1077#define Elf_Ehdr Elf64_Ehdr
1061#define Elf_Phdr Elf64_Phdr 1078#define Elf_Phdr Elf64_Phdr
1062#define Elf_Shdr Elf64_Shdr 1079#define Elf_Shdr Elf64_Shdr
1063#define Elf_Sym Elf64_Sym 1080#define Elf_Sym Elf64_Sym
1064#define Elf_Rel Elf64_Rel 1081#define Elf_Rel Elf64_Rel
1065#define Elf_Rela Elf64_Rela 1082#define Elf_Rela Elf64_Rela
1066#define Elf_Dyn Elf64_Dyn 1083#define Elf_Dyn Elf64_Dyn
1067#define Elf_Word Elf64_Word 1084#define Elf_Word Elf64_Word
1068#define Elf_Sword Elf64_Sword 1085#define Elf_Sword Elf64_Sword
1069#define Elf_Half Elf64_Half 1086#define Elf_Half Elf64_Half
1070#define Elf_Addr Elf64_Addr 1087#define Elf_Addr Elf64_Addr
1071#define Elf_Off Elf64_Off 1088#define Elf_Off Elf64_Off
1072#define Elf_SOff Elf64_SOff 1089#define Elf_SOff Elf64_SOff
1073#define Elf_Nhdr Elf64_Nhdr 1090#define Elf_Nhdr Elf64_Nhdr
1074#define Elf_Verdef Elf64_Verdef 1091#define Elf_Verdef Elf64_Verdef
1075#define Elf_Verdaux Elf64_Verdaux 1092#define Elf_Verdaux Elf64_Verdaux
1076#define Elf_Verneed Elf64_Verneed 1093#define Elf_Verneed Elf64_Verneed
1077#define Elf_Vernaux Elf64_Vernaux 1094#define Elf_Vernaux Elf64_Vernaux
1078#define Elf_Versym Elf64_Versym 1095#define Elf_Versym Elf64_Versym
1079 1096
1080#define ELF_R_SYM ELF64_R_SYM 1097#define ELF_R_SYM ELF64_R_SYM
1081#define ELF_R_TYPE ELF64_R_TYPE 1098#define ELF_R_TYPE ELF64_R_TYPE
1082#define ELFCLASS ELFCLASS64 1099#define ELFCLASS ELFCLASS64
1083 1100
1084#define AuxInfo Aux64Info 1101#define AuxInfo Aux64Info
1085#endif 1102#endif
1086 1103
1087#ifndef Elf_Symindx 1104#ifndef Elf_Symindx
1088#define Elf_Symindx uint32_t 1105#define Elf_Symindx uint32_t
1089#endif 1106#endif
1090 1107
1091#define ELF32_ST_BIND(info) ELF_ST_BIND(info) 1108#define ELF32_ST_BIND(info) ELF_ST_BIND(info)
1092#define ELF32_ST_TYPE(info) ELF_ST_TYPE(info) 1109#define ELF32_ST_TYPE(info) ELF_ST_TYPE(info)
1093#define ELF32_ST_INFO(bind,type) ELF_ST_INFO(bind,type) 1110#define ELF32_ST_INFO(bind,type) ELF_ST_INFO(bind,type)
1094#define ELF32_ST_VISIBILITY(other) ELF_ST_VISIBILITY(other) 1111#define ELF32_ST_VISIBILITY(other) ELF_ST_VISIBILITY(other)
1095 1112
1096#define ELF64_ST_BIND(info) ELF_ST_BIND(info) 1113#define ELF64_ST_BIND(info) ELF_ST_BIND(info)
1097#define ELF64_ST_TYPE(info) ELF_ST_TYPE(info) 1114#define ELF64_ST_TYPE(info) ELF_ST_TYPE(info)
1098#define ELF64_ST_INFO(bind,type) ELF_ST_INFO(bind,type) 1115#define ELF64_ST_INFO(bind,type) ELF_ST_INFO(bind,type)
1099#define ELF64_ST_VISIBILITY(other) ELF_ST_VISIBILITY(other) 1116#define ELF64_ST_VISIBILITY(other) ELF_ST_VISIBILITY(other)
1100 1117
1101typedef struct { 1118typedef struct {
1102 Elf32_Half si_boundto; /* direct bindings - symbol bound to */ 1119 Elf32_Half si_boundto; /* direct bindings - symbol bound to */
1103 Elf32_Half si_flags; /* per symbol flags */ 1120 Elf32_Half si_flags; /* per symbol flags */
1104} Elf32_Syminfo; 1121} Elf32_Syminfo;
1105 1122
1106typedef struct { 1123typedef struct {
1107 Elf64_Word si_boundto; /* direct bindings - symbol bound to */ 1124 Elf64_Word si_boundto; /* direct bindings - symbol bound to */
1108 Elf64_Word si_flags; /* per symbol flags */ 1125 Elf64_Word si_flags; /* per symbol flags */
1109} Elf64_Syminfo; 1126} Elf64_Syminfo;
1110 1127
1111#define SYMINFO_FLG_DIRECT 0x0001 /* symbol ref has direct association 1128#define SYMINFO_FLG_DIRECT 0x0001 /* symbol ref has direct association
1112 to object containing definition */ 1129 to object containing definition */
1113#define SYMINFO_FLG_PASSTHRU 0x0002 /* ignored - see SYMINFO_FLG_FILTER */ 1130#define SYMINFO_FLG_PASSTHRU 0x0002 /* ignored - see SYMINFO_FLG_FILTER */
1114#define SYMINFO_FLG_COPY 0x0004 /* symbol is a copy-reloc */ 1131#define SYMINFO_FLG_COPY 0x0004 /* symbol is a copy-reloc */
1115#define SYMINFO_FLG_LAZYLOAD 0x0008 /* object containing defn should be 1132#define SYMINFO_FLG_LAZYLOAD 0x0008 /* object containing defn should be
1116 lazily-loaded */ 1133 lazily-loaded */
1117#define SYMINFO_FLG_DIRECTBIND 0x0010 /* ref should be bound directly to 1134#define SYMINFO_FLG_DIRECTBIND 0x0010 /* ref should be bound directly to
1118 object containing definition */ 1135 object containing definition */
1119#define SYMINFO_FLG_NOEXTDIRECT 0x0020 /* don't let an external reference 1136#define SYMINFO_FLG_NOEXTDIRECT 0x0020 /* don't let an external reference
1120 directly bind to this symbol */ 1137 directly bind to this symbol */
1121#define SYMINFO_FLG_FILTER 0x0002 /* symbol ref is associated to a */ 1138#define SYMINFO_FLG_FILTER 0x0002 /* symbol ref is associated to a */
1122#define SYMINFO_FLG_AUXILIARY 0x0040 /* standard or auxiliary filter */ 1139#define SYMINFO_FLG_AUXILIARY 0x0040 /* standard or auxiliary filter */
1123 1140
1124#define SYMINFO_BT_SELF 0xffff /* symbol bound to self */ 1141#define SYMINFO_BT_SELF 0xffff /* symbol bound to self */
1125#define SYMINFO_BT_PARENT 0xfffe /* symbol bound to parent */ 1142#define SYMINFO_BT_PARENT 0xfffe /* symbol bound to parent */
1126#define SYMINFO_BT_NONE 0xfffd /* no special symbol binding */ 1143#define SYMINFO_BT_NONE 0xfffd /* no special symbol binding */
1127#define SYMINFO_BT_EXTERN 0xfffc /* symbol defined as external */ 1144#define SYMINFO_BT_EXTERN 0xfffc /* symbol defined as external */
1128#define SYMINFO_BT_LOWRESERVE 0xff00 /* beginning of reserved entries */ 1145#define SYMINFO_BT_LOWRESERVE 0xff00 /* beginning of reserved entries */
1129 1146
1130#define SYMINFO_NONE 0 /* Syminfo version */ 1147#define SYMINFO_NONE 0 /* Syminfo version */
1131#define SYMINFO_CURRENT 1 1148#define SYMINFO_CURRENT 1
1132#define SYMINFO_NUM 2 1149#define SYMINFO_NUM 2
1133 1150
1134/* 1151/*
1135 * These constants are used for Elf32_Verdef struct's version number.  1152 * These constants are used for Elf32_Verdef struct's version number.
1136 */ 1153 */
1137#define VER_DEF_NONE 0 1154#define VER_DEF_NONE 0
1138#define VER_DEF_CURRENT 1 1155#define VER_DEF_CURRENT 1
1139 1156
1140/* 1157/*
1141 * These constants are used for Elf32_Verdef struct's vd_ndx. 1158 * These constants are used for Elf32_Verdef struct's vd_ndx.
1142 */ 1159 */
1143#define VER_DEF_IDX(x) VER_NDX(x) 1160#define VER_DEF_IDX(x) VER_NDX(x)
1144 1161
1145/* 1162/*
1146 * These constants are used for Elf32_Verdef struct's vd_flags.  1163 * These constants are used for Elf32_Verdef struct's vd_flags.
1147 */ 1164 */
1148#define VER_FLG_BASE 0x1 1165#define VER_FLG_BASE 0x1
1149#define VER_FLG_WEAK 0x2 1166#define VER_FLG_WEAK 0x2
1150 1167
1151/* 1168/*
1152 * These are used in an Elf32_Versym field. 1169 * These are used in an Elf32_Versym field.
1153 */ 1170 */
1154#define VER_NDX_LOCAL 0 1171#define VER_NDX_LOCAL 0
1155#define VER_NDX_GLOBAL 1 1172#define VER_NDX_GLOBAL 1
1156#define VER_NDX_GIVEN 2 1173#define VER_NDX_GIVEN 2
1157 1174
1158/* 1175/*
1159 * These constants are used for Elf32_Verneed struct's version number.  1176 * These constants are used for Elf32_Verneed struct's version number.
1160 */ 1177 */
1161#define VER_NEED_NONE 0 1178#define VER_NEED_NONE 0
1162#define VER_NEED_CURRENT 1 1179#define VER_NEED_CURRENT 1
1163 1180
1164/* 1181/*
1165 * These constants are used for Elf32_Vernaux struct's vna_other. 1182 * These constants are used for Elf32_Vernaux struct's vna_other.
1166 */ 1183 */
1167#define VER_NEED_HIDDEN VER_NDX_HIDDEN 1184#define VER_NEED_HIDDEN VER_NDX_HIDDEN
1168#define VER_NEED_IDX(x) VER_NDX(x) 1185#define VER_NEED_IDX(x) VER_NDX(x)
1169 1186
1170/* index */ 1187/* index */
1171#define VER_NDX_HIDDEN 0x8000 1188#define VER_NDX_HIDDEN 0x8000
1172#define VER_NDX(x) ((x) & ~VER_NDX_HIDDEN) 1189#define VER_NDX(x) ((x) & ~VER_NDX_HIDDEN)
1173 1190
1174/* 1191/*
1175 * GNU Extension hidding symbol 1192 * GNU Extension hidding symbol
1176 */ 1193 */
1177#define VERSYM_HIDDEN 0x8000 1194#define VERSYM_HIDDEN 0x8000
1178#define VERSYM_VERSION 0x7fff 1195#define VERSYM_VERSION 0x7fff
1179 1196
1180#define ELF_VER_CHR '@' 1197#define ELF_VER_CHR '@'
1181 1198
1182/* 1199/*
1183 * These are current size independent. 1200 * These are current size independent.
1184 */ 1201 */
1185 1202
1186typedef struct { 1203typedef struct {
1187 Elf32_Half vd_version; /* version number of structure */ 1204 Elf32_Half vd_version; /* version number of structure */
1188 Elf32_Half vd_flags; /* flags (VER_FLG_*) */ 1205 Elf32_Half vd_flags; /* flags (VER_FLG_*) */
1189 Elf32_Half vd_ndx; /* version index */ 1206 Elf32_Half vd_ndx; /* version index */
1190 Elf32_Half vd_cnt; /* number of verdaux entries */ 1207 Elf32_Half vd_cnt; /* number of verdaux entries */
1191 Elf32_Word vd_hash; /* hash of name */ 1208 Elf32_Word vd_hash; /* hash of name */
1192 Elf32_Word vd_aux; /* offset to verdaux entries */ 1209 Elf32_Word vd_aux; /* offset to verdaux entries */
1193 Elf32_Word vd_next; /* offset to next verdef */ 1210 Elf32_Word vd_next; /* offset to next verdef */
1194} Elf32_Verdef; 1211} Elf32_Verdef;
1195typedef Elf32_Verdef Elf64_Verdef; 1212typedef Elf32_Verdef Elf64_Verdef;
1196 1213
1197typedef struct { 1214typedef struct {
1198 Elf32_Word vda_name; /* string table offset of name */ 1215 Elf32_Word vda_name; /* string table offset of name */
1199 Elf32_Word vda_next; /* offset to verdaux */ 1216 Elf32_Word vda_next; /* offset to verdaux */
1200} Elf32_Verdaux; 1217} Elf32_Verdaux;
1201typedef Elf32_Verdaux Elf64_Verdaux; 1218typedef Elf32_Verdaux Elf64_Verdaux;
1202 1219
1203typedef struct { 1220typedef struct {
1204 Elf32_Half vn_version; /* version number of structure */ 1221 Elf32_Half vn_version; /* version number of structure */
1205 Elf32_Half vn_cnt; /* number of vernaux entries */ 1222 Elf32_Half vn_cnt; /* number of vernaux entries */
1206 Elf32_Word vn_file; /* string table offset of library name*/ 1223 Elf32_Word vn_file; /* string table offset of library name*/
1207 Elf32_Word vn_aux; /* offset to vernaux entries */ 1224 Elf32_Word vn_aux; /* offset to vernaux entries */
1208 Elf32_Word vn_next; /* offset to next verneed */ 1225 Elf32_Word vn_next; /* offset to next verneed */
1209} Elf32_Verneed; 1226} Elf32_Verneed;
1210typedef Elf32_Verneed Elf64_Verneed; 1227typedef Elf32_Verneed Elf64_Verneed;
1211 1228
1212typedef struct { 1229typedef struct {
1213 Elf32_Word vna_hash; /* Hash of dependency name */ 1230 Elf32_Word vna_hash; /* Hash of dependency name */
1214 Elf32_Half vna_flags; /* flags (VER_FLG_*) */ 1231 Elf32_Half vna_flags; /* flags (VER_FLG_*) */
1215 Elf32_Half vna_other; /* unused */ 1232 Elf32_Half vna_other; /* unused */
1216 Elf32_Word vna_name; /* string table offset to version name*/ 1233 Elf32_Word vna_name; /* string table offset to version name*/
1217 Elf32_Word vna_next; /* offset to next vernaux */ 1234 Elf32_Word vna_next; /* offset to next vernaux */
1218} Elf32_Vernaux; 1235} Elf32_Vernaux;
1219typedef Elf32_Vernaux Elf64_Vernaux; 1236typedef Elf32_Vernaux Elf64_Vernaux;
1220 1237
1221typedef struct { 1238typedef struct {
1222 Elf32_Half vs_vers; 1239 Elf32_Half vs_vers;
1223} Elf32_Versym; 1240} Elf32_Versym;
1224typedef Elf32_Versym Elf64_Versym; 1241typedef Elf32_Versym Elf64_Versym;
1225 1242
1226#ifdef _KERNEL 1243#ifdef _KERNEL
1227 1244
1228/* 1245/*
1229 * Arbitrary limits to avoid DoS for excessive memory allocation. 1246 * Arbitrary limits to avoid DoS for excessive memory allocation.
1230 */ 1247 */
1231#define ELF_MAXPHNUM 128 1248#define ELF_MAXPHNUM 128
1232#define ELF_MAXSHNUM 32768 1249#define ELF_MAXSHNUM 32768
1233#define ELF_MAXNOTESIZE 1024 1250#define ELF_MAXNOTESIZE 1024
1234 1251
1235#define ELF_AUX_ENTRIES 15 /* Max size of aux array passed to loader */ 1252#define ELF_AUX_ENTRIES 15 /* Max size of aux array passed to loader */
1236#define ELF32_NO_ADDR (~(Elf32_Addr)0) /* Indicates addr. not yet filled in */ 1253#define ELF32_NO_ADDR (~(Elf32_Addr)0) /* Indicates addr. not yet filled in */
1237#define ELF32_LINK_ADDR ((Elf32_Addr)-2) /* advises to use link address */ 1254#define ELF32_LINK_ADDR ((Elf32_Addr)-2) /* advises to use link address */
1238#define ELF64_NO_ADDR (~(Elf64_Addr)0) /* Indicates addr. not yet filled in */ 1255#define ELF64_NO_ADDR (~(Elf64_Addr)0) /* Indicates addr. not yet filled in */
1239#define ELF64_LINK_ADDR ((Elf64_Addr)-2) /* advises to use link address */ 1256#define ELF64_LINK_ADDR ((Elf64_Addr)-2) /* advises to use link address */
1240 1257
1241#if defined(ELFSIZE) && (ELFSIZE == 64) 1258#if defined(ELFSIZE) && (ELFSIZE == 64)
1242#define ELF_NO_ADDR ELF64_NO_ADDR 1259#define ELF_NO_ADDR ELF64_NO_ADDR
1243#define ELF_LINK_ADDR ELF64_LINK_ADDR 1260#define ELF_LINK_ADDR ELF64_LINK_ADDR
1244#elif defined(ELFSIZE) && (ELFSIZE == 32) 1261#elif defined(ELFSIZE) && (ELFSIZE == 32)
1245#define ELF_NO_ADDR ELF32_NO_ADDR 1262#define ELF_NO_ADDR ELF32_NO_ADDR
1246#define ELF_LINK_ADDR ELF32_LINK_ADDR 1263#define ELF_LINK_ADDR ELF32_LINK_ADDR
1247#endif 1264#endif
1248 1265
1249#ifndef ELF32_EHDR_FLAGS_OK 1266#ifndef ELF32_EHDR_FLAGS_OK
1250#define ELF32_EHDR_FLAGS_OK(eh) 1 1267#define ELF32_EHDR_FLAGS_OK(eh) 1
1251#endif 1268#endif
1252 1269
1253#ifndef ELF64_EHDR_FLAGS_OK 1270#ifndef ELF64_EHDR_FLAGS_OK
1254#define ELF64_EHDR_FLAGS_OK(eh) 1 1271#define ELF64_EHDR_FLAGS_OK(eh) 1
1255#endif 1272#endif
1256 1273
1257#if defined(ELFSIZE) && (ELFSIZE == 64) 1274#if defined(ELFSIZE) && (ELFSIZE == 64)
1258#define ELF_EHDR_FLAGS_OK(eh) ELF64_EHDR_FLAGS_OK(eh) 1275#define ELF_EHDR_FLAGS_OK(eh) ELF64_EHDR_FLAGS_OK(eh)
1259#else 1276#else
1260#define ELF_EHDR_FLAGS_OK(eh) ELF32_EHDR_FLAGS_OK(eh) 1277#define ELF_EHDR_FLAGS_OK(eh) ELF32_EHDR_FLAGS_OK(eh)
1261#endif 1278#endif
1262 1279
1263#if defined(ELFSIZE) 1280#if defined(ELFSIZE)
1264struct elf_args { 1281struct elf_args {
1265 Elf_Addr arg_entry; /* program entry point */ 1282 Elf_Addr arg_entry; /* program entry point */
1266 Elf_Addr arg_interp; /* Interpreter load address */ 1283 Elf_Addr arg_interp; /* Interpreter load address */
1267 Elf_Addr arg_phaddr; /* program header address */ 1284 Elf_Addr arg_phaddr; /* program header address */
1268 Elf_Addr arg_phentsize; /* Size of program header */ 1285 Elf_Addr arg_phentsize; /* Size of program header */
1269 Elf_Addr arg_phnum; /* Number of program headers */ 1286 Elf_Addr arg_phnum; /* Number of program headers */
1270}; 1287};
1271#endif 1288#endif
1272 1289
1273#ifdef _KERNEL_OPT 1290#ifdef _KERNEL_OPT
1274#include "opt_execfmt.h" 1291#include "opt_execfmt.h"
1275#endif 1292#endif
1276 1293
1277struct ps_strings; 1294struct ps_strings;
1278struct coredump_iostate; 1295struct coredump_iostate;
1279struct note_state; 1296struct note_state;
1280 1297
1281#ifdef EXEC_ELF32 1298#ifdef EXEC_ELF32
1282int exec_elf32_makecmds(struct lwp *, struct exec_package *); 1299int exec_elf32_makecmds(struct lwp *, struct exec_package *);
1283int elf32_copyargs(struct lwp *, struct exec_package *, 1300int elf32_copyargs(struct lwp *, struct exec_package *,
1284 struct ps_strings *, char **, void *); 1301 struct ps_strings *, char **, void *);
1285 1302
1286int coredump_elf32(struct lwp *, struct coredump_iostate *); 1303int coredump_elf32(struct lwp *, struct coredump_iostate *);
1287void coredump_savenote_elf32(struct note_state *, unsigned int, 1304void coredump_savenote_elf32(struct note_state *, unsigned int,
1288 const char *, void *, size_t); 1305 const char *, void *, size_t);
1289 1306
1290int elf32_check_header(Elf32_Ehdr *); 1307int elf32_check_header(Elf32_Ehdr *);
1291#endif 1308#endif
1292 1309
1293#ifdef EXEC_ELF64 1310#ifdef EXEC_ELF64
1294int exec_elf64_makecmds(struct lwp *, struct exec_package *); 1311int exec_elf64_makecmds(struct lwp *, struct exec_package *);
1295int elf64_copyargs(struct lwp *, struct exec_package *, 1312int elf64_copyargs(struct lwp *, struct exec_package *,
1296 struct ps_strings *, char **, void *); 1313 struct ps_strings *, char **, void *);
1297 1314
1298int coredump_elf64(struct lwp *, struct coredump_iostate *); 1315int coredump_elf64(struct lwp *, struct coredump_iostate *);
1299void coredump_savenote_elf64(struct note_state *, unsigned int, 1316void coredump_savenote_elf64(struct note_state *, unsigned int,
1300 const char *, void *, size_t); 1317 const char *, void *, size_t);
1301 1318
1302int elf64_check_header(Elf64_Ehdr *); 1319int elf64_check_header(Elf64_Ehdr *);
1303#endif 1320#endif
1304 1321
1305#endif /* _KERNEL */ 1322#endif /* _KERNEL */
1306 1323
1307#endif /* !_SYS_EXEC_ELF_H_ */ 1324#endif /* !_SYS_EXEC_ELF_H_ */