Skip to content

Commit ce16637

Browse files
author
miod
committed
a.out is no longer the commonly encountered binary file format, the world has
moved to ELF. Move the a.out specific defines and macros, but the MID_xxx values, from <sys/exec.h> to <a.out.h>, and update the few userland binaries which really need these defines (i.e. boot-related tools for old architectures) to explicitly include <a.out.h> when needed. "Fine" deraadt@
1 parent 5a69559 commit ce16637

File tree

6 files changed

+123
-129
lines changed

6 files changed

+123
-129
lines changed

distrib/special/more/more.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: more.c,v 1.41 2019/06/28 13:32:52 deraadt Exp $ */
1+
/* $OpenBSD: more.c,v 1.42 2024/10/16 18:47:47 miod Exp $ */
22

33
/*
44
* Copyright (c) 2003 Todd C. Miller <[email protected]>
@@ -63,10 +63,10 @@
6363
*/
6464

6565
#include <sys/types.h>
66-
#include <sys/exec.h>
6766
#include <sys/ioctl.h>
6867
#include <sys/stat.h>
6968

69+
#include <a.out.h>
7070
#include <ctype.h>
7171
#include <curses.h>
7272
#include <errno.h>

include/a.out.h

+113-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: a.out.h,v 1.3 2003/06/02 19:34:12 millert Exp $ */
1+
/* $OpenBSD: a.out.h,v 1.4 2024/10/16 18:47:48 miod Exp $ */
22
/* $NetBSD: a.out.h,v 1.15 1994/10/26 00:55:42 cgd Exp $ */
33

