jcs's openbsd hax
openbsd

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@

miod ce166376 5a695598

+123 -129
+2 -2
distrib/special/more/more.c
··· 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 $ */ 2 2 3 3 /* 4 4 * Copyright (c) 2003 Todd C. Miller <millert@openbsd.org> ··· 63 63 */ 64 64 65 65 #include <sys/types.h> 66 - #include <sys/exec.h> 67 66 #include <sys/ioctl.h> 68 67 #include <sys/stat.h> 69 68 69 + #include <a.out.h> 70 70 #include <ctype.h> 71 71 #include <curses.h> 72 72 #include <errno.h>
+113 -1
include/a.out.h
··· 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 $ */ 2 2 /* $NetBSD: a.out.h,v 1.15 1994/10/26 00:55:42 cgd Exp $ */ 3 3 4 4 /*- ··· 35 35 36 36 #ifndef _AOUT_H_ 37 37 #define _AOUT_H_ 38 + 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) 38 150 39 151 #include <sys/exec.h> 40 152
+3 -3
sys/arch/hppa/stand/mkboot/mkboot.c
··· 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 $ */ 2 2 3 3 /* 4 4 * Copyright (c) 1990, 1993 ··· 32 32 */ 33 33 34 34 #include <sys/param.h> 35 - #include <sys/exec.h> 36 - #include <sys/exec_elf.h> 37 35 #include <sys/stat.h> 38 36 37 + #include <a.out.h> 39 38 #include <ctype.h> 39 + #include <elf.h> 40 40 #include <err.h> 41 41 #include <fcntl.h> 42 42 #include <stdlib.h>
+1 -119
sys/sys/exec.h
··· 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 $ */ 2 2 /* $NetBSD: exec.h,v 1.59 1996/02/09 18:25:09 christos Exp $ */ 3 3 4 4 /*- ··· 222 222 223 223 #endif /* _KERNEL */ 224 224 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 - 257 225 /* 258 226 * a_mid - keep sorted in numerical order for sanity's sake 259 227 * ensure that: 0 < mid < 0x3ff ··· 291 259 #define MID_HPUX800 0x20B /* hp800 HP-UX binary pa1.0 */ 292 260 #define MID_HPPA11 0x210 /* hp700 HP-UX binary pa1.1 */ 293 261 #define MID_HPPA20 0x214 /* hp700 HP-UX binary pa2.0 */ 294 - 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 262 381 263 #include <machine/exec.h> 382 264
+2 -2
usr.sbin/mopd/common/file.c
··· 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 $ */ 2 2 3 3 /* 4 4 * Copyright (c) 1995-96 Mats O Jansson. All rights reserved. ··· 32 32 33 33 #ifndef NOAOUT 34 34 #if defined(__OpenBSD__) 35 - #include <sys/exec.h> 35 + #include <a.out.h> 36 36 #endif 37 37 #if defined(__bsdi__) 38 38 #define NOAOUT
+2 -2
usr.sbin/mopd/mopa.out/mopa.out.c
··· 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 $ */ 2 2 3 3 /* 4 4 * mopa.out - Convert a Unix format kernel into something that ··· 53 53 #include "common/mopdef.h" 54 54 #include "common/file.h" 55 55 #if defined(__OpenBSD__) 56 - #include <sys/exec.h> 56 + #include <a.out.h> 57 57 #endif 58 58 #if defined(__FreeBSD__) 59 59 #include <sys/imgact_aout.h>