==================================================
Anatomy of a Hello World Object file Debug build
==================================================

This attempts to describe the meaning of all of the various sections here for my own benefit.  We start off with the header which I understand pretty well.

::

  Microsoft (R) COFF Binary File Dumper Version 5.12.8078
  Copyright (C) Microsoft Corp 1992-1998. All rights reserved.


  Dump of file objtest.obj

  File Type: COFF OBJECT

  FILE HEADER VALUES
             14C machine (i386)
               6 number of sections
        41AE47AE time date stamp Wed Dec 01 17:37:34 2004
             5A4 file pointer to symbol table
              20 number of symbols
               0 size of optional header
               0 characteristics

Section 1
=========

The directive section.  This apparently contains flags for use by the linker

::


  SECTION HEADER #1
  .drectve name
       0 physical address
       0 virtual address
      38 size of raw data
     104 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  -defaultlib:LIBC
  00000010: 44 20 2D 64 65 66 61 75 6C 74 6C 69 62 3A 4F 4C  D -defaultlib:OL
  00000020: 44 4E 41 4D 45 53 20 2D 65 64 69 74 61 6E 64 63  DNAMES -editandc
  00000030: 6F 6E 74 69 6E 75 65 20                          ontinue 

   Linker Directives
   -----------------
   -defaultlib:LIBCD
   -defaultlib:OLDNAMES
   -editandcontinue

Section 2
=========

Debug$S is presumably debug symbols.

