Introduction
This chapter describes the object file format, called ELF (Executable and
Linking Format). There are three main types of object files.
• A
relocatable file
holds code and data suitable for linking with
other object files to create an executable or a shared object file.
• An
executable file
holds a program suitable for execution; the file
specifies how exec(BA_OS) creates a program's process image.
• A
shared object file
holds code and data suitable for linking in
two contexts. First, the link editor [see ld(BA_OS)] processes the
shared object file with other relocatable and shared object files
to create another object file. Second, the dynamic linker combines
it with an executable file and other shared objects to create a
process image.
Created by the assembler and link editor, object files are binary
representations of programs intended to be executed directly on a
processor. Programs that require other abstract machines, such as shell
scripts, are excluded.
After the introductory material, this chapter focuses on the file format
and how it pertains to building programs. Chapter 5 also describes parts
of the object file, concentrating on the information necessary to execute
a program.
File Format
Object files participate in program linking (building a program) and
program execution (running a program). For convenience and efficiency,
the object file format provides parallel views of a file's contents,
reflecting the differing needs of those activities. Figure 4-1 shows an
object file's organization.
Figure 4-1: Object File Format
ELF Header
Program header table
optional
Section 1
...
Section n
ELF Header
Program header table
required
Segment 1
Segment 2
Segment 3