1a.out(4) File Formats a.out(4)
2
3
4
6 a.out - Executable and Linking Format (ELF) files
7
9 #include <elf.h>
10
11
13 The file name a.out is the default output file name from the link edi‐
14 tor, ld(1). The link editor will make an a.out executable if there were
15 no errors in linking. The output file of the assembler, as(1), also
16 follows the format of the a.out file although its default file name is
17 different.
18
19
20 Programs that manipulate ELF files may use the library that elf(3ELF)
21 describes. An overview of the file format follows. For more complete
22 information, see the references given below.
23
24
25
26
27 ┌────────────────────────────┬──────────────────────────────┐
28 │ Linking View │ Execution View │
29 ├────────────────────────────┼──────────────────────────────┤
30 │ELF header │ ELF header │
31 ├────────────────────────────┼──────────────────────────────┤
32 │Program header table │ Program header table │
33 │optional │ │
34 ├────────────────────────────┼──────────────────────────────┤
35 │Section 1 │ Segment 1 │
36 ├────────────────────────────┼──────────────────────────────┤
37 │. . . │ │
38 ├────────────────────────────┼──────────────────────────────┤
39 │Section n │ Segment 2 │
40 ├────────────────────────────┼──────────────────────────────┤
41 │. . . │ │
42 ├────────────────────────────┼──────────────────────────────┤
43 │. . . │ . . . │
44 ├────────────────────────────┼──────────────────────────────┤
45 │Section header table │ Section header table │
46 │ │ optional │
47 └────────────────────────────┴──────────────────────────────┘
48
49
50 An ELF header resides at the beginning and holds a ``road map''
51 describing the file's organization. Sections hold the bulk of object
52 file information for the linking view: instructions, data, symbol ta‐
53 ble, relocation information, and so on. Segments hold the object file
54 information for the program execution view. As shown, a segment may
55 contain one or more sections.
56
57
58 A program header table, if present, tells the system how to create a
59 process image. Files used to build a process image (execute a program)
60 must have a program header table; relocatable files do not need one. A
61 section header table contains information describing the file's sec‐
62 tions. Every section has an entry in the table; each entry gives infor‐
63 mation such as the section name, the section size, etc. Files used dur‐
64 ing linking must have a section header table; other object files may or
65 may not have one.
66
67
68 Although the figure shows the program header table immediately after
69 the ELF header, and the section header table following the sections,
70 actual files may differ. Moreover, sections and segments have no speci‐
71 fied order. Only the ELF header has a fixed position in the file.
72
73
74 When an a.out file is loaded into memory for execution, three logical
75 segments are set up: the text segment, the data segment (initialized
76 data followed by uninitialized, the latter actually being initialized
77 to all 0's), and a stack. The text segment is not writable by the pro‐
78 gram; if other processes are executing the same a.out file, the pro‐
79 cesses will share a single text segment.
80
81
82 The data segment starts at the next maximal page boundary past the last
83 text address. If the system supports more than one page size, the
84 ``maximal page'' is the largest supported size. When the process image
85 is created, the part of the file holding the end of text and the begin‐
86 ning of data may appear twice. The duplicated chunk of text that
87 appears at the beginning of data is never executed; it is duplicated so
88 that the operating system may bring in pieces of the file in multiples
89 of the actual page size without having to realign the beginning of the
90 data section to a page boundary. Therefore, the first data address is
91 the sum of the next maximal page boundary past the end of text plus the
92 remainder of the last text address divided by the maximal page size. If
93 the last text address is a multiple of the maximal page size, no dupli‐
94 cation is necessary. The stack is automatically extended as required.
95 The data segment is extended as requested by the brk(2) system call.
96
98 as(1), ld(1), brk(2), elf(3ELF)
99
100
101 ANSI C Programmer's Guide
102
103
104
105SunOS 5.11 24 Aug 2009 a.out(4)