::

  SECTION HEADER #2
  .debug$S name
       0 physical address
       0 virtual address
     334 size of raw data
     13C 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 2B 00 09 00 00 00 00 00 24 43 3A 5C  ....+.......$C:\
  00000010: 6F 62 6A 74 65 73 74 5C 6F 62 6A 74 65 73 74 5C  objtest\objtest\
  00000020: 44 65 62 75 67 5C 6F 62 6A 74 65 73 74 2E 6F 62  Debug\objtest.ob
  00000030: 6A 01 03 13 10 01 01 00 00 05 00 0C 00 00 00 04  j...............
  00000040: 23 0C 00 00 00 06 23 2E 4D 69 63 72 6F 73 6F 66  #.....#.Microsof
  00000050: 74 20 28 52 29 20 33 32 2D 62 69 74 20 43 2F 43  t (R) 32-bit C/C
  00000060: 2B 2B 20 4F 70 74 69 6D 69 7A 69 6E 67 20 43 6F  ++ Optimizing Co
  00000070: 6D 70 69 6C 65 72 63 77 64 00 43 3A 5C 6F 62 6A  mpilercwd.C:\obj
  00000080: 74 65 73 74 5C 6F 62 6A 74 65 73 74 00 63 6C 00  test\objtest.cl.
  00000090: 43 3A 5C 50 72 6F 67 72 61 6D 20 46 69 6C 65 73  C:\Program Files
  000000A0: 5C 4D 69 63 72 6F 73 6F 66 74 20 56 69 73 75 61  \Microsoft Visua
  000000B0: 6C 20 53 74 75 64 69 6F 5C 56 43 39 38 5C 42 49  l Studio\VC98\BI
  000000C0: 4E 5C 63 6C 2E 65 78 65 00 63 6D 64 00 2D 6E 6F  N\cl.exe.cmd.-no
  000000D0: 6C 6F 67 6F 20 2D 4D 4C 64 20 2D 57 33 20 2D 47  logo -MLd -W3 -G
  000000E0: 6D 20 2D 47 58 20 2D 5A 49 20 2D 4F 64 20 2D 44  m -GX -ZI -Od -D
  000000F0: 57 49 4E 33 32 20 2D 44 5F 44 45 42 55 47 20 2D  WIN32 -D_DEBUG -
  00000100: 44 5F 43 4F 4E 53 4F 4C 45 20 2D 44 5F 4D 42 43  D_CONSOLE -D_MBC
  00000110: 53 20 2D 46 70 43 3A 5C 6F 62 6A 74 65 73 74 5C  S -FpC:\objtest\
  00000120: 6F 62 6A 74 65 73 74 5C 44 65 62 75 67 5C 6F 62  objtest\Debug\ob
  00000130: 6A 74 65 73 74 2E 70 63 68 20 2D 59 75 73 74 64  jtest.pch -Yustd
  00000140: 61 66 78 2E 68 20 2D 46 6F 43 3A 5C 6F 62 6A 74  afx.h -FoC:\objt
  00000150: 65 73 74 5C 6F 62 6A 74 65 73 74 5C 44 65 62 75  est\objtest\Debu
  00000160: 67 5C 20 2D 46 64 43 3A 5C 6F 62 6A 74 65 73 74  g\ -FdC:\objtest
  00000170: 5C 6F 62 6A 74 65 73 74 5C 44 65 62 75 67 5C 20  \objtest\Debug\ 
  00000180: 2D 46 44 20 2D 47 5A 20 2D 63 20 2D 49 22 43 3A  -FD -GZ -c -I"C:
  00000190: 5C 50 72 6F 67 72 61 6D 20 46 69 6C 65 73 5C 4D  \Program Files\M
  000001A0: 69 63 72 6F 73 6F 66 74 20 56 69 73 75 61 6C 20  icrosoft Visual 
  000001B0: 53 74 75 64 69 6F 5C 56 43 39 38 5C 49 4E 43 4C  Studio\VC98\INCL
  000001C0: 55 44 45 22 20 2D 49 22 43 3A 5C 50 72 6F 67 72  UDE" -I"C:\Progr
  000001D0: 61 6D 20 46 69 6C 65 73 5C 4D 69 63 72 6F 73 6F  am Files\Microso
  000001E0: 66 74 20 56 69 73 75 61 6C 20 53 74 75 64 69 6F  ft Visual Studio
  000001F0: 5C 56 43 39 38 5C 4D 46 43 5C 49 4E 43 4C 55 44  \VC98\MFC\INCLUD
  00000200: 45 22 20 2D 49 22 43 3A 5C 50 72 6F 67 72 61 6D  E" -I"C:\Program
  00000210: 20 46 69 6C 65 73 5C 4D 69 63 72 6F 73 6F 66 74   Files\Microsoft
  00000220: 20 56 69 73 75 61 6C 20 53 74 75 64 69 6F 5C 56   Visual Studio\V
  00000230: 43 39 38 5C 41 54 4C 5C 49 4E 43 4C 55 44 45 22  C98\ATL\INCLUDE"
  00000240: 20 2D 49 22 43 3A 5C 50 72 6F 67 72 61 6D 20 46   -I"C:\Program F
  00000250: 69 6C 65 73 5C 4D 69 63 72 6F 73 6F 66 74 20 56  iles\Microsoft V
  00000260: 69 73 75 61 6C 20 53 74 75 64 69 6F 20 2E 4E 45  isual Studio .NE
  00000270: 54 5C 46 72 61 6D 65 77 6F 72 6B 53 44 4B 5C 69  T\FrameworkSDK\i
  00000280: 6E 63 6C 75 64 65 22 20 2D 49 63 3A 5C 73 72 63  nclude" -Ic:\src
  00000290: 5C 70 79 74 68 6F 6E 5C 64 69 73 74 5C 73 72 63  \python\dist\src
  000002A0: 5C 69 6E 63 6C 75 64 65 20 2D 49 63 3A 5C 73 72  \include -Ic:\sr
  000002B0: 63 5C 70 79 74 68 6F 6E 5C 64 69 73 74 5C 73 72  c\python\dist\sr
  000002C0: 63 5C 70 63 20 2D 49 63 3A 5C 73 72 63 5C 70 79  c\pc -Ic:\src\py
  000002D0: 77 69 6E 33 32 5C 77 69 6E 33 32 5C 73 72 63 20  win32\win32\src 
  000002E0: 2D 54 50 20 2D 58 00 73 72 63 00 43 3A 5C 6F 62  -TP -X.src.C:\ob
  000002F0: 6A 74 65 73 74 5C 6F 62 6A 74 65 73 74 5C 6F 62  jtest\objtest\ob
  00000300: 6A 74 65 73 74 2E 63 70 70 00 70 64 62 00 43 3A  jtest.cpp.pdb.C:
  00000310: 5C 6F 62 6A 74 65 73 74 5C 6F 62 6A 74 65 73 74  \objtest\objtest
  00000320: 5C 44 65 62 75 67 5C 76 63 36 30 2E 70 64 62 00  \Debug\vc60.pdb.
  00000330: 00 00 E0 77                                      ..àw

Section 3
=========

Text is actual code

