Specifications.
[pintos-anon] / specs / sysv-abi-update.html / ch4.intro.html
1 <html>
2 <title>Chapter 4: Object Files</title>
3 <h1>Introduction</h1>
4 This chapter describes the 
5 object file format, called ELF (Executable and Linking Format).
6 There are three main types of object files.
7 <ul>
8 <p><li>
9 A <i>relocatable file</i>
10 holds code and data suitable for linking
11 with other object files to create an executable
12 or a shared object file.
13 <p><li>
14 An <i>executable file</i>
15 holds a program suitable for execution;
16 the file specifies how
17 <code>exec</code>(BA_OS)
18 creates a program's process image.
19 <p><li>
20 A
21 <i>shared object file</i>
22 holds code and data suitable for linking
23 in two contexts.
24 First, the link editor [see <code>ld</code>(BA_OS)]
25 processes the shared object file with other relocatable
26 and shared object files to create another object file.
27 Second, the dynamic linker combines it with an executable file and other
28 shared objects to create a process image.
29 </ul>
30 <p>
31 Created by the assembler and link editor, object files are binary
32 representations of programs intended to be executed directly on
33 a processor.  Programs that require other abstract machines, such
34 as shell scripts, are excluded.
35 </p>
36 <p>
37 After the introductory material, this chapter focuses on the file
38 format and how it pertains to building programs.  Chapter 5 also
39 describes parts of the object file, concentrating on the information
40 necessary to execute a program.
41 </p>
42 <a name=file_format></a>
43 <h2>File Format</h2><p>
44 Object files participate in program linking (building a program)
45 and program execution (running a program).  For convenience and
46 efficiency, the object file format provides parallel views of a file's
47 contents, reflecting the differing needs of those activities.
48 Figure 4-1 shows an object file's organization.
49 <hr>
50 <b>Figure 4-1: Object File Format</b>
51 <p>
52 <table>
53 <tr><td width="250">
54 <table border=1 cellspacing=0>
55 <caption align=bottom><b>Linking View</b></caption>
56 <tr><td align=center>ELF Header</td></tr>
57 <tr><td align=center>Program header table<br><i>optional</i></td></tr>
58 <tr><td align=center>Section 1</td></tr>
59 <tr><td align=center>...</td></tr>
60 <tr><td align=center>Section n</td></tr>
61 <tr><td align=center>...</td></tr>
62 <tr><td align=center>Section header table<br><i>required</i></td></tr>
63 </table>
64 </td>
65 <td>
66 <table border=1 cellspacing=0>
67 <caption align=bottom><b>Execution View</b></caption>
68 <tr><td align=center>ELF Header</td></tr>
69 <tr><td align=center>Program header table<br><i>required</i></td></tr>
70 <tr><td align=center>Segment 1<br></td></tr>
71 <tr><td align=center>Segment 2<br></td></tr>
72 <tr><td align=center>Segment 3<br></td></tr>
73 <tr><td align=center>...</td></tr>
74 <tr><td align=center>Section header table<br><i>optional</i></td></tr>
75 </table>
76 </td>
77 </tr>
78 </table>
79 <hr>
80 <p>
81 An <i>ELF header</i> resides at the beginning and
82 holds a ``road map''
83 describing the file's organization. <i>Sections</i> hold the bulk
84 of object file information for the linking view: instructions,
85 data, symbol table, relocation information, and so on.
86 Descriptions of special sections appear later in the chapter.
87 Chapter 5 discusses <i>segments</i> and the program execution
88 view of the file.
89 </p>
90 <p>
91 A <i>program header table</i> tells the system how to create a process image.
92 Files used to build a process image (execute a program)
93 must have a program header table; relocatable files do not need one.
94 A <i>section header table</i>
95 contains information describing the file's sections.
96 Every section has an entry in the table; each entry
97 gives information such as the section name, the
98 section size, and so on.
99 Files used during linking must have a section header table;
100 other object files may or may not have one.
101 <p><hr>
102 <img src=warning.gif alt="NOTE:">
103 Although the figure shows the program header table
104 immediately after the ELF header, and the section header table
105 following the sections, actual files may differ.
106 Moreover, sections and segments have no specified order.
107 Only the ELF header has a fixed position in the file.
108 <hr><p>
109 <a name=data_representation></a>
110 <h2>Data Representation</h2><p>
111 As described here, the object file
112 format
113 supports various processors with 8-bit bytes
114 and either 32-bit or 64-bit architectures.
115 Nevertheless, it is intended to be extensible to larger
116 (or smaller) architectures.
117 Object files therefore represent some control data
118 with a machine-independent format,
119 making it possible to identify object files and
120 interpret their contents in a common way.
121 Remaining data in an object file
122 use the encoding of the target processor, regardless of
123 the machine on which the file was created.
124 <hr>
125 <b>Figure 4-2: 32-Bit Data Types</b>
126 <p>
127 <table border=1 cellspacing=0>
128 <tr>
129 <th>Name</th>
130 <th>Size</th>
131 <th>Alignment</th>
132 <th>Purpose</th>
133 <tr>
134 <td><code>Elf32_Addr</code></td>
135 <TD align=center><code>4</code></td>
136 <TD align=center><code>4</code></td>
137 <td>Unsigned program address</td>
138 </tr>
139 <tr>
140 <td><code>Elf32_Off</code></td>
141 <TD align=center><code>4</code></td>
142 <TD align=center><code>4</code></td>
143 <td>Unsigned file offset</td>
144 </tr>
145 <tr>
146 <td><code>Elf32_Half</code></td>
147 <td align=center><code>2</code></td>
148 <td align=center><code>2</code></td>
149 <td>Unsigned medium integer</td>
150 </tr>
151 <tr>
152 <td><code>Elf32_Word</code></td>
153 <TD align=center><code>4</code></td>
154 <TD align=center><code>4</code></td>
155 <td>Unsigned integer</td>
156 </tr>
157 <tr>
158 <td><code>Elf32_Sword</code></td>
159 <TD align=center><code>4</code></td>
160 <TD align=center><code>4</code></td>
161 <td>Signed integer</td>
162 </tr>
163 <tr>
164 <td><code>unsigned char</code></td>
165 <TD align=center><code>1</code></td>
166 <TD align=center><code>1</code></td>
167 <td>Unsigned small integer</td>
168 </tr>
169 </table>
170 <p>
171 <b>64-Bit Data Types</b>
172 <p>
173 <table border cellspacing=0>
174 <tr>
175 <th>Name</th>
176 <th>Size</th>
177 <th>Alignment</th>
178 <th>Purpose</th>
179 <tr>
180 <td><code>Elf64_Addr</code></td>
181 <TD align=center><code>8</code></td>
182 <TD align=center><code>8</code></td>
183 <td>Unsigned program address</td>
184 </tr>
185 <tr>
186 <td><code>Elf64_Off</code></td>
187 <TD align=center><code>8</code></td>
188 <TD align=center><code>8</code></td>
189 <td>Unsigned file offset</td>
190 </tr>
191 <tr>
192 <td><code>Elf64_Half</code></td>
193 <TD align=center><code>2</code></td>
194 <TD align=center><code>2</code></td>
195 <td>Unsigned medium integer</td>
196 </tr>
197 <tr>
198 <td><code>Elf64_Word</code></td>
199 <td align=center><code>4</code></td>
200 <td align=center><code>4</code></td>
201 <td>Unsigned integer</td>
202 </tr>
203 <tr>
204 <td><code>Elf64_Sword</code></td>
205 <td align=center><code>4</code></td>
206 <td align=center><code>4</code></td>
207 <td>Signed integer</td>
208 </tr>
209 <tr>
210 <td><code>Elf64_Xword</code></td>
211 <td align=center><code>8</code></td>
212 <td align=center><code>8</code></td>
213 <td>Unsigned long integer</td>
214 </tr>
215 <tr>
216 <td><code>Elf64_Sxword</code></td>
217 <td align=center><code>8</code></td>
218 <td align=center><code>8</code></td>
219 <td>Signed long integer</td>
220 </tr>
221 <tr>
222 <td><code>unsigned char</code></td>
223 <td align=center><code>1</code></td>
224 <td align=center><code>1</code></td>
225 <td>Unsigned small integer</td>
226 </tr>
227 </table>
228 <p>
229 <hr>
230 All data structures that the object file format
231 defines follow the ``natural'' size and alignment guidelines
232 for the relevant class.
233 If necessary, data structures contain explicit padding to
234 ensure 8-byte alignment for 8-byte objects,
235 4-byte alignment for 4-byte objects, to force
236 structure sizes to a multiple of 4 or 8, and so forth.
237 Data also have suitable alignment from the beginning of the file.
238 Thus, for example, a structure containing an
239 <code>Elf32_Addr</code>
240 member will be aligned on a 4-byte boundary within the file.
241 <p>
242 For portability reasons, ELF uses no bit-fields.
243 <hr>
244 <a href=contents.html><img src=contents.gif alt="Contents">
245 <a href=ch4.eheader.html><img src=next.gif alt="Next"></a>
246 <hr>
247 <i>
248 <small>
249 &#169; 1997, 1998, 1999, 2000, 2001 The Santa Cruz Operation, Inc.  All rights reserved.
250 </small>
251 </i>
252 </html>