44
/*-
@@ -36,6 +36,118 @@
3636
#ifndef _AOUT_H_
3737
#define _AOUT_H_
3838

39+
/*
40+
* Legacy a.out structures and defines.
41+
*/
42+
43+
/*
44+
* Header prepended to each a.out file.
45+
* only manipulate the a_midmag field via the
46+
* N_SETMAGIC/N_GET{MAGIC,MID,FLAG} macros below.
47+
*/
48+
struct exec {
49+
u_int32_t a_midmag; /* htonl(flags<<26|mid<<16|magic) */
50+
u_int32_t a_text; /* text segment size */
51+
u_int32_t a_data; /* initialized data size */
52+
u_int32_t a_bss; /* uninitialized data size */
53+
u_int32_t a_syms; /* symbol table size */
54+
u_int32_t a_entry; /* entry point */
55+
u_int32_t a_trsize; /* text relocation size */
56+
u_int32_t a_drsize; /* data relocation size */
57+
};
58+
59+
/* a_magic */
60+
#define OMAGIC 0407 /* old impure format */
61+
#define NMAGIC 0410 /* read-only text */
62+
#define ZMAGIC 0413 /* demand load format */
63+
#define QMAGIC 0314 /* "compact" demand load format; deprecated */
64+
65+
/*
66+
* a_flags
67+
*/
68+
#define EX_DYNAMIC 0x20
69+
#define EX_PIC 0x10
70+
#define EX_DPMASK 0x30
71+
/*
72+
* Interpretation of the (a_flags & EX_DPMASK) bits:
73+
*
74+
* 00 traditional executable or object file
75+
* 01 object file contains PIC code (set by `as -k')
76+
* 10 dynamic executable
77+
* 11 position independent executable image
78+
* (eg. a shared library)
79+
*
80+
*/
81+
82+
/*
83+
* The a.out structure's a_midmag field is a network-byteorder encoding
84+
* of this int
85+
* FFFFFFmmmmmmmmmmMMMMMMMMMMMMMMMM
86+
* Where `F' is 6 bits of flag like EX_DYNAMIC,
87+
* `m' is 10 bits of machine-id like MID_I386, and
88+
* `M' is 16 bits worth of magic number, ie. ZMAGIC.
89+
* The macros below will set/get the needed fields.
90+
*/
91+
#define N_GETMAGIC(ex) \
92+
( (((ex).a_midmag)&0xffff0000) ? (ntohl(((ex).a_midmag))&0xffff) : ((ex).a_midmag))
93+
#define N_GETMAGIC2(ex) \
94+
( (((ex).a_midmag)&0xffff0000) ? (ntohl(((ex).a_midmag))&0xffff) : \
95+
(((ex).a_midmag) | 0x10000) )
96+
#define N_GETMID(ex) \
97+
( (((ex).a_midmag)&0xffff0000) ? ((ntohl(((ex).a_midmag))>>16)&0x03ff) : MID_ZERO )
98+
#define N_GETFLAG(ex) \
99+
( (((ex).a_midmag)&0xffff0000) ? ((ntohl(((ex).a_midmag))>>26)&0x3f) : 0 )
100+
#define N_SETMAGIC(ex,mag,mid,flag) \
101+
( (ex).a_midmag = htonl( (((flag)&0x3f)<<26) | (((mid)&0x03ff)<<16) | \
102+
(((mag)&0xffff)) ) )
103+
104+
#define N_ALIGN(ex,x) \
105+
(N_GETMAGIC(ex) == ZMAGIC || N_GETMAGIC(ex) == QMAGIC ? \
106+
((x) + __LDPGSZ - 1) & ~(__LDPGSZ - 1) : (x))
107+
108+
/* Valid magic number check. */
109+
#define N_BADMAG(ex) \
110+
(N_GETMAGIC(ex) != NMAGIC && N_GETMAGIC(ex) != OMAGIC && \
111+
N_GETMAGIC(ex) != ZMAGIC && N_GETMAGIC(ex) != QMAGIC)
112+
113+
/* Address of the bottom of the text segment. */
114+
#define N_TXTADDR(ex) (N_GETMAGIC2(ex) == (ZMAGIC|0x10000) ? 0 : __LDPGSZ)
115+
116+
/* Address of the bottom of the data segment. */
117+
#define N_DATADDR(ex) \
118+
(N_GETMAGIC(ex) == OMAGIC ? N_TXTADDR(ex) + (ex).a_text : \
119+
(N_TXTADDR(ex) + (ex).a_text + __LDPGSZ - 1) & ~(__LDPGSZ - 1))
120+
121+
/* Address of the bottom of the bss segment. */
122+
#define N_BSSADDR(ex) \
123+
(N_DATADDR(ex) + (ex).a_data)
124+
125+
/* Text segment offset. */
126+
#define N_TXTOFF(ex) \
127+
( N_GETMAGIC2(ex)==ZMAGIC || N_GETMAGIC2(ex)==(QMAGIC|0x10000) ? \
128+
0 : (N_GETMAGIC2(ex)==(ZMAGIC|0x10000) ? __LDPGSZ : \
129+
sizeof(struct exec)) )
130+
131+
/* Data segment offset. */
132+
#define N_DATOFF(ex) \
133+
N_ALIGN(ex, N_TXTOFF(ex) + (ex).a_text)
134+
135+
/* Text relocation table offset. */
136+
#define N_TRELOFF(ex) \
137+
(N_DATOFF(ex) + (ex).a_data)
138+
139+
/* Data relocation table offset. */
140+
#define N_DRELOFF(ex) \
141+
(N_TRELOFF(ex) + (ex).a_trsize)
142+
143+
/* Symbol table offset. */
144+
#define N_SYMOFF(ex) \
145+
(N_DRELOFF(ex) + (ex).a_drsize)
146+
147+
/* String table offset. */
148+
#define N_STROFF(ex) \
149+
(N_SYMOFF(ex) + (ex).a_syms)
150+
39151
#include <sys/exec.h>
40152

41153
#define _AOUT_INCLUDE_

sys/arch/hppa/stand/mkboot/mkboot.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: mkboot.c,v 1.21 2017/12/30 23:08:29 guenther Exp $ */
1+
/* $OpenBSD: mkboot.c,v 1.22 2024/10/16 18:47:48 miod Exp $ */
22

33
/*
44
* Copyright (c) 1990, 1993
@@ -32,11 +32,11 @@
3232
*/
3333

3434
#include <sys/param.h>
35-
#include <sys/exec.h>
36-
#include <sys/exec_elf.h>
3735
#include <sys/stat.h>
3836

37+
#include <a.out.h>
3938
#include <ctype.h>
39+
#include <elf.h>
4040
#include <err.h>
4141
#include <fcntl.h>
4242
#include <stdlib.h>

