# COFF

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/COFF
> Markdown URL: https://mediated.wiki/source/COFF.md
> Source: https://en.wikipedia.org/wiki/COFF
> Source revision: 1311739756
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

{{Short description|Executable file format}}
{{Refimprove|date=March 2010}}
{{Infobox file format
| name          = COFF
| extension     = none, {{mono|.o}}, {{mono|.obj}}, {{mono|.lib}}<ref>{{Cite web|url=http://msdn.microsoft.com/library/en-us/dv_vcce4/html/evgrflibreference.asp|title=LIB Reference (Embedded Visual C++ Programmers Guide)|website=msdn.microsoft.com|access-date=2021-02-04|url-status=dead|archive-url=https://web.archive.org/web/20030825233127/http://msdn.microsoft.com/library/en-us/dv_vcce4/html/evgrflibreference.asp|archivedate=2003-08-25}}</ref>
| mime          = 
| magic         = * {{code|4C 01}}<!-- IMAGE_FILE_MACHINE_I386 --> for [i386](/source/Intel_80386)
* {{code|64 86}}<!-- IMAGE_FILE_MACHINE_AMD64 --> for [AMD64](/source/AMD64)
* {{code|00 02}}<!-- IMAGE_FILE_MACHINE_IA64 --> for [Itanium](/source/Itanium)<ref name="msCOFFheader">{{cite web|url=https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-image_file_header|title=IMAGE_FILE_HEADER structure (winnt.h)|language=en|date=2018-05-12|access-date=2023-12-22}}</ref>
| owner         = [AT&T Corporation](/source/AT%26T_Corporation)
| creatorcode   = 
| genre         = [Binary](/source/Binary_file), [executable](/source/executable), [object](/source/object_code), [shared libraries](/source/shared_libraries)
| containerfor  = 
| containedby   = 
| extendedfrom  = 
| extendedto    = [XCOFF](/source/XCOFF), [ECOFF](/source/ECOFF), [Portable Executable](/source/Portable_Executable), [Executable and Linkable Format](/source/Executable_and_Linkable_Format)
}}

The '''Common Object File Format''' ('''COFF''')  is a [format](/source/file_format) for [executable](/source/executable), [object code](/source/object_code), and [shared library](/source/shared_libraries) [computer file](/source/computer_file)s used on [Unix](/source/Unix) systems. It was introduced in [Unix System V](/source/Unix_System_V), replaced the previously used [a.out](/source/a.out) format, and formed the basis for extended specifications such as [XCOFF](/source/XCOFF) and [ECOFF](/source/ECOFF), before being largely replaced by [ELF](/source/Executable_and_Linkable_Format), introduced with [SVR4](/source/UNIX_System_V). 
COFF and its variants continue to be used on some [Unix-like](/source/Unix-like) systems, on [Microsoft Windows](/source/Microsoft_Windows) ([Portable Executable](/source/Portable_Executable)), in [UEFI](/source/Unified_Extensible_Firmware_Interface) environments and in some embedded development systems.

==History==
The original Unix object file format [a.out](/source/A.out_(file_format)) is unable to adequately support [shared libraries](/source/Library_(computing)), foreign format identification,{{Citation needed|date=January 2013}} or explicit address linkage.{{Citation needed|date=January 2013}} As development of [Unix-like](/source/Unix-like) systems continued both inside and outside [AT&T](/source/AT%26T), different solutions to these and other issues emerged.

COFF was introduced in 1983, in [AT&T's](/source/AT%26T_Computer_Systems) [UNIX System V](/source/UNIX_System_V) for non-[VAX](/source/VAX) [32-bit](/source/32-bit_computing) platforms such as the [3B20](/source/3B_series_computers).{{Citation needed|date=June 2007}} Improvements over the existing AT&T ''a.out'' format included arbitrary sections, explicit processor declarations, and explicit address linkage.

However, the COFF design was both too limited and incompletely specified: there was a limit on the maximum number of sections, a limit on the length of section names, included source files, and the [symbolic debugging](/source/symbolic_debugging) information was incapable of supporting real world languages such as [C](/source/C_(programming_language)), much less newer languages like [C++](/source/C%2B%2B), or new processors. All real world implementations of COFF were necessarily violations of the standard as a result. This led to numerous COFF extensions. [IBM](/source/IBM) used the [XCOFF](/source/XCOFF) format in [AIX](/source/AIX_operating_system); [DEC](/source/Digital_Equipment_Corporation), [SGI](/source/Silicon_Graphics) and others used [ECOFF](/source/ECOFF); and numerous [SysV](/source/SysV) ports and tool chains targeting embedded development each created their own, incompatible, variations.

With the release of SVR4, AT&T replaced COFF with [ELF](/source/Executable_and_Linkable_Format).

While extended versions of COFF continue to be used for some Unix and Unix-like platforms, primarily in [embedded system](/source/embedded_system)s, perhaps the most widespread use of the COFF format today is in [Microsoft](/source/Microsoft)'s [Portable Executable](/source/Portable_Executable) (PE) format. Developed for [Windows NT](/source/Windows_NT), the PE format (sometimes written as PE/COFF) uses a COFF header for [object file](/source/object_file)s, and as a component of the PE header for executable files.<ref>{{Harvnb|Microsoft Corporation|2006b}}</ref>

==Features==
COFF's main improvement over ''a.out'' was the introduction of multiple named sections in the object file. Different object files could have different numbers and types of sections.

===Symbolic debugging information===
The COFF symbolic debugging information consists of symbolic ([string](/source/String_(computer_science))) names for program functions and variables, and line number information, used for setting breakpoints and [tracing](/source/Tracing_(software)) execution.

Symbolic names are stored in the COFF symbol table. Each [symbol table](/source/symbol_table) entry includes a name, storage class, type, value and section number. Short names (8 characters or fewer) are stored directly in the symbol table; longer names are stored as an [offset](/source/Offset_(computer_science)) into the string table at the end of the COFF object.

Storage classes describe the type entity the symbol represents, and may include external variables (C_EXT), automatic (stack) variables (C_AUTO), register variables (C_REG), functions (C_FCN), and many others. The symbol type describes the interpretation of the symbol entity's value and includes values for all the [C](/source/C_(programming_language)) data types.

When compiled with appropriate options, a COFF object file will contain line number information for each possible break point in the text section of the object file. Line number information takes two forms: in the first, for each possible break point in the code, the line number table entry records the address and its matching line number. In the second form, the entry identifies a symbol table entry representing the start of a function, enabling a breakpoint to be set using the function's name.

Note that COFF was not capable of representing line numbers or debugging symbols for included source as with header files rendering the COFF debugging information virtually useless without incompatible extensions.

===Relative virtual address===
When a COFF file is generated, it is not usually known where in memory it will be loaded. The [virtual address](/source/virtual_address) where the first byte of the file will be loaded is called image [base address](/source/base_address). The rest of the file is not necessarily loaded in a contiguous block, but in different '''sections'''.

Relative virtual addresses (RVAs) are not to be confused with standard virtual addresses. A '''relative virtual address''' is the [virtual address](/source/virtual_address) of an object from the file once it is loaded into memory, minus the base address of the file image. If the file were to be mapped literally from disk to memory, the RVA would be the same as that of the offset into the file, but this is actually quite unusual.

Note that the RVA term is only used with objects in the image file. Once loaded into memory, the image base address is added, and ordinary VAs are used.

==Problems==

The COFF file header stores the date and time that the object file was created as a 32-bit binary integer, representing the number of seconds since the [Unix epoch](/source/Unix_epoch), 1&nbsp;January&nbsp;1970 00:00:00&nbsp;[UTC](/source/Coordinated_Universal_Time). As such, dates occurring after 19&nbsp;January&nbsp;2038 cannot be stored in this format (the [Year 2038 problem](/source/Year_2038_problem)).<ref>{{Cite book|url=http://bitsavers.org/pdf/att/unix/System_V_386_Release_3.2/UNIX_System_V_386_Release_3.2_Programmers_Guide_Vol2_1989.pdf|title=UNIX System V/386 Release 3.2 Programmer's Guide, Volume II|chapter=11 Common Object File Format (COFF)|publisher=[Prentice-Hall](/source/Prentice-Hall)|date=1989|isbn=0-13-944885-3}}</ref>{{Rp|11-4}}

==See also==
* [Comparison of executable file formats](/source/Comparison_of_executable_file_formats)

==References==
{{reflist}}

==Further reading==
* [https://web.archive.org/web/20140723105157/http://www-scf.usc.edu/~csci402/ncode/coff_8h-source.html MIPS COFF Spec]
* {{Citation|first=Gintaras|last=Gircys|title=Understanding and Using COFF|publisher=O'Reilly and Associates|isbn=0-937175-31-5|year=1988}}
* {{Citation|title=Common Object File Format (COFF)|edition=Revision 4.1|year=2006b|author=Microsoft Corporation|url=http://support.microsoft.com/?id=121460|accessdate=2007-06-02|archive-url=https://web.archive.org/web/20061216043713/http://support.microsoft.com/?id=121460|archive-date=2006-12-16|url-status=dead}}
* {{cite web |url=https://software-dl.ti.com/ccs/esd/documents/sdto_cgt_A-Brief-History-of-TI-Object-File-Formats.html |title=A Brief History of TI Object File Formats |archive-url=https://web.archive.org/web/20231126140009/https://software-dl.ti.com/ccs/esd/documents/sdto_cgt_A-Brief-History-of-TI-Object-File-Formats.html |archive-date=2023-11-26 |url-status=live}}
* {{cite web |url=https://www.ti.com/lit/an/spraao8/spraao8.pdf |title=Common Object File Format |website=Texas Instruments}}

==External links==
* [https://learn.microsoft.com/en-us/archive/msdn-magazine/2002/february/inside-windows-win32-portable-executable-file-format-in-detail An In-Depth Look into the Win32 Portable Executable File Format] and [https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#machine-types PE format documentation] at Microsoft

{{Executables}}

{{Authority control}}
{{DEFAULTSORT:Coff}}
Category:Executable file formats

---
Adapted from the Wikipedia article [COFF](https://en.wikipedia.org/wiki/COFF) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/COFF?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
