up | Inhaltsverzeichniss | Kommentar

Manual page for COFF(5)

coff - common assembler and link editor output

SYNOPSIS

#include <filehdr.h>
#include <aouthdr.h>
#include <scnhdr.h>
#include <reloc.h>
#include <linenum.h>
#include <storclass.h>
#include <syms.h>

AVAILABILITY

Available only on Sun 386i systems running a SunOS 4.0.x release or earlier. Not a SunOS 4.1 release feature.

DESCRIPTION

The output from the link editor and the assembler (named a.out by default) is in COFF format (Common Object File Format) on the Sun386i system.

A common object file consists of a file header, a system header (if the file is link editor output), a table of section headers, a data section, relocation information, (optional) line numbers, a symbol table, and a string table. The general format looks like this:

file-header
system-header
section-headers
data
relocation
line-numbers
symbol-table
string-table

section-headers contains a number of section headers:

section 1 header
...
section n header

Similarly, data, relocation, and line-numbers are each divided into n sections.

The last three parts of an object file (line numbers, symbol table and string table) may be missing if the program was linked with the -s option of ld.1 or if they were removed by strip.1 Also note that the relocation information will be absent after linking unless the -r option of ld.1 was used. The string table exists only if the symbol table contains symbols with names longer than eight characters.

The sizes of each section (contained in the header, discussed below) are in bytes.

