⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 a.out.5

📁 早期freebsd实现
💻 5
字号:
.\" Copyright (c) 1991, 1993.\"	The Regents of the University of California.  All rights reserved..\".\" This man page is derived from documentation contributed to Berkeley by.\" Donn Seeley at UUNET Technologies, Inc..\".\" Redistribution and use in source and binary forms, with or without.\" modification, are permitted provided that the following conditions.\" are met:.\" 1. Redistributions of source code must retain the above copyright.\"    notice, this list of conditions and the following disclaimer..\" 2. Redistributions in binary form must reproduce the above copyright.\"    notice, this list of conditions and the following disclaimer in the.\"    documentation and/or other materials provided with the distribution..\" 3. All advertising materials mentioning features or use of this software.\"    must display the following acknowledgement:.\"	This product includes software developed by the University of.\"	California, Berkeley and its contributors..\" 4. Neither the name of the University nor the names of its contributors.\"    may be used to endorse or promote products derived from this software.\"    without specific prior written permission..\".\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION).\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF.\" SUCH DAMAGE..\".\"	@(#)a.out.5	8.1 (Berkeley) 6/5/93.\".Dd June 5, 1993.Dt A.OUT 5.Os.Sh NAME.Nm a.out.Nd format of executable binary files.Sh SYNOPSIS.Fd #include <a.out.h>.Sh DESCRIPTIONThe include file.Aq Pa a.out.hdeclares three structures and several macros.The structures describe the format ofexecutable machine code files.Pq Sq binarieson the system..PpA binary file consists of up to 7 sections.In order, these sections are:.Bl -tag -width "text relocations".It exec headerContains parameters used by the kernelto load a binary file into memory and execute it,and by the link editor.Xr ld 1to combine a binary file with other binary files.This section is the only mandatory one..It text segmentContains machine code and related datathat are loaded into memory when a program executes.May be loaded read-only..It data segmentContains initialized data; always loaded into writable memory..It text relocationsContains records used by the link editorto update pointers in the text segment when combining binary files..It data relocationsLike the text relocation section, but for data segment pointers..It symbol tableContains records used by the link editorto cross reference the addresses of named variables and functions.Pq Sq symbolsbetween binary files..It string tableContains the character strings corresponding to the symbol names..El.PpEvery binary file begins with an.Fa execstructure:.Bd -literal -offset indentstruct exec {	unsigned short	a_mid;	unsigned short	a_magic;	unsigned long	a_text;	unsigned long	a_data;	unsigned long	a_bss;	unsigned long	a_syms;	unsigned long	a_entry;	unsigned long	a_trsize;	unsigned long	a_drsize;};.Ed.PpThe fields have the following functions:.Bl -tag -width a_trsize.It Fa a_midContains a bit pattern thatidentifies binaries that were built forcertain sub-classes of an architecture.Pq Sq machine IDsor variants of the operating system on a given architecture.The kernel may not support all machine IDson a given architecture.The.Fa a_midfield is not present on some architectures;in this case, the.Fa a_magicfield has type.Em unsigned long ..It Fa a_magicContains a bit pattern.Pq Sq magic numberthat uniquely identifies binary filesand distinguishes different loading conventions.The field must contain one of the following values:.Bl -tag -width ZMAGIC.It Dv OMAGICThe text and data segments immediately follow the headerand are contiguous.The kernel loads both text and data segments into writable memory..It Dv NMAGICAs with.Dv OMAGIC ,text and data segments immediately follow the header and are contiguous.However, the kernel loads the text into read-only memoryand loads the data into writable memory at the nextpage boundary after the text..It Dv ZMAGICThe kernel loads individual pages on demand from the binary.The header, text segment and data segment are allpadded 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_textContains the size of the text segment in bytes..It Fa a_dataContains the size of the data segment in bytes..It Fa a_bssContains the number of bytes in the.Sq bss segmentand is used by the kernel to set the initial break.Pq Xr brk 2after the data segment.The kernel loads the program so that this amount of writable memoryappears to follow the data segment and initially reads as zeroes..It Fa a_symsContains the size in bytes of the symbol table section..It Fa a_entryContains the address in memory of the entry pointof the program after the kernel has loaded it;the kernel starts the execution of the programfrom the machine instruction at this address..It Fa a_trsizeContains the size in bytes of the text relocation table..It Fa a_drsizeContains the size in bytes of the data relocation table..El.PpThe.Pa a.out.hinclude file defines several macros which use an.Fa execstructure to test consistency or to locate section offsets in the binary file..Bl -tag -width N_BADMAG(exec).It Fn N_BADMAG execNonzero if the.Fa a_magicfield does not contain a recognized value..It Fn N_TXTOFF execThe byte offset in the binary file of the beginning of the text segment..It Fn N_SYMOFF execThe byte offset of the beginning of the symbol table..It Fn N_STROFF execThe byte offset of the beginning of the string table..El.PpRelocation records have a standard format whichis described by the.Fa relocation_infostructure:.Bd -literal -offset indentstruct relocation_info {	int		r_address;	unsigned int	r_symbolnum : 24,			r_pcrel : 1,			r_length : 2,			r_extern : 1,			: 4;};.Ed.PpThe.Fa relocation_infofields are used as follows:.Bl -tag -width r_symbolnum.It Fa r_addressContains 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 offsetinto the new value that it computes using this relocation record..It Fa r_symbolnumContains the ordinal number of a symbol structurein the symbol table (it is.Em nota 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_externbit is clear, the situation is different; see below.).It Fa r_pcrelIf this is set,the link editor assumes that it is updating a pointerthat is part of a machine code instruction using pc-relative addressing.The address of the relocated pointer is implicitly addedto its value when the running program uses it..It Fa r_lengthContains 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_externSet if this relocation requires an external reference;the link editor must use a symbol address to update the pointer.When the.Fa r_externbit is clear, the relocation is.Sq local ;the link editor updates the pointer to reflectchanges 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_symbolnumfield is an.Fa n_typevalue (see below);this type field tells the link editorwhat segment the relocated pointer points into..El.PpSymbols 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 addressuntil an absolute value has been assigned.Symbols consist of a fixed-length record in the symbol tableand a variable-length name in the string table.The symbol table is an array of.Fa nliststructures:.Bd -literal -offset indentstruct nlist {	union {		char	*n_name;		long	n_strx;	} n_un;	unsigned char	n_type;	char		n_other;	short		n_desc;	unsigned long	n_value;};.Ed.PpThe fields are used as follows:.Bl -tag -width n_un.n_strx.It Fa n_un.n_strxContains a byte offset into the string tablefor the name of this symbol.When a program accesses a symbol table with the.Xr nlist 3function,this field is replaced with the.Fa n_un.n_namefield, which is a pointer to the string in memory..It Fa n_typeUsed by the link editor to determinehow to update the symbol's value.The.Fa n_typefield is broken down into three sub-fields using bitmasks.The link editor treats symbols with the.Dv N_EXTtype bit set as.Sq externalsymbols and permits references to them from other binary files.The.Dv N_TYPEmask selects bits of interest to the link editor:.Bl -tag -width N_TEXT.It Dv N_UNDFAn undefined symbol.The link editor must locate an external symbol with the same namein another binary file to determine the absolute value of this symbol.As a special case, if the.Fa n_valuefield is nonzero and no binary file in the link-edit defines this symbol,the link-editor will resolve this symbol to an addressin the bss segment,reserving an amount of bytes equal to.Fa n_value .If this symbol is undefined in more than one binary fileand the binary files do not agree on the size,the link editor chooses the greatest size found across all binaries..It Dv N_ABSAn absolute symbol.The link editor does not update an absolute symbol..It Dv N_TEXTA text symbol.This symbol's value is a text address andthe link editor will update it when it merges binary files..It Dv N_DATAA data symbol; similar to.Dv N_TEXTbut for data addresses.The values for text and data symbols are not file offsets butaddresses; to recover the file offsets, it is necessaryto identify the loaded address of the beginning of the correspondingsection and subtract it, then add the offset of the section..It Dv N_BSSA bss symbol; like text or data symbols buthas no corresponding offset in the binary file..It Dv N_FNA filename symbol.The link editor inserts this symbol beforethe other symbols from a binary file whenmerging binary files.The name of the symbol is the filename given to the link editor,and its value is the first text address from that binary file.Filename symbols are not needed for link-editing or loading,but are useful for debuggers..El.PpThe.Dv N_STABmask selects bits of interest to symbolic debuggerssuch as.Xr gdb 1 ;the values are described in.Xr stab 5 ..It Fa n_otherThis field is currently unused..It Fa n_descReserved for use by debuggers; passed untouched by the link editor.Different debuggers use this field for different purposes..It Fa n_valueContains the value of the symbol.For text, data and bss symbols, this is an address;for other symbols (such as debugger symbols),the value may be arbitrary..El.PpThe string table consists of an.Em unsigned longlength followed by null-terminated symbol strings.The length represents the size of the entire table in bytes,so its minimum value (or the offset of the first string)is always 4 on 32-bit machines..Sh SEE ALSO.Xr ld 1 ,.Xr execve 2 ,.Xr nlist 3 ,.Xr core 5 ,.Xr dbx 5 ,.Xr stab 5.Sh HISTORYThe.Pa a.out.hinclude file appeared in.At v7 ..Sh BUGSSince not all of the supported architectures use the.Fa a_midfield,it can be difficult to determine whatarchitecture a binary will execute onwithout examining its actual machine code.Even with a machine identifier,the byte order of the.Fa execheader is machine-dependent..PpNobody seems to agree on what.Em bssstands for..PpNew binary file formats may be supported in the future,and they probably will not be compatible at any levelwith this ancient format.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -