Appendix: Example Object File

This section describes the PE/COFF object file produced by compiling the file HELLO2.C, which contains the following small C program:

main()
{
foo();
}

foo()
{
}

The commands used to compile HELLO.C (with debug information) and generate this example were the following (the -Gy option to the compiler is used, which causes each procedure to be generated as a separate COMDAT section):

cl -c -Zi -Gy hello2.c
link -dump -all hello2.obj >hello2.dmp

Here is the resulting file HELLO2.DMP: (The reader is encouraged to experiment with various other examples, in order to clarify the concepts described in this specification.)

Dump of file hello2.obj

File Type: COFF OBJECT

FILE HEADER VALUES
     14C machine (i386)
       7 number of sections
3436E157 time date stamp Sat Oct 04 17:37:43 1997
     2A0 file pointer to symbol table
      1E number of symbols
       0 size of optional header
       0 characteristics

SECTION HEADER #1
.drectve name
       0 physical address
       0 virtual address
      26 size of raw data
     12C file pointer to raw data
       0 file pointer to relocation table
       0 file pointer to line numbers
       0 number of relocations
       0 number of line numbers
  100A00 flags
         Info
         Remove
         1 byte align

RAW DATA #1
00000000  2D 64 65 66 61 75 6C 74 | 6C 69 62 3A 4C 49 42 43 -default|lib:LIBC
00000010  20 2D 64 65 66 61 75 6C | 74 6C 69 62 3A 4F 4C 44  -defaul|tlib:OLD
00000020  4E 41 4D 45 53 20                                 NAMES 

   Linker Directives
   -----------------
   -defaultlib:LIBC
   -defaultlib:OLDNAMES

SECTION HEADER #2
.debug$S name
       0 physical address
       0 virtual address
      5C size of raw data
     152 file pointer to raw data
       0 file pointer to relocation table
       0 file pointer to line numbers
       0 number of relocations
       0 number of line numbers
42100048 flags
         No Pad
         Initialized Data
         Discardable
         1 byte align
         Read Only

RAW DATA #2
00000000  02 00 00 00 11 00 09 00 | 00 00 00 00 0A 68 65 6C ........|.....hel
00000010  6C 6F 32 2E 6F 62 6A 43 | 00 01 00 05 00 00 00 3C lo2.objC|.......<
00000020  4D 69 63 72 6F 73 6F 66 | 74 20 28 52 29 20 33 32 Microsof|t (R) 32
00000030  2D 62 69 74 20 43 2F 43 | 2B 2B 20 4F 70 74 69 6D -bit C/C|++ Optim
00000040  69 7A 69 6E 67 20 43 6F | 6D 70 69 6C 65 72 20 56 izing Co|mpiler V
00000050  65 72 73 69 6F 6E 20 31 | 31 2E 30 30             ersion 1|1.00

SECTION HEADER #3
   .text name
       0 physical address
       0 virtual address
       A size of raw data
     1AE file pointer to raw data
     1B8 file pointer to relocation table
     1C2 file pointer to line numbers
       1 number of relocations
       3 number of line numbers
60501020 flags
         Code
         Communal; sym= _main
         16 byte align
         Execute Read

RAW DATA #3
00000000  55 8B EC E8 00 00 00 00 | 5D C3                   U‹ìè....|].

RELOCATIONS #3
                                                Symbol    Symbol
 Offset    Type              Applied To         Index     Name
 --------  ----------------  -----------------  --------  ------
 00000004  REL32                      00000000        13  _foo

LINENUMBERS #3

 Symbol index:        8 Base line number:     2
 Symbol name = _main
 00000003(    3)  00000008(    4)

SECTION HEADER #4
.debug$S name
       0 physical address
       0 virtual address
      30 size of raw data
     1D4 file pointer to raw data
     204 file pointer to relocation table
       0 file pointer to line numbers
       2 number of relocations
       0 number of line numbers
42101048 flags
         No Pad
         Initialized Data
         Communal (no symbol)
         Discardable
         1 byte align
         Read Only

RAW DATA #4
00000000  2A 00 0B 10 00 00 00 00 | 00 00 00 00 00 00 00 00 *.......|........
00000010  0A 00 00 00 03 00 00 00 | 08 00 00 00 01 10 00 00 ........|........
00000020  00 00 00 00 00 00 01 04 | 6D 61 69 6E 02 00 06 00 ........|main....

