Developer's Topics
Chapter 7, Common Object File Format (COFF)

File header

File header

The file header contains the 20 bytes of information shown in Table 7-2, ``File header contents''. The last 2 bytes are flags that are used by ld and object file utilities.



Table 7-2 File header contents

 Bytes   Declaration      Name       Description
 -------------------------------------------------------------
   0-1   unsigned short   f_magic    Magic number 
   2-3   unsigned short   f_nscns    Number of sections
   4-7   long int         f_timdat   Time and date stamp
                                     indicating when the file
                                     was created, expressed as
                                     the number of elapsed
                                     seconds since 00:00:00
                                     GMT, January 1, 1970
  8-11   long int         f_symptr   File pointer containing
                                     the starting address of
                                     the symbol table
 12-15   long int         f_nsyms    Number of entries in the
                                     symbol table
 16-17   unsigned short   f_opthdr   Number of bytes in the
                                     optional header
 18-19   unsigned short   f_flags    Flags (see Table 7-3,
                                     ``File header flags'' 


Magic numbers

The magic number specifies the target machine on which the object file is executable. 

Flags

The last 2 bytes of the file header are flags that describe the type of the object file. Currently defined flags are found in the header file filehdr.h and are shown in Table 7-3, ``File header flags''.



Table 7-3 File header flags

 Mnemonic   Flag      Meaning
 ---------------------------------------------------
 F_RELFLG     00001   Relocation information
                      stripped from the file
 F_EXEC       00002   File is executable (i.e., no
                      unresolved external
                      references)
 F_LNNO       00004   Line numbers stripped from the
                      file
 F_LSYMS      00010   Local symbols stripped from
                      the file
 F_AR16WR   0000200   16-bit byte reversed word
 F_AR32WR   0000400   32-bit byte reversed word


File header declaration

The C structure declaration for the file header is shown below. This declaration may be found in the header file filehdr.h.

   struct filehdr
   {
     unsigned short   f_magic;  /* magic number */
     unsigned short   f_nscns;  /* number of section */
   

long f_timdat; /* time and date stamp */

long f_symptr; /* file ptr to symbol table */

long f_nsyms; /* number entries in the symbol table */

unsigned short f_opthdr; /* size of optional header */

unsigned short f_flags; /* flags */ };

#define FILHDR struct filehdr #define FILHSZ sizeof(FILHDR)