Writing a Compiler – .reloc section of the COFF

I’m looking for a little bit of direction in writing a compiler. I’ve written in Common Intermediate Language, C#, and various other .NET languages; I’ve written my own Metadata Parser and now I’m trying to understand the various aspects of the Portable Executable (PE) layout. One thing that somewhat befuddles me is the .reloc section.

I have the Relocs parsing (or at least I think I do? 🙂 and I wanted to know, within .NET libraries they usually have a single Reloc block with a single HighLow (IMAGE_REL_BASED_HIGHLOW, or just 3) reloc at a given offset that changes. When I go to writing my own PE Header and COFF sections, how do I calculate the Relative Virtual Address of the block, and the Offset (lower 12 bits) on the TypeOffset entry that follows that block header?

I’m currently using the pecoff_v83.docx (Microsoft Portable Executable and Common Object File Format Specification Revision 8.3) from Microsoft’s website, but I think there’s a step I’m missing out on.

I’ll link a relevant post: How are PE Base Relocations build up?

^ That helped me parse the Reloc entries, but parsing them and generating the data that goes into them are different questions.