RELOCATIONS #4
                                                Symbol    Symbol
 Offset    Type              Applied To         Index     Name
 --------  ----------------  -----------------  --------  ------
 00000020  SECREL                     00000000         8  _main
 00000024  SECTION                        0000         8  _main

SECTION HEADER #5
   .text name
       0 physical address
       0 virtual address
       5 size of raw data
     218 file pointer to raw data
       0 file pointer to relocation table
     21D file pointer to line numbers
       0 number of relocations
       2 number of line numbers
60501020 flags
         Code
         Communal; sym= _foo
         16 byte align
         Execute Read

RAW DATA #5
00000000  55 8B EC 5D C3                                    U‹ì].

LINENUMBERS #5

 Symbol index:       13 Base line number:     7
 Symbol name = _foo
 00000003(    8)

SECTION HEADER #6
.debug$S name
       0 physical address
       0 virtual address
      2F size of raw data
     229 file pointer to raw data
     258 file pointer to relocation table
       0 file pointer to line numbers
       2 number of relocations
       0 number of line numbers
42101048 flags
         No Pad
         Initialized Data
         Communal (no symbol)
         Discardable
         1 byte align
         Read Only

RAW DATA #6
00000000  29 00 0B 10 00 00 00 00 | 00 00 00 00 00 00 00 00 ).......|........
00000010  05 00 00 00 03 00 00 00 | 03 00 00 00 01 10 00 00 ........|........
00000020  00 00 00 00 00 00 01 03 | 66 6F 6F 02 00 06 00    ........|foo....

RELOCATIONS #6
                                                Symbol    Symbol
 Offset    Type              Applied To         Index     Name
 --------  ----------------  -----------------  --------  ------
 00000020  SECREL                     00000000        13  _foo
 00000024  SECTION                        0000        13  _foo

SECTION HEADER #7
.debug$T name
       0 physical address
       0 virtual address
      34 size of raw data
     26C file pointer to raw data
       0 file pointer to relocation table
       0 file pointer to line numbers
       0 number of relocations
       0 number of line numbers
42100048 flags
         No Pad
         Initialized Data
         Discardable
         1 byte align
         Read Only

RAW DATA #7
00000000  02 00 00 00 2E 00 16 00 | 33 E1 36 34 01 00 00 00 ........|3á64....
00000010  22 65 3A 5C 62 62 74 5C | 74 6F 6F 6C 73 5C 76 63 "e:\bbt\|tools\vc
00000020  35 30 5C 62 69 6E 5C 78 | 38 36 5C 76 63 35 30 2E 50\bin\x|86\vc50.
00000030  70 64 62 F1                                       pdb.

COFF SYMBOL TABLE
000 00000000 DEBUG  notype       Filename     | .file
    hello2.c
002 00000000 SECT1  notype       Static       | .drectve
    Section length   26, #relocs    0, #linenums    0, checksum        0
004 00000000 SECT2  notype       Static       | .debug$S
    Section length   5C, #relocs    0, #linenums    0, checksum        0
006 00000000 SECT3  notype       Static       | .text
    Section length    A, #relocs    1, #linenums    3, checksum        0, selection    1 (pick no duplicates)
008 00000000 SECT3  notype ()    External     | _main
    tag index 0000000A size 0000000A lines 000001C2 next function 00000013
00A 00000000 SECT3  notype       BeginFunction | .bf
    line# 0002 end 00000015
00C 00000003 SECT3  notype       .bf or.ef    | .lf
00D 0000000A SECT3  notype       EndFunction  | .ef
    line# 0004
00F 00000000 SECT4  notype       Static       | .debug$S
    Section length   30, #relocs    2, #linenums    0, checksum        0, selection    5 (pick associative Section 3)
011 00000000 SECT5  notype       Static       | .text
    Section length    5, #relocs    0, #linenums    2, checksum        0, selection    1 (pick no duplicates)
013 00000000 SECT5  notype ()    External     | _foo
    tag index 00000015 size 00000005 lines 0000021D next function 00000000
015 00000000 SECT5  notype       BeginFunction | .bf
    line# 0007 end 00000000
017 00000002 SECT5  notype       .bf or.ef    | .lf
018 00000005 SECT5  notype       EndFunction  | .ef
    line# 0008
01A 00000000 SECT6  notype       Static       | .debug$S
   Section length   2F, #relocs    2, #linenums    0, checksum        0, selection    5 (pick associative Section 5)