When an a.out file is loaded into memory for execution, three logical segments are set up: the text segment, the data segment (initialized data followed by uninitialized, the latter actually being initialized to all 0's), and a stack. The text segment starts at location 0x1000 by default.

The a.out file produced by ld.1 has the magic number 0413 in the first field of the system header. The headers (file header, system header, and section headers) are loaded at the beginning of the text segment and the text immediately follows the headers in the user address space. The first text address will equal 0x1000 plus the size of the headers, and will vary depending upon the number of section headers in the a.out file. In an a.out file with three sections (.text, .data, .bss, and .comment), the first text address is at 0x000010D0. The text segment is not writable by the program; if other processes are executing the same a.out file, the processes will share a single text segment.

The data segment starts at the next 4K boundary past the last text address. The first data address is determined by the following: If an a.out file were split into 4K chunks, one of the chunks would contain both the end of text and the beginning of data. When the a.out file is loaded into memory for execution, that chunk will appear twice; once at the end of text and once at the beginning of data (with some unused space in between). The duplicated chunk of text that appears at the beginning of data is never executed; it is duplicated so that the operating system may bring in pieces of the file in multiples of the page size without having to realign the beginning of the data section to a page boundary. Therefore the first data address is the sum of the next segment boundary past the end of text plus the remainder of the last text address divided by 4K. If the last text address is a multiple of 4K no duplication is necessary.

On the Sun386i computer the stack begins at location 0xFBFFFFFF and grows toward lower addresses. The stack is automatically extended as required. The data segment is extended only as requested by the brk.2 system call.

For relocatable files the value of a word in the text or data portions that is not a reference to an undefined external symbol is exactly the value that will appear in memory when the file is executed. If a word in the text involves a reference to an undefined external symbol, there will be a relocation entry for the word, the storage class of the symbol-table entry for the symbol will be marked as an ``external symbol'', and the value and section number of the symbol-table entry will be undefined. When the file is processed by the link editor and the external symbol becomes defined, the value of the symbol will be added to the word in the file.

File Header

The format of the file header is:

struct filehdr
{
	unsigned short	f_magic;	/* magic number */
	unsigned short	f_nscns;	/* number of sections */
	long		f_timdat;	/* time and date stamp */
	long		f_symptr;	/* file ptr to symtab */
	long		f_nsyms;	/* # symtab entries */
	unsigned short	f_opthdr;	/* sizeof(opt hdr) */
	unsigned short	f_flags;	/* flags */
};

System Header

The format of the system header is:

typedef struct aouthdr
{
	short	magic;		/* magic number */
	short	vstamp;		/* version stamp */
	long	tsize;		/* text size in bytes, padded */
	long	dsize;		/* initialized data (.data) */
	long	bsize;		/* uninitialized data (.bss) */
	long	entry;		/* entry point */
	long	text_start;	/* base of text used for this file */
	long	data_start;	/* base of data used for this file */
} AOUTHDR;

Section Header

The format of the section header is:

struct scnhdr
{
	char		s_name[SYMNMLEN];/* section name */
	long		s_paddr;	/* physical address */
	long		s_vaddr;	/* virtual address */
	long		s_size;		/* section size */
	long		s_scnptr;	/* file ptr to raw data */
	long		s_relptr;	/* file ptr to relocation */
	long		s_lnnoptr;	/* file ptr to line numbers */
	unsigned short	s_nreloc;	/* # reloc entries */
	unsigned short	s_nlnno;	/* # line number entries */
	long		s_flags;	/* flags */
};

Relocation

Object files have one relocation entry for each relocatable reference in the text or data. If relocation information is present, it will be in the following format:

struct reloc
{
	long	r_vaddr;	/* (virtual) address of reference */
	long	r_symndx;	/* index into symbol table */
	ushort	r_type;		/* relocation type */
};

The start of the relocation information is s_relptr from the section header. If there is no relocation information, s_relptr is 0.

Line Number

The cc.1v command generates an entry in the object file for each C source line on which a breakpoint is possible (when invoked with the -g option. Users can refer to line numbers when using the appropriate debugger, such as dbx.1 The structure of these line number entries appears below.

struct	lineno
{
	union
	{
		long	l_symndx ;
		long	l_paddr ;
	}		l_addr ;
	unsigned short	l_lnno ;
} ;

Numbering starts with one at the top of the source file and increments independent of transition between functions. The initial line number entry for a function has l_lnno equal to zero, and the symbol table index of the function's entry is in l_symndx. Otherwise, l_lnno is non-zero, and l_paddr is the physical address of the code for the referenced line. Thus the overall structure is the following:

l_addr l_lnno

function symtab index	0
physical address	line
physical address	line
...
function symtab index	0
physical address	line
physical address	line
...

Symbol Table

The format of each symbol in the symbol table is described by the syment structure, shown below. This structure is compatible with System V COFF, but has an added _n_dbx structure which is needed by dbx.1

#define  SYMNMLEN	8
#define  FILNMLEN	14
#define  DIMNUM	4

struct syment
{
    union/* all ways to get a symbol name */
    {
        char_n_name[SYMNMLEN]; /* name of symbol */
        struct
        {
            long_n_zeroes;/* == 0L if in string table */
            long_n_offset;/* location in string table */
        } _n_n;
        char*_n_nptr[2];/* allows overlaying */
        struct
        {
            char_n_leading_zero;/* null char */
            char_n_dbx_type;/* stab type */
            short_n_dbx_desc;/* value of desc field */
            long_n_stab_ptr;/* table ptr */
        } _n_dbx;
    } _n;
    longn_value;/* value of symbol */
    shortn_scnum;/* section number */
    unsigned shortn_type;/* type and derived type */
    charn_sclass;/* storage class */
    charn_numaux;/* number of aux entries */
};

#define  n_name	_n._n_name
#define  n_zeroes	_n._n_n._n_zeroes
#define  n_offset	_n._n_n._n_offset
#define  n_nptr	_n._n_nptr[1]

The storage class member (n_sclass) is set to one of the constants defined in <storclass.h>. Some symbols require more information than a single entry; they are followed by auxiliary entries that are the same size as a symbol entry. The format follows:

union auxent {
	struct {
		long	x_tagndx;
		union {
			struct {
				unsigned short	x_lnno;
				unsigned short	x_size;
			} x_lnsz;
			long	x_fsize;
		} x_misc;
		union {
			struct {
				long	x_lnnoptr;
				long	x_endndx;
			}  x_fcn;
			struct {
				unsigned short	x_dimen[DIMNUM];
			} x_ary;
		} x_fcnary;
		unsigned short  x_tvndx;
	} x_sym;

	struct {
		char	x_fname[FILNMLEN];
	} x_file;

	struct {
		long	    x_scnlen;	  
		unsigned short  x_nreloc;  
		unsigned short  x_nlinno;  
	} x_scn;

	struct {
		long		x_tvfill;
		unsigned short	x_tvlen;
		unsigned short	x_tvran[2];
	} x_tv;
};

Indexes of symbol table entries begin at zero. The start of the symbol table is f_symptr (from the file header) bytes from the beginning of the file. If the symbol table is stripped, f_symptr is 0. The string table (if one exists) begins at f_symptr + (f_nsyms * SYMESZ) bytes from the beginning of the file.

SEE ALSO

as.1 cc.1v ld.1 brk(2), ldfcn.3


index | Inhaltsverzeichniss | Kommentar

Created by unroff & hp-tools. © somebody (See intro for details). All Rights Reserved. Last modified 11/5/97