ArticleslgStudy

computer science

Object file

Object file is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Object file rather than just read about it. In short: An object file is a file that contains machine code or bytecode, as well as other data and metadata, generated by a compiler or assembler from source code during the compilation or assembly process. The machine code that is generated is known as object code.

Key takeaways

  • Object file belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Object file to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Object file from memory before moving on to harder problems.

Reference excerpt

An object file is a file that contains machine code or bytecode, as well as other data and metadata, generated by a compiler or assembler from source code during the compilation or assembly process. The machine code that is generated is known as object code. The object code is usually relocatable, and not usually directly executable. There are various formats for object files, and the same machine code can be packaged in different object file formats. An object file may also work like a shared library. The metadata that object files may include can be used for linking or debugging; it includes information to resolve symbolic cross-references between different modules, relocation information, stack unwinding information, comments, program symbols, and debugging or profiling information. Other metadata may include the date and time of compilation, the compiler name and version, and other identifying information.

The term "object program" dates from at least the 1950s: A term in automatic programming for the machine language program produced by the machine by translating a source program written by the programmer in a language similar to algebraic notation. A linker is used to combine the object code into one executable program or library pulling in precompiled system libraries as needed.

Object file formats There are many different object file formats; originally each type of computer and supporting software had its own unique format, such as the OS/360 Object File Format, but with the advent of Unix and other portable operating systems, some formats, such as COFF, ELF, and Mach-O, have been defined and used on different kinds of systems. Some systems make a distinction between formats which are directly executable and formats which require processing by the linker. For example, OS/360 and successors call the first format a load module and the second an object module. In this case the files have entirely different formats. DOS and Windows also have different file formats for executable files and object files, such as Portable Executable for executables and COFF for object files in 32-bit and 64-bit Windows. Unix and Unix-like systems have used the same format for executable and object files, starting with the original a.out format. Some formats can contain machine code for different processors, with the correct one chosen by the operating system when the program is loaded. 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 a program is being developed. If the format is used for executables, the design also affects the time programs take to begin running, and thus the responsiveness for users. 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.

Absolute files Many early computers, or small microcomputers, support only an absolute object format. Programs are not relocatable; they need to be assembled or compiled to execute at specific, predefined addresses. The file contains no relocation or linkage information. These files can be loaded into read/write memory, or stored in read-only memory. For example, the Motorola 6800 MIKBUG monitor contains a routine to read an absolute object file (SREC Format) from paper tape. DOS COM files are a more recent example of absolute object files.

Segmentation 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 to the program. Some of these regions correspond to sections 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) 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. The debugging data format of debugging information may either be an integral part of the object file format, as in COFF, or a semi-independent format which may be used with several object formats, such as stabs or DWARF.

See also Intel hexadecimal object file format (typically with file extension .HEX, but sometimes also with .OBJ) Object Module Format (ICL) (OMF for ICL VME) Object Module Format (Intel) (OMF for Intel 8080/8085, OBJ for Intel 8086) Executable Translation unit (programming) Precompiled header Modules (C++)

References

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Object file

Start with the simplest possible case. Write down what Object file claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Object file before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Object file ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Object file

In research
Object file appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Object file in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Object file is common in secondary-school and first-year university syllabi. It links to neighbouring topics Compiler construction, Computer libraries, Executable file formats, so understanding it makes those chapters shorter.
In everyday life
Look for Object file outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Object file” →

How to study Object file in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Object file means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Object file out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Object file in simple terms?

An object file is a file that contains machine code or bytecode, as well as other data and metadata, generated by a compiler or assembler from source code during the compilation or assembly process. The machine code that is generated is known as object code.

Why does Object file matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Object file?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Object file.

Tags

  • Compiler construction
  • Computer libraries
  • Executable file formats
  • Programming language implementation

Keep exploring