The Microsoft documentation for the PE file format mentions Image files and Object files:
This specification describes the structure of executable (image) files and object files under the Windows family of operating systems. These files are referred to as Portable Executable (PE) and Common Object File Format (COFF) files, respectively.
I understand that the PE file format is destined to hold all sorts of more-or-less executable files, including exe and dll files. I also understand that "object files" is typically used for libraries (i.e. dlls, or shared objects on linux).
Hence, the quoted sentence could mean that an "object file" - which would also be a COFF file? is a DLL, and an image file - PE - an exe?
To add to the confusion, further in the same documentation there is a "COFF header" that exists both for image file and for object files.
So I find it rather unclear: what is an image file? what is an object file? how do they relate to the PE format? and what does coff has to do with anything?
41 Answer
As far as I understand it, object files are the intermediate output of a compiler before the final .exe or .dll is created. For example, each input .c file corresponds to one output object file; they don't have references to other objects or external libraries resolved yet. A linker combines the object files into an image file.
(When a program consists of many source files, this means the whole thing doesn't have to be recompiled over and over for every edit a developer makes – just the edited file is recompiled and the whole thing relinked.)
Only static libraries (.lib/.a) contain object files, as they're read at linking time and statically incorporated into the output image. Dynamic libraries (.dll/.so) as well as executables are image files, as they contain the final data that's directly loaded into memory for execution.
Formats such as ELF or PE/COFF exist to add metadata to these files – in addition to raw machine code, they allow specifying which dynamic libraries the image needs, which symbols (functions or variables) it exports, which ones it imports, etc. As far as I know, Windows PE executable image format is a derivative of the original COFF.