Search code examples
windowsassemblyx86-64portable-executablefasm

How to use the fixups attribute on a section?


What exactly does "fixups" do when applied on a section? In a fasm sample i found the following section delcaration and i'm really not sure what the fixups attribute does, i couldn't find much information on that in the fasm documentation.

section '.reloc' fixups data readable discardable
if $=$$
    dd 0,8          ; if there are no fixups, generate dummy entry
end if

Solution

  • This appears to be a workaround for a bug in how FASM generates PECOFF DLLs. The .reloc section only applies to PECOFF images (EXEs and DLLs), and provides relocations (or "fixups") that allow the image to be loaded at any address. (Relocations of a different sort are used in PECOFF object files; these fixups aren't put in the .reloc section.)

    The bug in FASM is that it will generate an empty .reloc section if the DLL doesn't need any relocations rather than not generating one at all. Windows will refuse to load a DLL (or EXE) if has an empty section. The workaround forces a non-empty .reloc section, by adding a dummy "base relocation block" if the .reloc section doesn't have any contents.

    Apparently the developer of FASM doesn't think this is a bug in FASM, but rather a bug in Windows, and so hasn't fixed it.

    To answer your question directly, the fixups keyword appears to indicate that this section is special to FASM, that it's used for image relocations as described above. Unlike the the other attributes it doesn't correspond to one of the section flags used in PECOFF images, so it appears to only be used internally by FASM.