title: How do relocations work in COFF object (not image) files
body: <p>What steps exactly are taken by the linker while resolving relocations in an object file before creating the final image? More specifically, how does the linker treat the value which is already stored at the relocation site? Does it always add it to the final VA/RVA, or is it sometimes ignored (e.g certain relocation types)?</p>
  
  <p>I couldn't find a clear explanation in the <a href="http://msdn.microsoft.com/en-us/library/windows/hardware/gg463119.aspx" rel="noreferrer">MS PE/COFF Specfication</a>, and after googling and experimenting for a while, all I could find out was this:</p>
  
  <ol>
  <li>In the MS COFF spec, chapter 5.6.2 "Base Relocation Types", it is said that "The base relocation applies all 32 bits of the difference to the 32-bit field at offset", which I guess means that the relocation should take into account whatever address is already stored at the specified offset. However, chapter 5.6 (the .reloc section) is only relevant to image files, and not object files.</li>
  <li>The dumpbin utility adds a column named "Applied To" when printing the relocations table, which seems to always (no matter the relocation type) contain the value which is stored at the relocation site.</li>
  <li>The <a href="http://www.delorie.com/djgpp/doc/coff/reloc.html" rel="noreferrer">Relocation Directives chapter in the DJGPP COFF Specification</a> clearly states that the value currently stored at the location should be added to the address of the symbol pointed to by the relocation table entry.</li>
  </ol>
  
  <p>Can you point me to any (relevant) documentation which explains how relocations are handled by the linker?</p>