::

  SECTION HEADER #3
   .text name
       0 physical address
       0 virtual address
      38 size of raw data
     470 file pointer to raw data
     4A8 file pointer to relocation table
     4C6 file pointer to line numbers
       3 number of relocations
       4 number of line numbers
  60501020 flags
         Code
         Communal; sym= _main
         16 byte align
         Execute Read

  RAW DATA #3
  00000000: 55 8B EC 83 EC 40 53 56 57 8D 7D C0 B9 10 00 00  U‹ìƒì@SVW.}À¹...
  00000010: 00 B8 CC CC CC CC F3 AB 68 00 00 00 00 E8 00 00  .¸ÌÌÌÌó«h....è..
  00000020: 00 00 83 C4 04 33 C0 5F 5E 5B 83 C4 40 3B EC E8  ..ƒÄ.3À_^[ƒÄ@;ìè
  00000030: 00 00 00 00 8B E5 5D C3                          ....‹å]Ã

  RELOCATIONS #3
                                                Symbol    Symbol
  Offset    Type              Applied To         Index     Name
  --------  ----------------  -----------------  --------  ------
  00000019  DIR32                      00000000        13  ??_C@_0O@FEEI@Hello?5World?$CB?6?$AA@ (`string')
  0000001E  REL32                      00000000         F  _printf
  00000030  REL32                      00000000        14  __chkesp

  LINENUMBERS #3

  Symbol index:        D Base line number:     7
  Symbol name = _main
  00000018(    8)  00000025(    9)  00000027(   10)

Section 4
=========

Rdata is read only data.  Will I make this distinction?

::

  SECTION HEADER #4
  .rdata name
       0 physical address
       0 virtual address
       E size of raw data
     4DE 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
  40301040 flags
         Initialized Data
         Communal; sym= "`string'" (??_C@_0O@FEEI@Hello?5World?$CB?6?$AA@)
         4 byte align
         Read Only

  RAW DATA #4
  00000000: 48 65 6C 6C 6F 20 57 6F 72 6C 64 21 0A 00        Hello World!..

Section 5
=========

Debug$S? Why are there two of these?

::

  SECTION HEADER #5
  .debug$S name
       0 physical address
       0 virtual address
      70 size of raw data
     4EC file pointer to raw data
     55C 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 #5
  00000000: 2A 00 0B 10 00 00 00 00 00 00 00 00 00 00 00 00  *...............
  00000010: 38 00 00 00 18 00 00 00 27 00 00 00 5F 10 00 00  8.......'..._...
  00000020: 00 00 00 00 00 00 01 04 6D 61 69 6E 1C 00 12 10  ........main....
  00000030: 40 00 00 00 40 00 00 00 00 00 00 00 0C 00 00 00  @...@...........
  00000040: 00 00 00 00 00 00 00 00 00 00 0F 00 06 10 08 00  ................
  00000050: 00 00 74 00 00 00 04 61 72 67 63 0F 00 06 10 0C  ..t....argc.....
  00000060: 00 00 00 5D 10 00 00 04 61 72 67 76 02 00 06 00  ...]....argv....

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


Section 6
=========

Debug T  Where to find the .pdb?

::

  SECTION HEADER #6
  .debug$T name
       0 physical address
       0 virtual address
      34 size of raw data
     570 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 #6
  00000000: 02 00 00 00 2E 00 16 00 AD 47 AE 41 02 00 00 00  ........­G®A....
  00000010: 21 63 3A 5C 6F 62 6A 74 65 73 74 5C 6F 62 6A 74  !c:\objtest\objt
  00000020: 65 73 74 5C 64 65 62 75 67 5C 76 63 36 30 2E 70  est\debug\vc60.p
  00000030: 64 62 F2 F1                                      dbòñ

Symbol Table
============

::

  COFF SYMBOL TABLE
  000 00000000 DEBUG  notype       Filename     | .file
    C:\objtest\objtest\objtest.cpp
  003 000B2306 ABS    notype       Static       | @comp.id
  004 00000000 SECT1  notype       Static       | .drectve
    Section length   38, #relocs    0, #linenums    0, checksum        0
    Relocation CRC 00000000
  007 00000000 SECT2  notype       Static       | .debug$S
    Section length  334, #relocs    0, #linenums    0, checksum        0
    Relocation CRC 00000000
  00A 00000000 SECT3  notype       Static       | .text
    Section length   38, #relocs    3, #linenums    4, checksum D337989B, selection    1 (pick no duplicates)
    Relocation CRC E7AB95FF
  00D 00000000 SECT3  notype ()    External     | _main
    tag index 00000015 size 00000038 lines 000004C6 next function 00000000
  00F 00000000 UNDEF  notype ()    External     | _printf
  010 00000000 SECT4  notype       Static       | .rdata
    Section length    E, #relocs    0, #linenums    0, checksum FBA62CFE, selection    2 (pick any)
    Relocation CRC 00000000
  013 00000000 SECT4  notype       External     | ??_C@_0O@FEEI@Hello?5World?$CB?6?$AA@ (`string')
  014 00000000 UNDEF  notype ()    External     | __chkesp
  015 00000000 SECT3  notype       BeginFunction | .bf
    line# 0007 end 00000000
  017 00000004 SECT3  notype       .bf or.ef    | .lf
  018 00000038 SECT3  notype       EndFunction  | .ef
    line# 000a
  01A 00000000 SECT5  notype       Static       | .debug$S
    Section length   70, #relocs    2, #linenums    0, checksum        0, selection    5 (pick associative Section 3)
    Relocation CRC 13D2BF73
  01D 00000000 SECT6  notype       Static       | .debug$T
    Section length   34, #relocs    0, #linenums    0, checksum        0
    Relocation CRC 00000000

  String Table Size = 0x2A bytes

Summary
=======

::

  Summary

         3A4 .debug$S
          34 .debug$T
          38 .drectve
           E .rdata
          38 .text

