COFF: Difference between revisions
Jump to navigation
Jump to search
[unchecked revision] | [unchecked revision] |
Content deleted Content added
No edit summary |
|||
Line 76: | Line 76: | ||
The structure of this header can be found in filehdr.h, and is 20 bytes longs. |
The structure of this header can be found in filehdr.h, and is 20 bytes longs. |
||
<source lang="c"> |
|||
<pre> |
|||
{ |
{ |
||
unsigned short f_magic; /* Magic number */ |
unsigned short f_magic; /* Magic number */ |
||
Line 86: | Line 86: | ||
unsigned short f_flags; /* Flags */ |
unsigned short f_flags; /* Flags */ |
||
} |
} |
||
</ |
</source> |
||
The magic number varies from implementation to implementation, for example, DJGPP generates COFF files with the value 0x14C in this field. |
The magic number varies from implementation to implementation, for example, DJGPP generates COFF files with the value 0x14C in this field. |
||
Line 108: | Line 108: | ||
The structure of this header can be found in aouthdr.h, and is 28 bytes long. |
The structure of this header can be found in aouthdr.h, and is 28 bytes long. |
||
<source lang="c"> |
|||
<pre> |
|||
{ |
{ |
||
unsigned short magic; /* Magic Number */ |
unsigned short magic; /* Magic Number */ |
||
Line 119: | Line 119: | ||
unsigned long data_start; /* Base of Data used for this file */ |
unsigned long data_start; /* Base of Data used for this file */ |
||
} |
} |
||
</ |
</source> |
||
===Section Header=== |
===Section Header=== |
||
Line 131: | Line 131: | ||
The structure of this header can be found in scnhdr.h, and is 40 bytes long. |
The structure of this header can be found in scnhdr.h, and is 40 bytes long. |
||
<source lang="c"> |
|||
<pre> |
|||
{ |
{ |
||
char s_name[8]; /* Section Name */ |
char s_name[8]; /* Section Name */ |
||
Line 144: | Line 144: | ||
long s_flags; /* Flags for this section */ |
long s_flags; /* Flags for this section */ |
||
} |
} |
||
</ |
</source> |
||
The Section name field stores the name of this section if it is eight characters or fewer, otherwise this field contains a pointer into the String table. See the entry on the String table below. |
The Section name field stores the name of this section if it is eight characters or fewer, otherwise this field contains a pointer into the String table. See the entry on the String table below. |
||
Line 192: | Line 192: | ||
The structure of this header can be found in reloc.h, and is 10 bytes long. |
The structure of this header can be found in reloc.h, and is 10 bytes long. |
||
<source lang="c"> |
|||
<pre> |
|||
{ |
{ |
||
long r_vaddr; /* Reference Address */ |
long r_vaddr; /* Reference Address */ |
||
Line 198: | Line 198: | ||
unsigned short r_type; /* Type of relocation */ |
unsigned short r_type; /* Type of relocation */ |
||
} |
} |
||
</ |
</source> |
||
The Address field gives the offset within the Section's raw data where the address starts. The reference will almost always be a 32-bit value starting at the given address, but this is dependant on implementation and the r_type field. |
The Address field gives the offset within the Section's raw data where the address starts. The reference will almost always be a 32-bit value starting at the given address, but this is dependant on implementation and the r_type field. |
||
Line 218: | Line 218: | ||
The structure of this header can be found in linenum.h, and is 6 bytes long. |
The structure of this header can be found in linenum.h, and is 6 bytes long. |
||
<source lang="c"> |
|||
<pre> |
|||
{ |
{ |
||
union |
union |
||
Line 227: | Line 227: | ||
unsigned short l_lnno; /* Line Number */ |
unsigned short l_lnno; /* Line Number */ |
||
} |
} |
||
</ |
</source> |
||
In brief, The line number table will contain an entry with a line number of zero in which the l_symndx field will indicate the function name Symbol in the Symbol table. This entry will be followed by additional entries with incrementing line numbers which indicate, through the l_paddr field, the byte offset into the section where this line starts. Given this, an exception that occurs during processing of the COFF file can be traced back to a function and a line number within that function. |
In brief, The line number table will contain an entry with a line number of zero in which the l_symndx field will indicate the function name Symbol in the Symbol table. This entry will be followed by additional entries with incrementing line numbers which indicate, through the l_paddr field, the byte offset into the section where this line starts. Given this, an exception that occurs during processing of the COFF file can be traced back to a function and a line number within that function. |
||
Line 241: | Line 241: | ||
The structure of this header can be found in syms.h, and is 18 bytes long. |
The structure of this header can be found in syms.h, and is 18 bytes long. |
||
<source lang="c"> |
|||
<pre> |
|||
{ |
{ |
||
char n_name[8]; /* Symbol Name */ |
char n_name[8]; /* Symbol Name */ |
||
Line 250: | Line 250: | ||
char n_numaux; /* Auxiliary Count */ |
char n_numaux; /* Auxiliary Count */ |
||
} |
} |
||
</ |
</source> |
||
The Symbol name field stores the name of this symbol if it is eight characters or fewer, otherwise this field contains a pointer into the String table. See the entry on the String table below. |
The Symbol name field stores the name of this symbol if it is eight characters or fewer, otherwise this field contains a pointer into the String table. See the entry on the String table below. |
||
Line 339: | Line 339: | ||
The Section table name field and the Symbol table name field are actaully more complicated than was detailed above, they in fact look more like this: |
The Section table name field and the Symbol table name field are actaully more complicated than was detailed above, they in fact look more like this: |
||
<source lang="c"> |
|||
<pre> |
|||
{ |
{ |
||
union |
union |
||
Line 351: | Line 351: | ||
} |
} |
||
} |
} |
||
</ |
</source> |
||
If the name is eight characters or fewer, then the field "zeroes" will be non-zero, and "name" should be interpretted as a character array. Note that this field is not null-terminated unless it is fewer than eight characters in length. |
If the name is eight characters or fewer, then the field "zeroes" will be non-zero, and "name" should be interpretted as a character array. Note that this field is not null-terminated unless it is fewer than eight characters in length. |
||
Line 394: | Line 394: | ||
</pre> |
</pre> |
||
<source lang="c"> |
|||
<pre> |
|||
int mGlobalInt; |
int mGlobalInt; |
||
short mGlobalShort; |
short mGlobalShort; |
||
Line 433: | Line 433: | ||
return mTestValue; |
return mTestValue; |
||
} |
} |
||
</ |
</source> |
||
As you can see, the static global variables are defined in either section 2 (.data) for the initialised ones, or section 3 (.bss) for the uninitialised, with n_value being an offset into the relevant section. The initialised global variables are also defined in section 2 (.data) with offsets. |
As you can see, the static global variables are defined in either section 2 (.data) for the initialised ones, or section 3 (.bss) for the uninitialised, with n_value being an offset into the relevant section. The initialised global variables are also defined in section 2 (.data) with offsets. |