-
-#define OMAGIC 0407 /* old impure format */
-#define NMAGIC 0410 /* read-only text */
-#define ZMAGIC 0413 /* demand load format */
-
-/*
-.ti +\w'/'u
-* Macros which take exec structures as arguments and tell whether
-.ti +\w'/'u
-* the file has a reasonable magic number or offsets to text\||\|symbols\||\|strings.
-.ti +\w'/'u
-*/
-#define N_BADMAG(x) \e
- (((x).a_magic)!=OMAGIC && ((x).a_magic)!=NMAGIC && ((x).a_magic)!=ZMAGIC)
-
-#define N_TXTOFF(x) \e
- ((x).a_magic==ZMAGIC ? 1024 : sizeof (struct exec))
-#define N_SYMOFF(x) \e
- (N_TXTOFF(x) + (x).a_text+(x).a_data + (x).a_trsize+(x).a_drsize)
-#define N_STROFF(x) \e
- (N_SYMOFF(x) + (x).a_syms)
-.DT
-.fi
-.PP
-The file has five sections:
-a header, the program text and data,
-relocation information, a symbol table and a string table (in that order).
-The last three may be omitted
-if the program was loaded
-with the `\-s' option
-of
-.I ld
-or if the symbols and relocation have been
-removed by
-.IR strip (1).
-.PP
-In the header the sizes of each section are given in bytes.
-The size of the header is not included in any of the other sizes.
-.PP
-When an
-.I a.out
-file is executed, three logical segments are
-set up: the text segment, the data segment
-(with uninitialized data, which starts off as all 0, following
-initialized),
-and a stack.
-The text segment begins at 0
-in the core image; the header is not loaded.
-If the magic number in the header is OMAGIC (0407),
-it indicates that the text
-segment is not to be write-protected and shared,
-so the data segment is immediately contiguous
-with the text segment.
-This is the oldest kind of executable program and is rarely used.
-If the magic number is NMAGIC (0410) or ZMAGIC (0413),
-the data segment begins at the first 0 mod 1024 byte
-boundary following the text segment,
-and the text segment is not writable by the program;
-if other processes are executing the same file,
-they will share the text segment.
-For ZMAGIC format, the text segment begins at a 0 mod 1024 byte boundary
-in the
-.I a.out
-file, the remaining bytes after the header in the first block are
-reserved and should be zero.
-In this case the text and data sizes must both be multiples of 1024 bytes,
-and the pages of the file will be brought into the running image as needed,
-and not pre-loaded as with the other formats. This is especially suitable
-for very large programs and is the default format produced by
-.IR ld (1).
-.PP
-The stack will occupy the highest possible locations
-in the core image, growing downwards from USRSTACK (from
-.IR <machine/vmparam.h> ).
-The stack is automatically extended as required.
-The data segment is only extended as requested by
-.IR brk (2).
-.PP
-After the header in the file follow the text, data, text relocation
-data relocation, symbol table and string table in that order.
-The text begins at the byte 1024 in the file for ZMAGIC format or just
-after the header for the other formats. The N_TXTOFF macro returns
-this absolute file position when given the name of an exec structure
-as argument. The data segment is contiguous with the text and immediately
-followed by the text relocation and then the data relocation information.
-The symbol table follows all this; its position is computed by the
-N_SYMOFF macro. Finally, the string table immediately follows the
-symbol table at a position which can be gotten easily using N_STROFF.
-The first 4 bytes of the string table are not used for string storage,
-but rather contain the size of the string table; this size INCLUDES
-the 4 bytes, the minimum string table size is thus 4.
-.PP
-The layout of a symbol table entry and the principal flag values
-that distinguish symbol types are given in the include file as follows:
-.PP
-.nf
-.ta \w'#define 'u +\w'char'u-1u +\w'unsigned 'u+1u +\w'*n_name 'u
-/*
-.ti +\w'/'u
-* Format of a symbol table entry.
-.ti +\w'/'u
-*/
+.Ed
+.Pp
+The fields have the following functions:
+.Bl -tag -width a_trsize
+.It Fa a_mid
+Contains a bit pattern that
+identifies binaries that were built for
+certain sub-classes of an architecture
+.Pq Sq machine IDs
+or variants of the operating system on a given architecture.
+The kernel may not support all machine IDs
+on a given architecture.
+The
+.Fa a_mid
+field is not present on some architectures;
+in this case, the
+.Fa a_magic
+field has type
+.Em unsigned long .
+.It Fa a_magic
+Contains a bit pattern
+.Pq Sq magic number
+that uniquely identifies binary files
+and distinguishes different loading conventions.
+The field must contain one of the following values:
+.Bl -tag -width ZMAGIC
+.It Dv OMAGIC
+The text and data segments immediately follow the header
+and are contiguous.
+The kernel loads both text and data segments into writable memory.
+.It Dv NMAGIC
+As with
+.Dv OMAGIC ,
+text and data segments immediately follow the header and are contiguous.
+However, the kernel loads the text into read-only memory
+and loads the data into writable memory at the next
+page boundary after the text.
+.It Dv ZMAGIC
+The kernel loads individual pages on demand from the binary.
+The header, text segment and data segment are all
+padded by the link editor to a multiple of the page size.
+Pages that the kernel loads from the text segment are read-only,
+while pages from the data segment are writable.
+.El
+.It Fa a_text
+Contains the size of the text segment in bytes.
+.It Fa a_data
+Contains the size of the data segment in bytes.
+.It Fa a_bss
+Contains the number of bytes in the
+.Sq bss segment
+and is used by the kernel to set the initial break
+.Pq Xr brk 2
+after the data segment.
+The kernel loads the program so that this amount of writable memory
+appears to follow the data segment and initially reads as zeroes.
+.It Fa a_syms
+Contains the size in bytes of the symbol table section.
+.It Fa a_entry
+Contains the address in memory of the entry point
+of the program after the kernel has loaded it;
+the kernel starts the execution of the program
+from the machine instruction at this address.
+.It Fa a_trsize
+Contains the size in bytes of the text relocation table.
+.It Fa a_drsize
+Contains the size in bytes of the data relocation table.
+.El
+.Pp
+The
+.Pa a.out.h
+include file defines several macros which use an
+.Fa exec
+structure to test consistency or to locate section offsets in the binary file.
+.Bl -tag -width N_BADMAG(exec)
+.It Fn N_BADMAG exec
+Nonzero if the
+.Fa a_magic
+field does not contain a recognized value.
+.It Fn N_TXTOFF exec
+The byte offset in the binary file of the beginning of the text segment.
+.It Fn N_SYMOFF exec
+The byte offset of the beginning of the symbol table.
+.It Fn N_STROFF exec
+The byte offset of the beginning of the string table.
+.El
+.Pp
+Relocation records have a standard format which
+is described by the
+.Fa relocation_info
+structure:
+.Bd -literal -offset indent
+struct relocation_info {
+ int r_address;
+ unsigned int r_symbolnum : 24,
+ r_pcrel : 1,
+ r_length : 2,
+ r_extern : 1,
+ : 4;
+};
+.Ed
+.Pp
+The
+.Fa relocation_info
+fields are used as follows:
+.Bl -tag -width r_symbolnum
+.It Fa r_address
+Contains the byte offset of a pointer that needs to be link-edited.
+Text relocation offsets are reckoned from the start of the text segment,
+and data relocation offsets from the start of the data segment.
+The link editor adds the value that is already stored at this offset
+into the new value that it computes using this relocation record.
+.It Fa r_symbolnum
+Contains the ordinal number of a symbol structure
+in the symbol table (it is
+.Em not
+a byte offset).
+After the link editor resolves the absolute address for this symbol,
+it adds that address to the pointer that is undergoing relocation.
+(If the
+.Fa r_extern
+bit is clear, the situation is different; see below.)
+.It Fa r_pcrel
+If this is set,
+the link editor assumes that it is updating a pointer
+that is part of a machine code instruction using pc-relative addressing.
+The address of the relocated pointer is implicitly added
+to its value when the running program uses it.
+.It Fa r_length
+Contains the log base 2 of the length of the pointer in bytes;
+0 for 1-byte displacements, 1 for 2-byte displacements,
+2 for 4-byte displacements.
+.It Fa r_extern
+Set if this relocation requires an external reference;
+the link editor must use a symbol address to update the pointer.
+When the
+.Fa r_extern
+bit is clear, the relocation is
+.Sq local ;
+the link editor updates the pointer to reflect
+changes in the load addresses of the various segments,
+rather than changes in the value of a symbol.
+In this case, the content of the
+.Fa r_symbolnum
+field is an
+.Fa n_type
+value (see below);
+this type field tells the link editor
+what segment the relocated pointer points into.
+.El
+.Pp
+Symbols map names to addresses (or more generally, strings to values).
+Since the link-editor adjusts addresses,
+a symbol's name must be used to stand for its address
+until an absolute value has been assigned.
+Symbols consist of a fixed-length record in the symbol table
+and a variable-length name in the string table.
+The symbol table is an array of
+.Fa nlist
+structures:
+.Bd -literal -offset indent