sys/sys/exec.h

+1-119
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: exec.h,v 1.54 2024/04/02 08:39:16 deraadt Exp $ */
1+
/* $OpenBSD: exec.h,v 1.55 2024/10/16 18:47:48 miod Exp $ */
22
/* $NetBSD: exec.h,v 1.59 1996/02/09 18:25:09 christos Exp $ */
33

44
/*-
@@ -222,38 +222,6 @@ extern int stackgap_random;
222222

223223
#endif /* _KERNEL */
224224

225-
#ifndef N_PAGSIZ
226-
#define N_PAGSIZ(ex) (__LDPGSZ)
227-
#endif
228-
229-
/*
230-
* Legacy a.out structures and defines; start deleting these when
231-
* external use no longer exist.
232-
*/
233-
234-
235-
/*
236-
* Header prepended to each a.out file.
237-
* only manipulate the a_midmag field via the
238-
* N_SETMAGIC/N_GET{MAGIC,MID,FLAG} macros below.
239-
*/
240-
struct exec {
241-
u_int32_t a_midmag; /* htonl(flags<<26|mid<<16|magic) */
242-
u_int32_t a_text; /* text segment size */
243-
u_int32_t a_data; /* initialized data size */
244-
u_int32_t a_bss; /* uninitialized data size */
245-
u_int32_t a_syms; /* symbol table size */
246-
u_int32_t a_entry; /* entry point */
247-
u_int32_t a_trsize; /* text relocation size */
248-
u_int32_t a_drsize; /* data relocation size */
249-
};
250-
251-
/* a_magic */
252-
#define OMAGIC 0407 /* old impure format */
253-
#define NMAGIC 0410 /* read-only text */
254-
#define ZMAGIC 0413 /* demand load format */
255-
#define QMAGIC 0314 /* "compact" demand load format; deprecated */
256-
257225
/*
258226
* a_mid - keep sorted in numerical order for sanity's sake
259227
* ensure that: 0 < mid < 0x3ff
@@ -292,92 +260,6 @@ struct exec {
292260
#define MID_HPPA11 0x210 /* hp700 HP-UX binary pa1.1 */
293261
#define MID_HPPA20 0x214 /* hp700 HP-UX binary pa2.0 */
294262

