]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - share/man/man5/elf.5
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / share / man / man5 / elf.5
1 .\" Copyright (c) 1999 Jeroen Ruigrok van der Werven
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\"
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 .\" SUCH DAMAGE.
24 .\"
25 .\" $FreeBSD$
26 .\"
27 .Dd December 18, 2005
28 .Dt ELF 5
29 .Os
30 .Sh NAME
31 .Nm elf
32 .Nd format of ELF executable binary files
33 .Sh SYNOPSIS
34 .In elf.h
35 .Sh DESCRIPTION
36 The header file
37 .In elf.h
38 defines the format of ELF executable binary files.
39 Amongst these files are
40 normal executable files, relocatable object files, core files and shared
41 libraries.
42 .Pp
43 An executable file using the ELF file format consists of an ELF header,
44 followed by a program header table or a section header table, or both.
45 The ELF header is always at offset zero of the file.
46 The program header
47 table and the section header table's offset in the file are defined in the
48 ELF header.
49 The two tables describe the rest of the particularities of
50 the file.
51 .Pp
52 Applications which wish to process ELF binary files for their native
53 architecture only should include
54 .In elf.h
55 in their source code.
56 These applications should need to refer to
57 all the types and structures by their generic names
58 .Dq Elf_xxx
59 and to the macros by
60 .Dq ELF_xxx .
61 Applications written this way can be compiled on any architecture,
62 regardless whether the host is 32-bit or 64-bit.
63 .Pp
64 Should an application need to process ELF files of an unknown
65 architecture then the application needs to include both
66 .In sys/elf32.h
67 and
68 .In sys/elf64.h
69 instead of
70 .In elf.h .
71 Furthermore, all types and structures need to be identified by either
72 .Dq Elf32_xxx
73 or
74 .Dq Elf64_xxx .
75 The macros need to be identified by
76 .Dq ELF32_xxx
77 or
78 .Dq ELF64_xxx .
79 .Pp
80 Whatever the system's architecture is, it will always include
81 .In sys/elf_common.h
82 as well as
83 .In sys/elf_generic.h .
84 .Pp
85 These header files describe the above mentioned headers as C structures
86 and also include structures for dynamic sections, relocation sections and
87 symbol tables.
88 .Pp
89 The following types are being used for 32-bit architectures:
90 .Bd -literal -offset indent
91 Elf32_Addr      Unsigned 32-bit program address
92 Elf32_Half      Unsigned 16-bit field
93 Elf32_Lword     Unsigned 64-bit field
94 Elf32_Off       Unsigned 32-bit file offset
95 Elf32_Sword     Signed 32-bit field or integer
96 Elf32_Word      Unsigned 32-bit field or integer
97 .Ed
98 .Pp
99 For 64-bit architectures we have the following types:
100 .Bd -literal -offset indent
101 Elf64_Addr      Unsigned 64-bit program address
102 Elf64_Half      Unsigned 16-bit field
103 Elf64_Lword     Unsigned 64-bit field
104 Elf64_Off       Unsigned 64-bit file offset
105 Elf64_Sword     Signed 32-bit field
106 Elf64_Sxword    Signed 64-bit field or integer
107 Elf64_Word      Unsigned 32-bit field
108 Elf64_Xword     Unsigned 64-bit field or integer
109 .Ed
110 .Pp
111 All data structures that the file format defines follow the
112 .Dq natural
113 size and alignment guidelines for the relevant class.
114 If necessary,
115 data structures contain explicit padding to ensure 4-byte alignment
116 for 4-byte objects, to force structure sizes to a multiple of 4, etc.
117 .Pp
118 The ELF header is described by the type Elf32_Ehdr or Elf64_Ehdr:
119 .Bd -literal -offset indent
120 typedef struct {
121         unsigned char   e_ident[EI_NIDENT];
122         Elf32_Half      e_type;
123         Elf32_Half      e_machine;
124         Elf32_Word      e_version;
125         Elf32_Addr      e_entry;
126         Elf32_Off       e_phoff;
127         Elf32_Off       e_shoff;
128         Elf32_Word      e_flags;
129         Elf32_Half      e_ehsize;
130         Elf32_Half      e_phentsize;
131         Elf32_Half      e_phnum;
132         Elf32_Half      e_shentsize;
133         Elf32_Half      e_shnum;
134         Elf32_Half      e_shstrndx;
135 } Elf32_Ehdr;
136 .Ed
137 .Bd -literal -offset indent
138 typedef struct {
139         unsigned char   e_ident[EI_NIDENT];
140         Elf64_Half      e_type;
141         Elf64_Half      e_machine;
142         Elf64_Word      e_version;
143         Elf64_Addr      e_entry;
144         Elf64_Off       e_phoff;
145         Elf64_Off       e_shoff;
146         Elf64_Word      e_flags;
147         Elf64_Half      e_ehsize;
148         Elf64_Half      e_phentsize;
149         Elf64_Half      e_phnum;
150         Elf64_Half      e_shentsize;
151         Elf64_Half      e_shnum;
152         Elf64_Half      e_shstrndx;
153 } Elf64_Ehdr;
154 .Ed
155 .Pp
156 The fields have the following meanings:
157 .Pp
158 .Bl -tag -width "e_phentsize" -compact -offset indent
159 .It Dv e_ident
160 This array of bytes specifies to interpret the file,
161 independent of the processor or the file's remaining contents.
162 Within this array everything is named by macros, which start with
163 the prefix
164 .Sy EI_
165 and may contain values which start with the prefix
166 .Sy ELF .
167 The following macros are defined:
168 .Pp
169 .Bl -tag -width "EI_ABIVERSION" -compact
170 .It Dv EI_MAG0
171 The first byte of the magic number.
172 It must be filled with
173 .Sy ELFMAG0 .
174 .It Dv EI_MAG1
175 The second byte of the magic number.
176 It must be filled with
177 .Sy ELFMAG1 .
178 .It Dv EI_MAG2
179 The third byte of the magic number.
180 It must be filled with
181 .Sy ELFMAG2 .
182 .It Dv EI_MAG3
183 The fourth byte of the magic number.
184 It must be filled with
185 .Sy ELFMAG3 .
186 .It Dv EI_CLASS
187 The fifth byte identifies the architecture for this binary:
188 .Pp
189 .Bl -tag -width "ELFCLASSNONE" -compact
190 .It Dv ELFCLASSNONE
191 This class is invalid.
192 .It Dv ELFCLASS32
193 This defines the 32-bit architecture.
194 It supports machines with files
195 and virtual address spaces up to 4 Gigabytes.
196 .It Dv ELFCLASS64
197 This defines the 64-bit architecture.
198 .El
199 .It Dv EI_DATA
200 The sixth byte specifies the data encoding of the processor-specific
201 data in the file.
202 Currently these encodings are supported:
203 .Pp
204 .Bl -tag -width "ELFDATA2LSB" -compact
205 .It Dv ELFDATANONE
206 Unknown data format.
207 .It Dv ELFDATA2LSB
208 Two's complement, little-endian.
209 .It Dv ELFDATA2MSB
210 Two's complement, big-endian.
211 .El
212 .It Dv EI_VERSION
213 The version number of the ELF specification:
214 .Pp
215 .Bl -tag -width "EV_CURRENT" -compact
216 .It Dv EV_NONE
217 Invalid version.
218 .It Dv EV_CURRENT
219 Current version.
220 .El
221 .It Dv EI_OSABI
222 This byte identifies the operating system
223 and ABI to which the object is targeted.
224 Some fields in other ELF structures have flags
225 and values that have platform specific meanings;
226 the interpretation of those fields is determined by the value of this byte.
227 The following values are currently defined:
228 .Pp
229 .Bl -tag -width "ELFOSABI_STANDALONE" -compact
230 .It Dv ELFOSABI_SYSV
231 UNIX System V ABI.
232 .It Dv ELFOSABI_HPUX
233 HP-UX operating system ABI.
234 .It Dv ELFOSABI_NETBSD
235 .Nx
236 operating system ABI.
237 .It Dv ELFOSABI_LINUX
238 GNU/Linux operating system ABI.
239 .It Dv ELFOSABI_HURD
240 GNU/Hurd operating system ABI.
241 .It Dv ELFOSABI_86OPEN
242 86Open Common IA32 ABI.
243 .It Dv ELFOSABI_SOLARIS
244 Solaris operating system ABI.
245 .It Dv ELFOSABI_MONTEREY
246 Monterey project ABI.
247 .It Dv ELFOSABI_IRIX
248 IRIX operating system ABI.
249 .It Dv ELFOSABI_FREEBSD
250 .Fx
251 operating system ABI.
252 .It Dv ELFOSABI_TRU64
253 TRU64 UNIX operating system ABI.
254 .It Dv ELFOSABI_ARM
255 ARM architecture ABI.
256 .It Dv ELFOSABI_STANDALONE
257 Standalone (embedded) ABI.
258 .El
259 .It Dv EI_ABIVERSION
260 This byte identifies the version of the ABI
261 to which the object is targeted.
262 This field is used to distinguish among incompatible versions of an ABI.
263 The interpretation of this version number
264 is dependent on the ABI identified by the EI_OSABI field.
265 Applications conforming to this specification use the value 0.
266 .It Dv EI_PAD
267 Start of padding.
268 These bytes are reserved and set to zero.
269 Programs
270 which read them should ignore them.
271 The value for EI_PAD will change in
272 the future if currently unused bytes are given meanings.
273 .It Dv EI_BRAND
274 Start of architecture identification.
275 .It Dv EI_NIDENT
276 The size of the e_ident array.
277 .El
278 .Pp
279 .It Dv e_type
280 This member of the structure identifies the object file type:
281 .Pp
282 .Bl -tag -width "ET_NONE" -compact
283 .It Dv ET_NONE
284 An unknown type.
285 .It Dv ET_REL
286 A relocatable file.
287 .It Dv ET_EXEC
288 An executable file.
289 .It Dv ET_DYN
290 A shared object.
291 .It Dv ET_CORE
292 A core file.
293 .El
294 .Pp
295 .It Dv e_machine
296 This member specifies the required architecture for an individual file:
297 .Pp
298 .Bl -tag -width "EM_MIPS_RS4_BE" -compact
299 .It Dv EM_NONE
300 An unknown machine.
301 .It Dv EM_M32
302 AT&T WE 32100.
303 .It Dv EM_SPARC
304 Sun Microsystems SPARC.
305 .It Dv EM_386
306 Intel 80386.
307 .It Dv EM_68K
308 Motorola 68000.
309 .It Dv EM_88K
310 Motorola 88000.
311 .It Dv EM_486
312 Intel 80486.
313 .It Dv EM_860
314 Intel 80860.
315 .It Dv EM_MIPS
316 MIPS RS3000 (big-endian only).
317 .It Dv EM_MIPS_RS4_BE
318 MIPS RS4000 (big-endian only).
319 .It Dv EM_SPARC64
320 SPARC v9 64-bit unofficial.
321 .It Dv EM_PARISC
322 HPPA.
323 .It Dv EM_PPC
324 PowerPC.
325 .It Dv EM_ALPHA
326 Compaq [DEC] Alpha.
327 .El
328 .Pp
329 .It Dv e_version
330 This member identifies the file version:
331 .Pp
332 .Bl -tag -width "EV_CURRENT" -compact
333 .It Dv EV_NONE
334 Invalid version
335 .It Dv EV_CURRENT
336 Current version
337 .El
338 .It Dv e_entry
339 This member gives the virtual address to which the system first transfers
340 control, thus starting the process.
341 If the file has no associated entry
342 point, this member holds zero.
343 .It Dv e_phoff
344 This member holds the program header table's file offset in bytes.
345 If
346 the file has no program header table, this member holds zero.
347 .It Dv e_shoff
348 This member holds the section header table's file offset in bytes.
349 If the
350 file has no section header table this member holds zero.
351 .It Dv e_flags
352 This member holds processor-specific flags associated with the file.
353 Flag
354 names take the form EF_`machine_flag'.
355 Currently no flags have been defined.
356 .It Dv e_ehsize
357 This member holds the ELF header's size in bytes.
358 .It Dv e_phentsize
359 This member holds the size in bytes of one entry in the file's program header
360 table; all entries are the same size.
361 .It Dv e_phnum
362 This member holds the number of entries in the program header
363 table.
364 If the file is using extended program header numbering, then the
365 .Sy e_phnum
366 member will contain the value
367 .Dv PN_XNUM
368 and the actual number of program header table entries will be stored
369 in the
370 .Sy sh_info
371 member of the section header at index
372 .Dv SHN_UNDEF .
373 The product of
374 .Sy e_phentsize
375 and the number of program header table entries gives the program
376 header table's size in bytes.
377 If a file has no program header,
378 .Sy e_phnum
379 holds the value zero.
380 .It Dv e_shentsize
381 This member holds a sections header's size in bytes.
382 A section header is one
383 entry in the section header table; all entries are the same size.
384 .It Dv e_shnum
385 This member holds the number of entries in the section header table.
386 If the file is using extended section numbering, then the
387 .Sy e_shnum
388 member will be zero and the actual section number will be stored in the
389 .Sy sh_size
390 member of the section header at index
391 .Dv SHN_UNDEF .
392 If a file has no section header table, both the
393 .Sy e_shnum
394 and the
395 .Sy e_shoff
396 fields of the ELF header will be zero.
397 The product of
398 .Sy e_shentsize
399 and the number of sections in the file gives the section header
400 table's size in bytes.
401 .It Dv e_shstrndx
402 This member holds the section header table index of the entry associated
403 with the section name string table.
404 If extended section numbering is being used, this field will hold the
405 value
406 .Sy SHN_XINDEX ,
407 and the actual section header table index will be present in the
408 .Sy sh_link
409 field of the section header entry at index
410 .Dv SHN_UNDEF .
411 If the file has no section name string
412 table, this member holds the value
413 .Sy SHN_UNDEF .
414 .El
415 .Pp
416 An executable or shared object file's program header table is an array of
417 structures, each describing a segment or other information the system needs
418 to prepare the program for execution.
419 An object file
420 .Em segment
421 contains one or more
422 .Em sections .
423 Program headers are meaningful only for executable and shared object files.
424 A file specifies its own program header size with the ELF header's
425 .Sy e_phentsize
426 and
427 .Sy e_phnum
428 members.
429 As with the Elf executable header, the program header
430 also has different versions depending on the architecture:
431 .Bd -literal -offset indent
432 typedef struct {
433         Elf32_Word      p_type;
434         Elf32_Off       p_offset;
435         Elf32_Addr      p_vaddr;
436         Elf32_Addr      p_paddr;
437         Elf32_Word      p_filesz;
438         Elf32_Word      p_memsz;
439         Elf32_Word      p_flags;
440         Elf32_Word      p_align;
441 } Elf32_Phdr;
442 .Ed
443 .Bd -literal -offset indent
444 typedef struct {
445         Elf64_Word      p_type;
446         Elf64_Word      p_flags;
447         Elf64_Off       p_offset;
448         Elf64_Addr      p_vaddr;
449         Elf64_Addr      p_paddr;
450         Elf64_Xword     p_filesz;
451         Elf64_Xword     p_memsz;
452         Elf64_Xword     p_align;
453 } Elf64_Phdr;
454 .Ed
455 .Pp
456 The main difference between the 32-bit and the 64-bit program header lies
457 only in the location of a
458 .Sy p_flags
459 member in the total struct.
460 .Pp
461 .Bl -tag -width "p_offset" -compact -offset indent
462 .It Dv p_type
463 This member of the Phdr struct tells what kind of segment this array
464 element describes or how to interpret the array element's information.
465 .Pp
466 .Bl -tag -width "PT_DYNAMIC" -compact
467 .It Dv PT_NULL
468 The array element is unused and the other members' values are undefined.
469 This lets the program header have ignored entries.
470 .It Dv PT_LOAD
471 The array element specifies a loadable segment, described by
472 .Sy p_filesz
473 and
474 .Sy p_memsz .
475 The bytes from the file are mapped to the beginning of the memory
476 segment.
477 If the segment's memory size
478 .Pq Sy p_memsz
479 is larger than the file size
480 .Pq Sy p_filesz ,
481 the
482 .Dq extra
483 bytes are defined to hold the value 0 and to follow the segment's
484 initialized area.
485 The file size may not be larger than the memory size.
486 Loadable segment entries in the program header table appear in ascending
487 order, sorted on the
488 .Sy p_vaddr
489 member.
490 .It Dv PT_DYNAMIC
491 The array element specifies dynamic linking information.
492 .It Dv PT_INTERP
493 The array element specifies the location and size of a null-terminated
494 path name to invoke as an interpreter.
495 This segment type is meaningful
496 only for executable files (though it may occur for shared objects).
497 However
498 it may not occur more than once in a file.
499 If it is present it must precede
500 any loadable segment entry.
501 .It Dv PT_NOTE
502 The array element specifies the location and size for auxiliary information.
503 .It Dv PT_SHLIB
504 This segment type is reserved but has unspecified semantics.
505 Programs that
506 contain an array element of this type do not conform to the ABI.
507 .It Dv PT_PHDR
508 The array element, if present, specifies the location and size of the program
509 header table itself, both in the file and in the memory image of the program.
510 This segment type may not occur more than once in a file.
511 Moreover, it may
512 only occur if the program header table is part of the memory image of the
513 program.
514 If it is present it must precede any loadable segment entry.
515 .It Dv PT_LOPROC
516 This value up to and including
517 .Sy PT_HIPROC
518 are reserved for processor-specific semantics.
519 .It Dv PT_HIPROC
520 This value down to and including
521 .Sy PT_LOPROC
522 are reserved for processor-specific semantics.
523 .El
524 .Pp
525 .It Dv p_offset
526 This member holds the offset from the beginning of the file at which
527 the first byte of the segment resides.
528 .It Dv p_vaddr
529 This member holds the virtual address at which the first byte of the
530 segment resides in memory.
531 .It Dv p_paddr
532 On systems for which physical addressing is relevant, this member is
533 reserved for the segment's physical address.
534 Under
535 .Bx
536 this member is
537 not used and must be zero.
538 .It Dv p_filesz
539 This member holds the number of bytes in the file image of the segment.
540 It may be zero.
541 .It Dv p_memsz
542 This member holds the number of bytes in the memory image of the segment.
543 It may be zero.
544 .It Dv p_flags
545 This member holds flags relevant to the segment:
546 .Pp
547 .Bl -tag -width "PF_X" -compact
548 .It Dv PF_X
549 An executable segment.
550 .It Dv PF_W
551 A writable segment.
552 .It Dv PF_R
553 A readable segment.
554 .El
555 .Pp
556 A text segment commonly has the flags
557 .Sy PF_X
558 and
559 .Sy PF_R .
560 A data segment commonly has
561 .Sy PF_X ,
562 .Sy PF_W
563 and
564 .Sy PF_R .
565 .It Dv p_align
566 This member holds the value to which the segments are aligned in memory
567 and in the file.
568 Loadable process segments must have congruent values for
569 .Sy p_vaddr
570 and
571 .Sy p_offset ,
572 modulo the page size.
573 Values of zero and one mean no alignment is required.
574 Otherwise,
575 .Sy p_align
576 should be a positive, integral power of two, and
577 .Sy p_vaddr
578 should equal
579 .Sy p_offset ,
580 modulo
581 .Sy p_align .
582 .El
583 .Pp
584 An file's section header table lets one locate all the file's sections.
585 The
586 section header table is an array of Elf32_Shdr or Elf64_Shdr structures.
587 The
588 ELF header's
589 .Sy e_shoff
590 member gives the byte offset from the beginning of the file to the section
591 header table.
592 .Sy e_shnum
593 holds the number of entries the section header table contains.
594 .Sy e_shentsize
595 holds the size in bytes of each entry.
596 .Pp
597 A section header table index is a subscript into this array.
598 Some section
599 header table indices are reserved.
600 An object file does not have sections for
601 these special indices:
602 .Pp
603 .Bl -tag -width "SHN_LORESERVE" -compact
604 .It Dv SHN_UNDEF
605 This value marks an undefined, missing, irrelevant, or otherwise meaningless
606 section reference.
607 For example, a symbol
608 .Dq defined
609 relative to section number
610 .Sy SHN_UNDEF
611 is an undefined symbol.
612 .It Dv SHN_LORESERVE
613 This value specifies the lower bound of the range of reserved indices.
614 .It Dv SHN_LOPROC
615 This value up to and including
616 .Sy SHN_HIPROC
617 are reserved for processor-specific semantics.
618 .It Dv SHN_HIPROC
619 This value down to and including
620 .Sy SHN_LOPROC
621 are reserved for processor-specific semantics.
622 .It Dv SHN_ABS
623 This value specifies absolute values for the corresponding reference.
624 For
625 example, symbols defined relative to section number
626 .Sy SHN_ABS
627 have absolute values and are not affected by relocation.
628 .It Dv SHN_COMMON
629 Symbols defined relative to this section are common symbols, such as FORTRAN
630 COMMON or unallocated C external variables.
631 .It Dv SHN_HIRESERVE
632 This value specifies the upper bound of the range of reserved indices.
633 The
634 system reserves indices between
635 .Sy SHN_LORESERVE
636 and
637 .Sy SHN_HIRESERVE ,
638 inclusive.
639 The section header table does not contain entries for the
640 reserved indices.
641 .El
642 .Pp
643 The section header has the following structure:
644 .Bd -literal -offset indent
645 typedef struct {
646         Elf32_Word      sh_name;
647         Elf32_Word      sh_type;
648         Elf32_Word      sh_flags;
649         Elf32_Addr      sh_addr;
650         Elf32_Off       sh_offset;
651         Elf32_Word      sh_size;
652         Elf32_Word      sh_link;
653         Elf32_Word      sh_info;
654         Elf32_Word      sh_addralign;
655         Elf32_Word      sh_entsize;
656 } Elf32_Shdr;
657 .Ed
658 .Bd -literal -offset indent
659 typedef struct {
660         Elf64_Word      sh_name;
661         Elf64_Word      sh_type;
662         Elf64_Xword     sh_flags;
663         Elf64_Addr      sh_addr;
664         Elf64_Off       sh_offset;
665         Elf64_Xword     sh_size;
666         Elf64_Word      sh_link;
667         Elf64_Word      sh_info;
668         Elf64_Xword     sh_addralign;
669         Elf64_Xword     sh_entsize;
670 } Elf64_Shdr;
671 .Ed
672 .Pp
673 .Bl -tag -width "sh_addralign" -compact
674 .It Dv sh_name
675 This member specifies the name of the section.
676 Its value is an index
677 into the section header string table section, giving the location of
678 a null-terminated string.
679 .It Dv sh_type
680 This member categorizes the section's contents and semantics.
681 .Pp
682 .Bl -tag -width "SHT_PROGBITS" -compact
683 .It Dv SHT_NULL
684 This value marks the section header as inactive.
685 It does not
686 have an associated section.
687 Other members of the section header
688 have undefined values.
689 .It Dv SHT_PROGBITS
690 The section holds information defined by the program, whose
691 format and meaning are determined solely by the program.
692 .It Dv SHT_SYMTAB
693 This section holds a symbol table.
694 Typically,
695 .Sy SHT_SYMTAB
696 provides symbols for link editing, though it may also be used
697 for dynamic linking.
698 As a complete symbol table, it may contain
699 many symbols unnecessary for dynamic linking.
700 An object file can
701 also contain a
702 .Sy SHN_DYNSYM
703 section.
704 .It Dv SHT_STRTAB
705 This section holds a string table.
706 An object file may have multiple
707 string table sections.
708 .It Dv SHT_RELA
709 This section holds relocation entries with explicit addends, such
710 as type
711 .Sy Elf32_Rela
712 for the 32-bit class of object files.
713 An object may have multiple
714 relocation sections.
715 .It Dv SHT_HASH
716 This section holds a symbol hash table.
717 All object participating in
718 dynamic linking must contain a symbol hash table.
719 An object file may
720 have only one hash table.
721 .It Dv SHT_DYNAMIC
722 This section holds information for dynamic linking.
723 An object file may
724 have only one dynamic section.
725 .It Dv SHT_NOTE
726 This section holds information that marks the file in some way.
727 .It Dv SHT_NOBITS
728 A section of this type occupies no space in the file but otherwise
729 resembles
730 .Sy SHN_PROGBITS .
731 Although this section contains no bytes, the
732 .Sy sh_offset
733 member contains the conceptual file offset.
734 .It Dv SHT_REL
735 This section holds relocation offsets without explicit addends, such
736 as type
737 .Sy Elf32_Rel
738 for the 32-bit class of object files.
739 An object file may have multiple
740 relocation sections.
741 .It Dv SHT_SHLIB
742 This section is reserved but has unspecified semantics.
743 .It Dv SHT_DYNSYM
744 This section holds a minimal set of dynamic linking symbols.
745 An
746 object file can also contain a
747 .Sy SHN_SYMTAB
748 section.
749 .It Dv SHT_LOPROC
750 This value up to and including
751 .Sy SHT_HIPROC
752 are reserved for processor-specific semantics.
753 .It Dv SHT_HIPROC
754 This value down to and including
755 .Sy SHT_LOPROC
756 are reserved for processor-specific semantics.
757 .It Dv SHT_LOUSER
758 This value specifies the lower bound of the range of indices reserved for
759 application programs.
760 .It Dv SHT_HIUSER
761 This value specifies the upper bound of the range of indices reserved for
762 application programs.
763 Section types between
764 .Sy SHT_LOUSER
765 and
766 .Sy SHT_HIUSER
767 may be used by the application, without conflicting with current or future
768 system-defined section types.
769 .El
770 .Pp
771 .It Dv sh_flags
772 Sections support one-bit flags that describe miscellaneous attributes.
773 If a flag bit is set in
774 .Sy sh_flags ,
775 the attribute is
776 .Dq on
777 for the section.
778 Otherwise, the attribute is
779 .Dq off
780 or does not apply.
781 Undefined attributes are set to zero.
782 .Pp
783 .Bl -tag -width "SHF_EXECINSTR" -compact
784 .It Dv SHF_WRITE
785 This section contains data that should be writable during process
786 execution.
787 .It Dv SHF_ALLOC
788 The section occupies memory during process execution.
789 Some control
790 sections do not reside in the memory image of an object file.
791 This
792 attribute is off for those sections.
793 .It Dv SHF_EXECINSTR
794 The section contains executable machine instructions.
795 .It Dv SHF_MASKPROC
796 All bits included in this mask are reserved for processor-specific
797 semantics.
798 .El
799 .Pp
800 .It Dv sh_addr
801 If the section will appear in the memory image of a process, this member
802 holds the address at which the section's first byte should reside.
803 Otherwise, the member contains zero.
804 .It Dv sh_offset
805 This member's value holds the byte offset from the beginning of the file
806 to the first byte in the section.
807 One section type,
808 .Sy SHT_NOBITS ,
809 occupies no space in the file, and its
810 .Sy sh_offset
811 member locates the conceptual placement in the file.
812 .It Dv sh_size
813 This member holds the section's size in bytes.
814 Unless the section type
815 is
816 .Sy SHT_NOBITS ,
817 the section occupies
818 .Sy sh_size
819 bytes in the file.
820 A section of type
821 .Sy SHT_NOBITS
822 may have a non-zero size, but it occupies no space in the file.
823 .It Dv sh_link
824 This member holds a section header table index link, whose interpretation
825 depends on the section type.
826 .It Dv sh_info
827 This member holds extra information, whose interpretation depends on the
828 section type.
829 .It Dv sh_addralign
830 Some sections have address alignment constraints.
831 If a section holds a
832 doubleword, the system must ensure doubleword alignment for the entire
833 section.
834 That is, the value of
835 .Sy sh_addr
836 must be congruent to zero, modulo the value of
837 .Sy sh_addralign .
838 Only zero and positive integral powers of two are allowed.
839 Values of zero
840 or one mean the section has no alignment constraints.
841 .It Dv sh_entsize
842 Some sections hold a table of fixed-sized entries, such as a symbol table.
843 For such a section, this member gives the size in bytes for each entry.
844 This member contains zero if the section does not hold a table of
845 fixed-size entries.
846 .El
847 .Pp
848 Various sections hold program and control information:
849 .Bl -tag -width ".shstrtab" -compact
850 .It .bss
851 (Block Started by Symbol)
852 This section holds uninitialized data that contributes to the program's
853 memory image.
854 By definition, the system initializes the data with zeros
855 when the program begins to run.
856 This section is of type
857 .Sy SHT_NOBITS .
858 The attributes types are
859 .Sy SHF_ALLOC
860 and
861 .Sy SHF_WRITE .
862 .It .comment
863 This section holds version control information.
864 This section is of type
865 .Sy SHT_PROGBITS .
866 No attribute types are used.
867 .It .data
868 This section holds initialized data that contribute to the program's
869 memory image.
870 This section is of type
871 .Sy SHT_PROGBITS .
872 The attribute types are
873 .Sy SHF_ALLOC
874 and
875 .Sy SHF_WRITE .
876 .It .data1
877 This section holds initialized data that contribute to the program's
878 memory image.
879 This section is of type
880 .Sy SHT_PROGBITS .
881 The attribute types are
882 .Sy SHF_ALLOC
883 and
884 .Sy SHF_WRITE .
885 .It .debug
886 This section holds information for symbolic debugging.
887 The contents
888 are unspecified.
889 This section is of type
890 .Sy SHT_PROGBITS .
891 No attribute types are used.
892 .It .dynamic
893 This section holds dynamic linking information.
894 The section's attributes
895 will include the
896 .Sy SHF_ALLOC
897 bit.
898 Whether the
899 .Sy SHF_WRITE
900 bit is set is processor-specific.
901 This section is of type
902 .Sy SHT_DYNAMIC .
903 See the attributes above.
904 .It .dynstr
905 This section holds strings needed for dynamic linking, most commonly
906 the strings that represent the names associated with symbol table entries.
907 This section is of type
908 .Sy SHT_STRTAB .
909 The attribute type used is
910 .Sy SHF_ALLOC .
911 .It .dynsym
912 This section holds the dynamic linking symbol table.
913 This section is of type
914 .Sy SHT_DYNSYM .
915 The attribute used is
916 .Sy SHF_ALLOC .
917 .It .fini
918 This section holds executable instructions that contribute to the process
919 termination code.
920 When a program exits normally the system arranges to
921 execute the code in this section.
922 This section is of type
923 .Sy SHT_PROGBITS .
924 The attributes used are
925 .Sy SHF_ALLOC
926 and
927 .Sy SHF_EXECINSTR .
928 .It .got
929 This section holds the global offset table.
930 This section is of type
931 .Sy SHT_PROGBITS .
932 The attributes are processor-specific.
933 .It .hash
934 This section holds a symbol hash table.
935 This section is of type
936 .Sy SHT_HASH .
937 The attribute used is
938 .Sy SHF_ALLOC .
939 .It .init
940 This section holds executable instructions that contribute to the process
941 initialization code.
942 When a program starts to run the system arranges to
943 execute the code in this section before calling the main program entry point.
944 This section is of type
945 .Sy SHT_PROGBITS .
946 The attributes used are
947 .Sy SHF_ALLOC
948 and
949 .Sy SHF_EXECINSTR .
950 .It .interp
951 This section holds the pathname of a program interpreter.
952 If the file has
953 a loadable segment that includes the section, the section's attributes will
954 include the
955 .Sy SHF_ALLOC
956 bit.
957 Otherwise, that bit will be off.
958 This section is of type
959 .Sy SHT_PROGBITS .
960 .It .line
961 This section holds line number information for symbolic debugging, which
962 describes the correspondence between the program source and the machine code.
963 The contents are unspecified.
964 This section is of type
965 .Sy SHT_PROGBITS .
966 No attribute types are used.
967 .It .note
968 This section holds information in the
969 .Dq Note Section
970 format described below.
971 This section is of type
972 .Sy SHT_NOTE .
973 No attribute types are used.
974 .It .plt
975 This section holds the procedure linkage table.
976 This section is of type
977 .Sy SHT_PROGBITS .
978 The attributes are processor-specific.
979 .It .relNAME
980 This section holds relocation information as described below.
981 If the file
982 has a loadable segment that includes relocation, the section's attributes
983 will include the
984 .Sy SHF_ALLOC
985 bit.
986 Otherwise the bit will be off.
987 By convention,
988 .Dq NAME
989 is supplied by the section to which the relocations apply.
990 Thus a relocation
991 section for
992 .Sy .text
993 normally would have the name
994 .Sy .rel.text .
995 This section is of type
996 .Sy SHT_REL .
997 .It .relaNAME
998 This section holds relocation information as described below.
999 If the file
1000 has a loadable segment that includes relocation, the section's attributes
1001 will include the
1002 .Sy SHF_ALLOC
1003 bit.
1004 Otherwise the bit will be off.
1005 By convention,
1006 .Dq NAME
1007 is supplied by the section to which the relocations apply.
1008 Thus a relocation
1009 section for
1010 .Sy .text
1011 normally would have the name
1012 .Sy .rela.text .
1013 This section is of type
1014 .Sy SHT_RELA .
1015 .It .rodata
1016 This section holds read-only data that typically contributes to a
1017 non-writable segment in the process image.
1018 This section is of type
1019 .Sy SHT_PROGBITS .
1020 The attribute used is
1021 .Sy SHF_ALLOC .
1022 .It .rodata1
1023 This section hold read-only data that typically contributes to a
1024 non-writable segment in the process image.
1025 This section is of type
1026 .Sy SHT_PROGBITS .
1027 The attribute used is
1028 .Sy SHF_ALLOC .
1029 .It .shstrtab
1030 This section holds section names.
1031 This section is of type
1032 .Sy SHT_STRTAB .
1033 No attribute types are used.
1034 .It .strtab
1035 This section holds strings, most commonly the strings that represent the
1036 names associated with symbol table entries.
1037 If the file has a loadable
1038 segment that includes the symbol string table, the section's attributes
1039 will include the
1040 .Sy SHF_ALLOC
1041 bit.
1042 Otherwise the bit will be off.
1043 This section is of type
1044 .Sy SHT_STRTAB .
1045 .It .symtab
1046 This section holds a symbol table.
1047 If the file has a loadable segment
1048 that includes the symbol table, the section's attributes will include
1049 the
1050 .Sy SHF_ALLOC
1051 bit.
1052 Otherwise the bit will be off.
1053 This section is of type
1054 .Sy SHT_SYMTAB .
1055 .It .text
1056 This section holds the
1057 .Dq text ,
1058 or executable instructions, of a program.
1059 This section is of type
1060 .Sy SHT_PROGBITS .
1061 The attributes used are
1062 .Sy SHF_ALLOC
1063 and
1064 .Sy SHF_EXECINSTR .
1065 .It .jcr
1066 This section holds information about Java classes that must
1067 be registered.
1068 .It .eh_frame
1069 This section holds information used for C++ exception-handling.
1070 .El
1071 .Pp
1072 String table sections hold null-terminated character sequences, commonly
1073 called strings.
1074 The object file uses these strings to represent symbol
1075 and section names.
1076 One references a string as an index into the string
1077 table section.
1078 The first byte, which is index zero, is defined to hold
1079 a null character.
1080 Similarly, a string table's last byte is defined to
1081 hold a null character, ensuring null termination for all strings.
1082 .Pp
1083 An object file's symbol table holds information needed to locate and
1084 relocate a program's symbolic definitions and references.
1085 A symbol table
1086 index is a subscript into this array.
1087 .Bd -literal -offset indent
1088 typedef struct {
1089         Elf32_Word      st_name;
1090         Elf32_Addr      st_value;
1091         Elf32_Word      st_size;
1092         unsigned char   st_info;
1093         unsigned char   st_other;
1094         Elf32_Half      st_shndx;
1095 } Elf32_Sym;
1096 .Ed
1097 .Bd -literal -offset indent
1098 typedef struct {
1099         Elf64_Word      st_name;
1100         unsigned char   st_info;
1101         unsigned char   st_other;
1102         Elf64_Half      st_shndx;
1103         Elf64_Addr      st_value;
1104         Elf64_Xword     st_size;
1105 } Elf64_Sym;
1106 .Ed
1107 .Pp
1108 .Bl -tag -width "st_value" -compact
1109 .It Dv st_name
1110 This member holds an index into the object file's symbol string table,
1111 which holds character representations of the symbol names.
1112 If the value
1113 is non-zero, it represents a string table index that gives the symbol
1114 name.
1115 Otherwise, the symbol table has no name.
1116 .It Dv st_value
1117 This member gives the value of the associated symbol.
1118 .It Dv st_size
1119 Many symbols have associated sizes.
1120 This member holds zero if the symbol
1121 has no size or an unknown size.
1122 .It Dv st_info
1123 This member specifies the symbol's type and binding attributes:
1124 .Pp
1125 .Bl -tag -width "STT_SECTION" -compact
1126 .It Dv STT_NOTYPE
1127 The symbol's type is not defined.
1128 .It Dv STT_OBJECT
1129 The symbol is associated with a data object.
1130 .It Dv STT_FUNC
1131 The symbol is associated with a function or other executable code.
1132 .It Dv STT_SECTION
1133 The symbol is associated with a section.
1134 Symbol table entries of
1135 this type exist primarily for relocation and normally have
1136 .Sy STB_LOCAL
1137 bindings.
1138 .It Dv STT_FILE
1139 By convention the symbol's name gives the name of the source file
1140 associated with the object file.
1141 A file symbol has
1142 .Sy STB_LOCAL
1143 bindings, its section index is
1144 .Sy SHN_ABS ,
1145 and it precedes the other
1146 .Sy STB_LOCAL
1147 symbols of the file, if it is present.
1148 .It Dv STT_LOPROC
1149 This value up to and including
1150 .Sy STT_HIPROC
1151 are reserved for processor-specific semantics.
1152 .It Dv STT_HIPROC
1153 This value down to and including
1154 .Sy STT_LOPROC
1155 are reserved for processor-specific semantics.
1156 .El
1157 .Pp
1158 .Bl -tag -width "STB_GLOBAL" -compact
1159 .It Dv STB_LOCAL
1160 Local symbols are not visible outside the object file containing their
1161 definition.
1162 Local symbols of the same name may exist in multiple file
1163 without interfering with each other.
1164 .It Dv STB_GLOBAL
1165 Global symbols are visible to all object files being combined.
1166 One file's
1167 definition of a global symbol will satisfy another file's undefined
1168 reference to the same symbol.
1169 .It Dv STB_WEAK
1170 Weak symbols resemble global symbols, but their definitions have lower
1171 precedence.
1172 .It Dv STB_LOPROC
1173 This value up to and including
1174 .Sy STB_HIPROC
1175 are reserved for processor-specific semantics.
1176 .It Dv STB_HIPROC
1177 This value down to and including
1178 .Sy STB_LOPROC
1179 are reserved for processor-specific semantics.
1180 .Pp
1181 There are macros for packing and unpacking the binding and type fields:
1182 .Pp
1183 .Bl -tag -width "ELF32_ST_INFO(bind, type)" -compact
1184 .It Xo
1185 .Fn ELF32_ST_BIND info
1186 .Xc
1187 or
1188 .Fn ELF64_ST_BIND info
1189 extract a binding from an st_info value.
1190 .It Xo
1191 .Fn ELF64_ST_TYPE info
1192 .Xc
1193 or
1194 .Fn ELF32_ST_TYPE info
1195 extract a type from an st_info value.
1196 .It Xo
1197 .Fn ELF32_ST_INFO bind type
1198 .Xc
1199 or
1200 .Fn ELF64_ST_INFO bind type
1201 convert a binding and a type into an st_info value.
1202 .El
1203 .El
1204 .Pp
1205 .It Dv st_other
1206 This member currently holds zero and has no defined meaning.
1207 .It Dv st_shndx
1208 Every symbol table entry is
1209 .Dq defined
1210 in relation to some section.
1211 This member holds the relevant section
1212 header table index.
1213 .El
1214 .Pp
1215 Relocation is the process of connecting symbolic references with
1216 symbolic definitions.
1217 Relocatable files must have information that
1218 describes how to modify their section contents, thus allowing executable
1219 and shared object files to hold the right information for a process'
1220 program image.
1221 Relocation entries are these data.
1222 .Pp
1223 Relocation structures that do not need an addend:
1224 .Bd -literal -offset indent
1225 typedef struct {
1226         Elf32_Addr      r_offset;
1227         Elf32_Word      r_info;
1228 } Elf32_Rel;
1229 .Ed
1230 .Bd -literal -offset indent
1231 typedef struct {
1232         Elf64_Addr      r_offset;
1233         Elf64_Xword     r_info;
1234 } Elf64_Rel;
1235 .Ed
1236 .Pp
1237 Relocation structures that need an addend:
1238 .Bd -literal -offset indent
1239 typedef struct {
1240         Elf32_Addr      r_offset;
1241         Elf32_Word      r_info;
1242         Elf32_Sword     r_addend;
1243 } Elf32_Rela;
1244 .Ed
1245 .Bd -literal -offset indent
1246 typedef struct {
1247         Elf64_Addr      r_offset;
1248         Elf64_Xword     r_info;
1249         Elf64_Sxword    r_addend;
1250 } Elf64_Rela;
1251 .Ed
1252 .Pp
1253 .Bl -tag -width "r_offset" -compact
1254 .It Dv r_offset
1255 This member gives the location at which to apply the relocation action.
1256 For a relocatable file, the value is the byte offset from the beginning
1257 of the section to the storage unit affected by the relocation.
1258 For an
1259 executable file or shared object, the value is the virtual address of
1260 the storage unit affected by the relocation.
1261 .It Dv r_info
1262 This member gives both the symbol table index with respect to which the
1263 relocation must be made and the type of relocation to apply.
1264 Relocation
1265 types are processor-specific.
1266 When the text refers to a relocation
1267 entry's relocation type or symbol table index, it means the result of
1268 applying
1269 .Sy ELF_[32|64]_R_TYPE
1270 or
1271 .Sy ELF[32|64]_R_SYM ,
1272 respectively to the entry's
1273 .Sy r_info
1274 member.
1275 .It Dv r_addend
1276 This member specifies a constant addend used to compute the value to be
1277 stored into the relocatable field.
1278 .El
1279 .Sh SEE ALSO
1280 .Xr as 1 ,
1281 .Xr gdb 1 ,
1282 .Xr ld 1 ,
1283 .Xr objdump 1 ,
1284 .Xr execve 2 ,
1285 .Xr ar 5 ,
1286 .Xr core 5
1287 .Rs
1288 .%A Hewlett Packard
1289 .%B Elf-64 Object File Format
1290 .Re
1291 .Rs
1292 .%A Santa Cruz Operation
1293 .%B System V Application Binary Interface
1294 .Re
1295 .Rs
1296 .%A Unix System Laboratories
1297 .%T Object Files
1298 .%B "Executable and Linking Format (ELF)"
1299 .Re
1300 .Sh HISTORY
1301 The ELF header files made their appearance in
1302 .Fx 2.2.6 .
1303 ELF in itself first appeared in
1304 .At V .
1305 The ELF format is an adopted standard.
1306 .Sh AUTHORS
1307 This manual page was written by
1308 .An Jeroen Ruigrok van der Werven
1309 .Aq asmodai@FreeBSD.org
1310 with inspiration from BSDi's
1311 .Bsx
1312 .Xr elf 5
1313 manpage.