Introduction
When Microsoft’s compiler in
Visual Studio builds with link-time
code generation (/GL), it doesn’t write machine code. The
.obj file holds the compiler’s own intermediate language, and the linker
generates the code later. A short anonymous header identifies what the data is, and the
data after it is private to Microsoft’s tools.
Structure
The header is called ANON_OBJECT_HEADER in winnt.h. Version 1 is 32 bytes; version 2 and later add three fields, 44 bytes in all.
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 2 | Sig1 | 0: IMAGE_FILE_MACHINE_UNKNOWN |
| 2 | 2 | Sig2 | 0xFFFF |
| 4 | 2 | Version | The version, 1 or more |
| 6 | 2 | Machine | The processor, as in the COFF machine values |
| 8 | 4 | TimeDateStamp | When the file was made |
| 12 | 16 | ClassID | A class identifier for the data that follows |
| 28 | 4 | SizeOfData | The size of the data after the header |
| 32 | 4 | Flags | Version 2 and later (ANON_OBJECT_HEADER_V2). The meaning of its bits is not documented in any source read (no flag values are defined in the headers) |
| 36 | 4 | MetaDataSize | Version 2 and later. By its name, the size of metadata; not documented |
| 40 | 4 | MetaDataOffset | Version 2 and later. By its name, the offset of the metadata; not documented (whether it is counted from the start of the file or of the data is not stated) |
The field layout above was checked against the raw
mingw-w64 winnt.h:
ANON_OBJECT_HEADER is Sig1, Sig2, Version, Machine (WORD each), TimeDateStamp (DWORD), ClassID (CLSID, 16 bytes) and
SizeOfData (DWORD), 32 bytes; ANON_OBJECT_HEADER_V2 adds Flags, MetaDataSize and MetaDataOffset (DWORD each), 44
bytes; ANON_OBJECT_HEADER_BIGOBJ adds NumberOfSections, PointerToSymbolTable and NumberOfSymbols, 56 bytes. The
viewer lists a problem when SizeOfData is smaller or larger than the bytes after the header.
Sources: the structure definitions ANON_OBJECT_HEADER and ANON_OBJECT_HEADER_V2 in the
mingw-w64 winnt.h (Wine’s winnt.h has only the 32-byte version). Neither Microsoft’s PE Format
specification nor LLVM describes this header; PE Format covers only the
short import header that shares its first four bytes. LLVM’s COFF.h defines two class identifiers: BigObjMagic (the bigobj value below) and ClGlObjMagic, the bytes 38 FE B3 0C A5 D9 AB 4D AC 9B D6 B6 22 26 53 C2; from its name, that is the class of a link-time-code-generation object written by cl with /GL (inference from the name; LLVM has no comment). Other class identifiers may exist. The data’s format, and the contents of the data after the header (private to Microsoft’s
tools) are undocumented. The little-endian byte order of the fields is as in every
COFF structure.
A file with the same first four bytes, version 2 or more and the class identifier
D1BAA1C7-BAEE-4BA9-AF20-FAF66AA4DCB8 is a
bigobj, and one with version 0 is a
short import object.
Not described
The gaps are those on the object file overview.
Also used for
- Wavefront OBJ – A plain text mesh of vertices, normals and faces, read by almost every 3D program.
Variants
- OMF object file – Intel’s object format for 16-bit DOS and Windows compilers, in typed records
- COFF object file – compiled code from Windows compilers, waiting for the linker
- COFF object file (bigobj) – the extended form of COFF, for objects with very many sections
- Anonymous object header – the wrapper Microsoft’s compiler writes for link-time code generation
Links
Software
- Visual Studio – Microsoft’s development environment, whose compiler writes these with
/GLand whose linker reads them (Windows)
Reference
- /GL – Microsoft’s documentation of whole program optimisation