01C 00000000 SECT7  notype       Static       | .debug$T
    Section length   34, #relocs    0, #linenums    0, checksum        0

String Table Size = 0x0 bytes

     Summary

          BB .debug$S
          34 .debug$T
          26 .drectve
           F .text

Here is a hexadecimal dump of HELLO2.OBJ:

hello2.obj: 
00000000   4c 01 07 00 57 e1 36 34 a0 02 00 00 1e 00 00 00  L...W.64........
00000010   00 00 00 00 2e 64 72 65 63 74 76 65 00 00 00 00  .....drectve....
00000020   00 00 00 00 26 00 00 00 2c 01 00 00 00 00 00 00  ....&...,.......
00000030   00 00 00 00 00 00 00 00 00 0a 10 00 2e 64 65 62  .............deb
00000040   75 67 24 53 00 00 00 00 00 00 00 00 5c 00 00 00  ug$S........\...
00000050   52 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00  R...............
00000060   48 00 10 42 2e 74 65 78 74 00 00 00 00 00 00 00  H..B.text.......
00000070   00 00 00 00 0a 00 00 00 ae 01 00 00 b8 01 00 00  ................
00000080   c2 01 00 00 01 00 03 00 20 10 50 60 2e 64 65 62  ........ .P`.deb
00000090   75 67 24 53 00 00 00 00 00 00 00 00 30 00 00 00  ug$S........0...
000000a0   d4 01 00 00 04 02 00 00 00 00 00 00 02 00 00 00  ................
000000b0   48 10 10 42 2e 74 65 78 74 00 00 00 00 00 00 00  H..B.text.......
000000c0   00 00 00 00 05 00 00 00 18 02 00 00 00 00 00 00  ................
000000d0   1d 02 00 00 00 00 02 00 20 10 50 60 2e 64 65 62  ........ .P`.deb
000000e0   75 67 24 53 00 00 00 00 00 00 00 00 2f 00 00 00  ug$S......../...
000000f0   29 02 00 00 58 02 00 00 00 00 00 00 02 00 00 00  )...X...........
00000100   48 10 10 42 2e 64 65 62 75 67 24 54 00 00 00 00  H..B.debug$T....
00000110   00 00 00 00 34 00 00 00 6c 02 00 00 00 00 00 00  ....4...l.......
00000120   00 00 00 00 00 00 00 00 48 00 10 42 2d 64 65 66  ........H..B-def
00000130   61 75 6c 74 6c 69 62 3a 4c 49 42 43 20 2d 64 65  aultlib:LIBC -de
00000140   66 61 75 6c 74 6c 69 62 3a 4f 4c 44 4e 41 4d 45  faultlib:OLDNAME
00000150   53 20 02 00 00 00 11 00 09 00 00 00 00 00 0a 68  S .............h
00000160   65 6c 6c 6f 32 2e 6f 62 6a 43 00 01 00 05 00 00  ello2.objC......
00000170   00 3c 4d 69 63 72 6f 73 6f 66 74 20 28 52 29 20  .<Microsoft (R) 
00000180   33 32 2d 62 69 74 20 43 2f 43 2b 2b 20 4f 70 74  32-bit C/C++ Opt
00000190   69 6d 69 7a 69 6e 67 20 43 6f 6d 70 69 6c 65 72  imizing Compiler
000001a0   20 56 65 72 73 69 6f 6e 20 31 31 2e 30 30 55 8b   Version 11.00U.
000001b0   ec e8 00 00 00 00 5d c3 04 00 00 00 13 00 00 00  ......].........
000001c0   14 00 08 00 00 00 00 00 03 00 00 00 01 00 08 00  ................
000001d0   00 00 02 00 2a 00 0b 10 00 00 00 00 00 00 00 00  ....*...........
000001e0   00 00 00 00 0a 00 00 00 03 00 00 00 08 00 00 00  ................
000001f0   01 10 00 00 00 00 00 00 00 00 01 04 6d 61 69 6e  ............main
00000200   02 00 06 00 20 00 00 00 08 00 00 00 0b 00 24 00  .... .........$.
00000210   00 00 08 00 00 00 0a 00 55 8b ec 5d c3 13 00 00  ........U..]....
00000220   00 00 00 03 00 00 00 01 00 29 00 0b 10 00 00 00  .........)......
00000230   00 00 00 00 00 00 00 00 00 05 00 00 00 03 00 00  ................
00000240   00 03 00 00 00 01 10 00 00 00 00 00 00 00 00 01  ................
00000250   03 66 6f 6f 02 00 06 00 20 00 00 00 13 00 00 00  .foo.... .......
00000260   0b 00 24 00 00 00 13 00 00 00 0a 00 02 00 00 00  ..$.............
00000270   2e 00 16 00 33 e1 36 34 01 00 00 00 22 65 3a 5c  ....3.64...."e:\
00000280   62 62 74 5c 74 6f 6f 6c 73 5c 76 63 35 30 5c 62  bbt\tools\vc50\b
00000290   69 6e 5c 78 38 36 5c 76 63 35 30 2e 70 64 62 f1  in\x86\vc50.pdb.
000002a0   2e 66 69 6c 65 00 00 00 00 00 00 00 fe ff 00 00  .file...........
000002b0   67 01 68 65 6c 6c 6f 32 2e 63 00 00 00 00 00 00  g.hello2.c......
000002c0   00 00 00 00 2e 64 72 65 63 74 76 65 00 00 00 00  .....drectve....
000002d0   01 00 00 00 03 01 26 00 00 00 00 00 00 00 00 00  ......&.........
000002e0   00 00 00 00 00 00 00 00 2e 64 65 62 75 67 24 53  .........debug$S
000002f0   00 00 00 00 02 00 00 00 03 01 5c 00 00 00 00 00  ..........\.....
00000300   00 00 00 00 00 00 00 00 00 00 00 00 2e 74 65 78  .............tex
00000310   74 00 00 00 00 00 00 00 03 00 00 00 03 01 0a 00  t...............
00000320   00 00 01 00 03 00 00 00 00 00 00 00 01 00 00 00  ................
00000330   5f 6d 61 69 6e 00 00 00 00 00 00 00 03 00 20 00  _main......... .
00000340   02 01 0a 00 00 00 0a 00 00 00 c2 01 00 00 13 00  ................
00000350   00 00 00 00 2e 62 66 00 00 00 00 00 00 00 00 00  .....bf.........
00000360   03 00 00 00 65 01 00 00 00 00 02 00 00 00 00 00  ....e...........
00000370   00 00 15 00 00 00 00 00 2e 6c 66 00 00 00 00 00  .........lf.....
00000380   03 00 00 00 03 00 00 00 65 00 2e 65 66 00 00 00  ........e..ef...
00000390   00 00 0a 00 00 00 03 00 00 00 65 01 00 00 00 00  ..........e.....
000003a0   04 00 00 00 00 00 00 00 00 00 00 00 00 00 2e 64  ...............d
000003b0   65 62 75 67 24 53 00 00 00 00 04 00 00 00 03 01  ebug$S..........
000003c0   30 00 00 00 02 00 00 00 00 00 00 00 03 00 05 00  0...............
000003d0   00 00 2e 74 65 78 74 00 00 00 00 00 00 00 05 00  ...text.........
000003e0   00 00 03 01 05 00 00 00 00 00 02 00 00 00 00 00  ................
000003f0   00 00 01 00 00 00 5f 66 6f 6f 00 00 00 00 00 00  ......_foo......
00000400   00 00 05 00 20 00 02 01 15 00 00 00 05 00 00 00  .... ...........
00000410   1d 02 00 00 00 00 00 00 00 00 2e 62 66 00 00 00  ...........bf...
00000420   00 00 00 00 00 00 05 00 00 00 65 01 00 00 00 00  ..........e.....
00000430   07 00 00 00 00 00 00 00 00 00 00 00 00 00 2e 6c  ...............l
00000440   66 00 00 00 00 00 02 00 00 00 05 00 00 00 65 00  f.............e.
00000450   2e 65 66 00 00 00 00 00 05 00 00 00 05 00 00 00  .ef.............
00000460   65 01 00 00 00 00 08 00 00 00 00 00 00 00 00 00  e...............
00000470   00 00 00 00 2e 64 65 62 75 67 24 53 00 00 00 00  .....debug$S....
00000480   06 00 00 00 03 01 2f 00 00 00 02 00 00 00 00 00  ....../.........
00000490   00 00 05 00 05 00 00 00 2e 64 65 62 75 67 24 54  .........debug$T
000004a0   00 00 00 00 07 00 00 00 03 01 34 00 00 00 00 00  ..........4.....
000004b0   00 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00  ................