What is the O file format?
A .o file is a compiled object file - an intermediate binary produced by a compiler such as GCC or Clang when it translates a single C source file into machine code. The output contains machine instructions, initialized and uninitialized data segments, a symbol table, and relocation entries, but it is not yet executable: references to functions and variables defined in other translation units are left as unresolved placeholders for the linker.
The binary format depends on the target platform:
- On Linux and most Unix/BSD systems,
.ofiles use the ELF (Executable and Linkable Format) container, recognized by the magic bytes\x7FELFat byte offset 0 and ane_typeofET_REL(relocatable, value0x0001). - On macOS, the equivalent uses the Mach-O format, beginning with
CF FA ED FE(64-bit little-endian). - On Windows the functionally identical file is named with the .obj extension and uses the COFF format.
After compilation, the linker (ld) combines one or more .o files with libraries to produce an executable or a shared library. Multiple .o files can also be bundled into a static archive using the ar command.
.o files are temporary build artifacts generated automatically by the toolchain and are not intended to be opened by end users. Developers who need to inspect them can use nm, objdump, or readelf to examine symbols, sections, and disassembly.
Security & safety
RISK: LOWA .o is build-time data, not something the OS launches, so it poses little direct risk to end users - you cannot double-click and run it. For developers the concern is supply-chain trust: linking an object from an untrusted source bakes its machine code straight into your program, so only build with objects/libraries from sources you trust. The objects in your own build tree are safe to delete; they regenerate on the next compile.
Format details
in a nutshellPrograms that open O files
Technical details
deep spec| Container format | ELF on Linux/Unix, Mach-O on macOS, COFF on Windows (where the file is typically named `.obj`) |
| File encoding | Binary (not human-readable text) |
| ELF magic bytes | `7F 45 4C 46` (`\x7FELF`) at byte offset 0 - present in all ELF-based object files |
| ELF object type field | `e_type = ET_REL` (0x0001) in the ELF header - distinguishes a relocatable object from an executable (`ET_EXEC`) or shared library (`ET_DYN`) |
| MIME type | `application/x-object`; also carried as `application/octet-stream` by generic servers |
| Byte order | Encoded in the `EI_DATA` byte of the ELF header: little-endian (`ELFDATA2LSB`) on x86/x86-64/ARM, big-endian (`ELFDATA2MSB`) on PowerPC/SPARC |
| Key sections | `.text` (executable code), `.data` (initialized globals), `.bss` (zero-initialized globals), `.rodata` (read-only constants) |
| Symbol table | `.symtab` section lists each defined and referenced symbol's name, binding (local/global/weak), type (function/object), and value |
| Relocation entries | `.rel.text` / `.rela.text` sections record every address slot the linker must patch when merging object files into a final binary |
| Architecture identification | `e_machine` field in the ELF header identifies the CPU target: `EM_X86_64` (0x3E), `EM_AARCH64` (0xB7), `EM_386` (0x03), etc. |
| Typical file size | 1 KB to several MB per translation unit, depending on source complexity and compiler optimization level |
| Compression | None - object files are stored as raw uncompressed binary data |
| One-to-one compilation model | Exactly one `.o` file is emitted per source translation unit (one per `.c` or `.cpp` file); the linker later merges them |
| Static library packaging | Multiple `.o` files are archived into a `.a` static library using `ar`, which preserves each object as a named member |
| Link-time resolution only | Unlike `.so` / `.dylib` shared libraries, all symbol references in a `.o` are resolved entirely at link time, leaving no runtime dynamic dependencies |
| Inspection tools | `nm` (list symbols), `objdump` (disassembly and section dumps), `readelf` (ELF header and section details), `otool` (macOS Mach-O equivalent) |
| Released | Object-file concept from early Unix (1970s); ELF since System V Release 4 (early 1990s) |
| Latest version | ELF format frozen since the 1990s; container evolves with each compiler/ABI |
| Open standard | Yes · royalty-free |
| Specification | refspecs.linuxfoundation.org |
O conversions
Community Q&A
asked by usersNo questions yet - be the first to ask about O files.