Object file formats[edit]

advertisement
Object file
From Wikipedia, the free encyclopedia
"OBJ file" redirects here. For the specific format used on DOS, see Relocatable Object Module Format.
For OBJ model files, see Wavefront .obj file.
This article needs additional citations for verification. Please help improve this
article by adding citations to reliable sources. Unsourced material may be challenged
and removed. (August 2012)
An object file is a file containing object code, meaning relocable format machine code that is usually
not directly executable. Object files are produced by an assembler, compiler, or other language
translator, and used as input to the linker, which in turn typically generates an executable or library by
combining parts of object files. There are various formats for object files, and the same object code can
be packaged in different object files.
In addition to the object code itself, object files may contain metadata used for linking or debugging,
including: information to resolve symbolic cross-references between different
modules, relocation information, stack unwinding (*) information, comments, program symbols,
debugging or profiling information.
Contents
[hide]




1 Object file formats
2 See also
3 References
4 Further reading
Object file formats[edit]
An object file format is a computer file format used for the storage of object code and related data.
There are many different object file formats; originally each type of computer had its own unique format,
but with the advent of Unix and other portable operating systems, some formats, such
as COFF and ELF have been defined and used on different kinds of systems. It is possible for the same
file format to be used both as linker input and output, and thus as the library and executable file
format.[1]:p.16
The design and/or choice of an object file format is a key part of overall system design. It affects the
performance of the linker and thus programmer turnaround while developing. If the format is used for
executables, the design also affects the time programs take to begin running, and thus
the responsiveness for users.
Most object file formats are structured as separate sections of data, each section containing a certain
type of data. These sections are known as "segments" due to the term "memory segment", which was
previously a common form of memory management. When a program is loaded into memory by
a loader, the loader allocates various regions of memory. Some of these regions correspond to
segments of the object file, and thus are usually known by the same names. Others, such as the stack,
only exist at run time. In some cases relocation is done by the loader (or linker) to specify the actual
memory addresses. However, for many programs or architectures relocation is not necessary, due to
being handled by the memory management unit or by position-independent code. On some systems
the segments of the object file can then be copied (paged) into memory and executed, without needing
further processing. On these systems this may be done lazily, that is, only when the segments are
referenced during execution, for example via a memory-mapped file backed by the object file.
Types of data supported by typical object file formats:

Header (descriptive and control information)
I








Code segment ("text segment", executable code)
Data segment (initialized static variables)
Read-only data segment (rodata, initialized static constants)
BSS segment (uninitialized static data, both variables and constants)
External definitions and references for linking
Relocation information
Dynamic linking information
Debugging information
Segments in different object files may be combined by the linker according to rules specified when the
segments are defined. Conventions exist for segments shared between object files; for instance,
in DOS there are different memory models that specify the names of special segments and whether or
not they may be combined.[2]
Debugging information may either be an integral part of the object file format, as in COFF, or a semiindependent format which may be used with several object formats, such as stabs or DWARF.
The GNU Project's Binary File Descriptor library (BFD library) provides a common API for the
manipulation of object files in a variety of formats.
See also[edit]


Linker
Object code
References[edit]
1. Jump up^ IBM Corporation (1973). IBM OS Linkage Editor and Loader.
2. Jump up^ Irvine, Kip R. (1993), Assembly language for the IBM-PC (2nd ed.), New York:
Macmillan, ISBN 0-02-359651-1
Further reading[edit]

Levine, John R. (2000). Linkers & Loaders. Morgan Kaufmann Publishers. p. 256. ISBN 1-55860496-0.
*) What is stack unwinding?
In any language that supports recursive functions (ie. pretty much everything except Fortran 77 and
Brainf*ck) the language runtime keeps a stack of what functions are currently executing. Stack unwinding
is a way of inspecting, and possibly modifying, that stack.
II
Download