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