295-
/*
296-
* a_flags
297-
*/
298-
#define EX_DYNAMIC 0x20
299-
#define EX_PIC 0x10
300-
#define EX_DPMASK 0x30
301-
/*
302-
* Interpretation of the (a_flags & EX_DPMASK) bits:
303-
*
304-
* 00 traditional executable or object file
305-
* 01 object file contains PIC code (set by `as -k')
306-
* 10 dynamic executable
307-
* 11 position independent executable image
308-
* (eg. a shared library)
309-
*
310-
*/
311-
312-
/*
313-
* The a.out structure's a_midmag field is a network-byteorder encoding
314-
* of this int
315-
* FFFFFFmmmmmmmmmmMMMMMMMMMMMMMMMM
316-
* Where `F' is 6 bits of flag like EX_DYNAMIC,
317-
* `m' is 10 bits of machine-id like MID_I386, and
318-
* `M' is 16 bits worth of magic number, ie. ZMAGIC.
319-
* The macros below will set/get the needed fields.
320-
*/
321-
#define N_GETMAGIC(ex) \
322-
( (((ex).a_midmag)&0xffff0000) ? (ntohl(((ex).a_midmag))&0xffff) : ((ex).a_midmag))
323-
#define N_GETMAGIC2(ex) \
324-
( (((ex).a_midmag)&0xffff0000) ? (ntohl(((ex).a_midmag))&0xffff) : \
325-
(((ex).a_midmag) | 0x10000) )
326-
#define N_GETMID(ex) \
327-
( (((ex).a_midmag)&0xffff0000) ? ((ntohl(((ex).a_midmag))>>16)&0x03ff) : MID_ZERO )
328-
#define N_GETFLAG(ex) \
329-
( (((ex).a_midmag)&0xffff0000) ? ((ntohl(((ex).a_midmag))>>26)&0x3f) : 0 )
330-
#define N_SETMAGIC(ex,mag,mid,flag) \
331-
( (ex).a_midmag = htonl( (((flag)&0x3f)<<26) | (((mid)&0x03ff)<<16) | \
332-
(((mag)&0xffff)) ) )
333-
334-
#define N_ALIGN(ex,x) \
335-
(N_GETMAGIC(ex) == ZMAGIC || N_GETMAGIC(ex) == QMAGIC ? \
336-
((x) + __LDPGSZ - 1) & ~(__LDPGSZ - 1) : (x))
337-
338-
/* Valid magic number check. */
339-
#define N_BADMAG(ex) \
340-
(N_GETMAGIC(ex) != NMAGIC && N_GETMAGIC(ex) != OMAGIC && \
341-
N_GETMAGIC(ex) != ZMAGIC && N_GETMAGIC(ex) != QMAGIC)
342-
343-
/* Address of the bottom of the text segment. */
344-
#define N_TXTADDR(ex) (N_GETMAGIC2(ex) == (ZMAGIC|0x10000) ? 0 : __LDPGSZ)
345-
346-
/* Address of the bottom of the data segment. */
347-
#define N_DATADDR(ex) \
348-
(N_GETMAGIC(ex) == OMAGIC ? N_TXTADDR(ex) + (ex).a_text : \
349-
(N_TXTADDR(ex) + (ex).a_text + __LDPGSZ - 1) & ~(__LDPGSZ - 1))
350-
351-
/* Address of the bottom of the bss segment. */
352-
#define N_BSSADDR(ex) \
353-
(N_DATADDR(ex) + (ex).a_data)
354-
355-
/* Text segment offset. */
356-
#define N_TXTOFF(ex) \
357-
( N_GETMAGIC2(ex)==ZMAGIC || N_GETMAGIC2(ex)==(QMAGIC|0x10000) ? \
358-
0 : (N_GETMAGIC2(ex)==(ZMAGIC|0x10000) ? __LDPGSZ : \
359-
sizeof(struct exec)) )
360-
361-
/* Data segment offset. */
362-
#define N_DATOFF(ex) \
363-
N_ALIGN(ex, N_TXTOFF(ex) + (ex).a_text)
364-
365-
/* Text relocation table offset. */
366-
#define N_TRELOFF(ex) \
367-
(N_DATOFF(ex) + (ex).a_data)
368-
369-
/* Data relocation table offset. */
370-
#define N_DRELOFF(ex) \
371-
(N_TRELOFF(ex) + (ex).a_trsize)
372-
373-
/* Symbol table offset. */
374-
#define N_SYMOFF(ex) \
375-
(N_DRELOFF(ex) + (ex).a_drsize)
376-
377-
/* String table offset. */
378-
#define N_STROFF(ex) \
379-
(N_SYMOFF(ex) + (ex).a_syms)
380-
381263
#include <machine/exec.h>
382264

383265
#endif /* !_SYS_EXEC_H_ */

usr.sbin/mopd/common/file.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: file.c,v 1.19 2017/10/29 08:45:53 mpi Exp $ */
1+
/* $OpenBSD: file.c,v 1.20 2024/10/16 18:47:48 miod Exp $ */
22

33
/*
44
* Copyright (c) 1995-96 Mats O Jansson. All rights reserved.
@@ -32,7 +32,7 @@
3232

3333
#ifndef NOAOUT
3434
#if defined(__OpenBSD__)
35-
#include <sys/exec.h>
35+
#include <a.out.h>
3636
#endif
3737
#if defined(__bsdi__)
3838
#define NOAOUT

usr.sbin/mopd/mopa.out/mopa.out.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: mopa.out.c,v 1.18 2022/12/28 21:30:17 jmc Exp $ */
1+
/* $OpenBSD: mopa.out.c,v 1.19 2024/10/16 18:47:48 miod Exp $ */
22

33
/*
44
* mopa.out - Convert a Unix format kernel into something that
@@ -53,7 +53,7 @@
5353
#include "common/mopdef.h"
5454
#include "common/file.h"
5555
#if defined(__OpenBSD__)
56-
#include <sys/exec.h>
56+
#include <a.out.h>
5757
#endif
5858
#if defined(__FreeBSD__)
5959
#include <sys/imgact_aout.h>

0 commit comments

Comments
 (0)