]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/man/man5/elf.5
mdoc(7) police: s;BSD/OS;.Bsx; where appropriate.
[FreeBSD/FreeBSD.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 July 31, 1999
28 .Dt ELF 5
29 .Os
30 .Sh NAME
31 .Nm elf
32 .Nd format of ELF executable binary files
33 .Sh SYNOPSIS
34 .Fd #include <elf.h>
35 .Sh DESCRIPTION
36 The header file
37 .Aq Pa 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 .Pa 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 .Pa sys/elf32.h
67 and
68 .Pa sys/elf64.h
69 instead of
70 .Pa 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 .Pa sys/elf_common.h
82 as well as
83 .Pa 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 program address
92 Elf32_Half      Unsigned halfword field
93 Elf32_Off       Unsigned file offset
94 Elf32_Sword     Signed large integer
95 Elf32_Word      Field or unsigned large integer
96 Elf32_Size      Unsigned object size
97 .Ed
98 .Pp
99 For 64-bit architectures we have the following types:
100 .Bd -literal -offset indent
101 Elf64_Addr      Unsigned program address
102 Elf64_Half      Unsigned halfword field
103 Elf64_Off       Unsigned file offset
104 Elf64_Sword     Signed large integer
105 Elf64_Word      Field or unsigned large integer
106 Elf64_Size      Unsigned object size
107 Elf64_Quarter   Unsigned quarterword field
108 .Ed
109 .Pp
110 All data structures that the file format defines follow the
111 .Dq natural
112 size and alignment guidelines for the relevant class.
113 If necessary,
114 data structures contain explicit padding to ensure 4-byte alignment
115 for 4-byte objects, to force structure sizes to a multiple of 4, etc.
116 .Pp
117 The ELF header is described by the type Elf32_Ehdr or Elf64_Ehdr:
118 .Bd -literal -offset indent
119 typedef struct {
120         unsigned char   e_ident[EI_NIDENT];
121         Elf32_Half      e_type;
122         Elf32_Half      e_machine;
123         Elf32_Word      e_version;
124         Elf32_Addr      e_entry;
125         Elf32_Off       e_phoff;
126         Elf32_Off       e_shoff;
127         Elf32_Word      e_flags;
128         Elf32_Half      e_ehsize;
129         Elf32_Half      e_phentsize;
130         Elf32_Half      e_phnum;
131         Elf32_Half      e_shentsize;
132         Elf32_Half      e_shnum;
133         Elf32_Half      e_shstrndx;
134 } Elf32_Ehdr;
135 .Ed
136 .Pp
137 .Bd -literal -offset indent
138 typedef struct {
139         unsigned char   e_ident[EI_NIDENT];
140         Elf64_Quarter   e_type;
141         Elf64_Quarter   e_machine;
142         Elf64_Half      e_version;
143         Elf64_Addr      e_entry;
144         Elf64_Off       e_phoff;
145         Elf64_Off       e_shoff;
146         Elf64_Half      e_flags;
147         Elf64_Quarter   e_ehsize;
148         Elf64_Quarter   e_phentsize;
149         Elf64_Quarter   e_phnum;
150         Elf64_Quarter   e_shentsize;
151         Elf64_Quarter   e_shnum;
152         Elf64_Quarter   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'. Currently no flags have been defined.
355 .It Dv e_ehsize
356 This member holds the ELF header's size in bytes.
357 .It Dv e_phentsize
358 This member holds the size in bytes of one entry in the file's program header
359 table; all entries are the same size.
360 .It Dv e_phnum
361 This member holds the number of entries in the program header
362 table.
363 Thus the product of
364 .Sy e_phentsize
365 and
366 .Sy e_phnum
367 gives the table's size
368 in bytes.
369 If a file has no program header,
370 .Sy e_phnum
371 holds the value zero.
372 .It Dv e_shentsize
373 This member holds a sections header's size in bytes.
374 A section header is one
375 entry in the section header table; all entries are the same size.
376 .It Dv e_shnum
377 This member holds the number of entries in the section header table.
378 Thus
379 the product of
380 .Sy e_shentsize
381 and
382 .Sy e_shnum
383 gives the section header table's size in bytes.
384 If a file has no section
385 header table,
386 .Sy e_shnum
387 holds the value of zero.
388 .It Dv e_shstrndx
389 This member holds the section header table index of the entry associated
390 with the section name string table.
391 If the file has no section name string
392 table, this member holds the value
393 .Sy SHN_UNDEF .
394 .Pp
395 .Bl -tag -width "SHN_LORESERVE" -compact
396 .It Dv SHN_UNDEF
397 This value marks an undefined, missing, irrelevant, or otherwise meaningless
398 section reference.
399 For example, a symbol
400 .Dq defined
401 relative to section number
402 .Sy SHN_UNDEF
403 is an undefined symbol.
404 .It Dv SHN_LORESERVE
405 This value specifies the lower bound of the range of reserved indexes.
406 .It Dv SHN_LOPROC
407 This value up to and including
408 .Sy SHN_HIPROC
409 are reserved for processor-specific semantics.
410 .It Dv SHN_HIPROC
411 This value down to and including
412 .Sy SHN_LOPROC
413 are reserved for processor-specific semantics.
414 .It Dv SHN_ABS
415 This value specifies absolute values for the corresponding reference.
416 For
417 example, symbols defined relative to section number
418 .Sy SHN_ABS
419 have absolute values and are not affected by relocation.
420 .It Dv SHN_COMMON
421 Symbols defined relative to this section are common symbols, such as Fortran
422 COMMON or unallocated C external variables.
423 .It Dv SHN_HIRESERVE
424 This value specifies the upper bound of the range of the range of reserved
425 indices between
426 .Sy SHN_LORESERVE
427 and
428 .Sy SHN_HIRESERVE ,
429 inclusive; the values do
430 not reference the section header table.
431 That is, the section header table
432 does
433 .Em not
434 contain entries for the reserved indices.
435 .El
436 .El
437 .Pp
438 An executable or shared object file's program header table is an array of
439 structures, each describing a segment or other information the system needs
440 to prepare the program for execution.
441 An object file
442 .Em segment
443 contains one or more
444 .Em sections .
445 Program headers are meaningful only for executable and shared object files.
446 A file specifies its own program header size with the ELF header's
447 .Sy e_phentsize
448 and
449 .Sy e_phnum
450 members.
451 As with the Elf executable header, the program header
452 also has different versions depending on the architecture:
453 .Pp
454 .Bd -literal -offset indent
455 typedef struct {
456         Elf32_Word      p_type;
457         Elf32_Off       p_offset;
458         Elf32_Addr      p_vaddr;
459         Elf32_Addr      p_paddr;
460         Elf32_Size      p_filesz;
461         Elf32_Size      p_memsz;
462         Elf32_Word      p_flags;
463         Elf32_Size      p_align;
464 } Elf32_Phdr;
465 .Ed
466 .Pp
467 .Bd -literal -offset indent
468 typedef struct {
469         Elf64_Half      p_type;
470         Elf64_Half      p_flags;
471         Elf64_Off       p_offset;
472         Elf64_Addr      p_vaddr;
473         Elf64_Addr      p_paddr;
474         Elf64_Size      p_filesz;
475         Elf64_Size      p_memsz;
476         Elf64_Size      p_align;
477 } Elf64_Phdr;
478 .Ed
479 .Pp
480 The main difference between the 32-bit and the 64-bit program header lies
481 only in the location of a
482 .Sy p_flags
483 member in the total struct.
484 .Pp
485 .Bl -tag -width "p_offset" -compact -offset indent
486 .It Dv p_type
487 This member of the Phdr struct tells what kind of segment this array
488 element describes or how to interpret the array element's information.
489 .Bl -tag -width "PT_DYNAMIC" -compact
490 .Pp
491 .It Dv PT_NULL
492 The array element is unused and the other members' values are undefined.
493 This lets the program header have ignored entries.
494 .It Dv PT_LOAD
495 The array element specifies a loadable segment, described by
496 .Sy p_filesz
497 and
498 .Sy p_memsz .
499 The bytes from the file are mapped to the beginning of the memory
500 segment.
501 If the segment's memory size
502 .Pq Sy p_memsz
503 is larger than the file size
504 .Pq Sy p_filesz ,
505 the
506 .Dq extra
507 bytes are defined to hold the value 0 and to follow the segment's
508 initialized area.
509 The file size may not be larger than the memory size.
510 Loadable segment entries in the program header table appear in ascending
511 order, sorted on the
512 .Sy p_vaddr
513 member.
514 .It Dv PT_DYNAMIC
515 The array element specifies dynamic linking information.
516 .It Dv PT_INTERP
517 The array element specifies the location and size of a null-terminated
518 path name to invoke as an interpreter.
519 This segment type is meaningful
520 only for executable files (though it may occur for shared objects). However
521 it may not occur more than once in a file.
522 If it is present it must precede
523 any loadable segment entry.
524 .It Dv PT_NOTE
525 The array element specifies the location and size for auxiliary information.
526 .It Dv PT_SHLIB
527 This segment type is reserved but has unspecified semantics.
528 Programs that
529 contain an array element of this type do not conform to the ABI.
530 .It Dv PT_PHDR
531 The array element, if present, specifies the location and size of the program
532 header table itself, both in the file and in the memory image of the program.
533 This segment type may not occur more than once in a file.
534 Moreover, it may
535 only occur if the program header table is part of the memory image of the
536 program.
537 If it is present it must precede any loadable segment entry.
538 .It Dv PT_LOPROC
539 This value up to and including
540 .Sy PT_HIPROC
541 are reserved for processor-specific semantics.
542 .It Dv PT_HIPROC
543 This value down to and including
544 .Sy PT_LOPROC
545 are reserved for processor-specific semantics.
546 .El
547 .Pp
548 .It Dv p_offset
549 This member holds the offset from the beginning of the file at which
550 the first byte of the of the segment resides.
551 .It Dv p_vaddr
552 This member holds the virtual address at which the first byte of the
553 segment resides in memory.
554 .It Dv p_paddr
555 On systems for which physical addressing is relevant, this member is
556 reserved for the segment's physical address.
557 Under BSD this member is
558 not used and must be zero.
559 .It Dv p_filesz
560 This member holds the number of bytes in the file image of the segment.
561 It may be zero.
562 .It Dv p_memsz
563 This member holds the number of bytes in the memory image of the segment.
564 It may be zero.
565 .It Dv p_flags
566 This member holds flags relevant to the segment:
567 .Pp
568 .Bl -tag -width "PF_X" -compact
569 .It Dv PF_X
570 An executable segment.
571 .It Dv PF_W
572 A writable segment.
573 .It Dv PF_R
574 A readable segment.
575 .El
576 .Pp
577 A text segment commonly has the flags
578 .Sy PF_X
579 and
580 .Sy PF_R .
581 A data segment commonly has
582 .Sy PF_X ,
583 .Sy PF_W
584 and
585 .Sy PF_R .
586 .It Dv p_align
587 This member holds the value to which the segments are aligned in memory
588 and in the file.
589 Loadable process segments must have congruent values for
590 .Sy p_vaddr
591 and
592 .Sy p_offset ,
593 modulo the page size.
594 Values of zero and one mean no alignment is required.
595 Otherwise,
596 .Sy p_align
597 should be a positive, integral power of two, and
598 .Sy p_vaddr
599 should equal
600 .Sy p_offset ,
601 modulo
602 .Sy p_align .
603 .El
604 .Pp
605 An file's section header table lets one locate all the file's sections.
606 The
607 section header table is an array of Elf32_Shdr or Elf64_Shdr structures.
608 The
609 ELF header's
610 .Sy e_shoff
611 member gives the byte offset from the beginning of the file to the section
612 header table.
613 .Sy e_shnum
614 holds the number of entries the section header table contains.
615 .Sy e_shentsize
616 holds the size in bytes of each entry.
617 .Pp
618 A section header table index is a subscript into this array.
619 Some section
620 header table indices are reserved.
621 An object file does not have sections for
622 these special indices:
623 .Pp
624 .Bl -tag -width "SHN_LORESERVE" -compact
625 .It Dv SHN_UNDEF
626 This value marks an undefined, missing, irrelevant or otherwise meaningless
627 section reference.
628 .It Dv SHN_LORESERVE
629 This value specifies the lower bound of the range of reserved indices.
630 .It Dv SHN_LOPROC
631 This value up to and including
632 .Sy SHN_HIPROC
633 are reserved for processor-specific semantics.
634 .It Dv SHN_HIPROC
635 This value down to and including
636 .Sy SHN_LOPROC
637 are reserved for processor-specific semantics.
638 .It Dv SHN_ABS
639 This value specifies absolute values for the corresponding reference.
640 For
641 example, symbols defined relative to section number
642 .Sy SHN_ABS
643 have absolute values and are not affected by relocation.
644 .It Dv SHN_COMMON
645 Symbols defined relative to this section are common symbols, such as FORTRAN
646 COMMON or unallocated C external variables.
647 .It Dv SHN_HIRESERVE
648 This value specifies the upper bound of the range of reserved indices.
649 The
650 system reserves indices between
651 .Sy SHN_LORESERVE
652 and
653 .Sy SHN_HIRESERVE ,
654 inclusive.
655 The section header table does not contain entries for the
656 reserved indices.
657 .El
658 .Pp
659 The section header has the following structure:
660 .Bd -literal -offset indent
661 typedef struct {
662         Elf32_Word      sh_name;
663         Elf32_Word      sh_type;
664         Elf32_Word      sh_flags;
665         Elf32_Addr      sh_addr;
666         Elf32_Off       sh_offset;
667         Elf32_Size      sh_size;
668         Elf32_Word      sh_link;
669         Elf32_Word      sh_info;
670         Elf32_Size      sh_addralign;
671         Elf32_Size      sh_entsize;
672 } Elf32_Shdr;
673 .Ed
674 .Pp
675 .Bd -literal -offset indent
676 typedef struct {
677         Elf64_Half      sh_name;
678         Elf64_Half      sh_type;
679         Elf64_Size      sh_flags;
680         Elf64_Addr      sh_addr;
681         Elf64_Off       sh_offset;
682         Elf64_Size      sh_size;
683         Elf64_Half      sh_link;
684         Elf64_Half      sh_info;
685         Elf64_Size      sh_addralign;
686         Elf64_Size      sh_entsize;
687 } Elf64_Shdr;
688 .Ed
689 .Pp
690 .Bl -tag -width "sh_addralign" -compact
691 .It Dv sh_name
692 This member specifies the name of the section.
693 Its value is an index
694 into the section header string table section, giving the location of
695 a null-terminated string.
696 .It Dv sh_type
697 This member categorizes the section's contents and semantics.
698 .Pp
699 .Bl -tag -width "SHT_PROGBITS" -compact
700 .It Dv SHT_NULL
701 This value marks the section header as inactive.
702 It does not
703 have an associated section.
704 Other members of the section header
705 have undefined values.
706 .It Dv SHT_PROGBITS
707 The section holds information defined by the program, whose
708 format and meaning are determined solely by the program.
709 .It Dv SHT_SYMTAB
710 This section holds a symbol table.
711 Typically,
712 .Sy SHT_SYMTAB
713 provides symbols for link editing, though it may also be used
714 for dynamic linking.
715 As a complete symbol table, it may contain
716 many symbols unnecessary for dynamic linking.
717 An object file can
718 also contain a
719 .Sy SHN_DYNSYM
720 section.
721 .It Dv SHT_STRTAB
722 This section holds a string table.
723 An object file may have multiple
724 string table sections.
725 .It Dv SHT_RELA
726 This section holds relocation entries with explicit addends, such
727 as type
728 .Sy Elf32_Rela
729 for the 32-bit class of object files.
730 An object may have multiple
731 relocation sections.
732 .It Dv SHT_HASH
733 This section holds a symbol hash table.
734 All object participating in
735 dynamic linking must contain a symbol hash table.
736 An object file may
737 have only one hash table.
738 .It Dv SHT_DYNAMIC
739 This section holds information for dynamic linking.
740 An object file may
741 have only one dynamic section.
742 .It Dv SHT_NOTE
743 This section holds information that marks the file in some way.
744 .It Dv SHT_NOBITS
745 A section of this type occupies no space in the file but otherwise
746 resembles
747 .Sy SHN_PROGBITS .
748 Although this section contains no bytes, the
749 .Sy sh_offset
750 member contains the conceptual file offset.
751 .It Dv SHT_REL
752 This section holds relocation offsets without explicit addends, such
753 as type
754 .Sy Elf32_Rel
755 for the 32-bit class of object files.
756 An object file may have multiple
757 relocation sections.
758 .It Dv SHT_SHLIB
759 This section is reserved but has unspecified semantics.
760 .It Dv SHT_DYNSYM
761 This section holds a minimal set of dynamic linking symbols.
762 An
763 object file can also contain a
764 .Sy SHN_SYMTAB
765 section.
766 .It Dv SHT_LOPROC
767 This value up to and including
768 .Sy SHT_HIPROC
769 are reserved for processor-specific semantics.
770 .It Dv SHT_HIPROC
771 This value down to and including
772 .Sy SHT_LOPROC
773 are reserved for processor-specific semantics.
774 .It Dv SHT_LOUSER
775 This value specifies the lower bound of the range of indices reserved for
776 application programs.
777 .It Dv SHT_HIUSER
778 This value specifies the upper bound of the range of indices reserved for
779 application programs.
780 Section types between
781 .Sy SHT_LOUSER
782 and
783 .Sy SHT_HIUSER
784 may be used by the application, without conflicting with current or future
785 system-defined section types.
786 .El
787 .Pp
788 .It Dv sh_flags
789 Sections support one-bit flags that describe miscellaneous attributes.
790 If a flag bit is set in
791 .Sy sh_flags ,
792 the attribute is
793 .Dq on
794 for the section.
795 Otherwise, the attribute is
796 .Dq off
797 or does not apply.
798 Undefined attributes are set to zero.
799 .Pp
800 .Bl -tag -width "SHF_EXECINSTR" -compact
801 .It Dv SHF_WRITE
802 This section contains data that should be writable during process
803 execution.
804 .It Dv SHF_ALLOC
805 The section occupies memory during process execution.
806 Some control
807 sections do not reside in the memory image of an object file.
808 This
809 attribute is off for those sections.
810 .It Dv SHF_EXECINSTR
811 The section contains executable machine instructions.
812 .It Dv SHF_MASKPROC
813 All bits included in this mask are reserved for processor-specific
814 semantics.
815 .El
816 .Pp
817 .It Dv sh_addr
818 If the section will appear in the memory image of a process, this member
819 holds the address at which the section's first byte should reside.
820 Otherwise, the member contains zero.
821 .It Dv sh_offset
822 This member's value holds the byte offset from the beginning of the file
823 to the first byte in the section.
824 One section type,
825 .Sy SHT_NOBITS ,
826 occupies no space in the file, and its
827 .Sy sh_offset
828 member locates the conceptual placement in the file.
829 .It Dv sh_size
830 This member holds the section's size in bytes.
831 Unless the section type
832 is
833 .Sy SHT_NOBITS ,
834 the section occupies
835 .Sy sh_size
836 bytes in the file.
837 A section of type
838 .Sy SHT_NOBITS
839 may have a non-zero size, but it occupies no space in the file.
840 .It Dv sh_link
841 This member holds a section header table index link, whose interpretation
842 depends on the section type.
843 .It Dv sh_info
844 This member holds extra information, whose interpretation depends on the
845 section type.
846 .It Dv sh_addralign
847 Some sections have address alignment constraints.
848 If a section holds a
849 doubleword, the system must ensure doubleword alignment for the entire
850 section.
851 That is, the value of
852 .Sy sh_addr
853 must be congruent to zero, modulo the value of
854 .Sy sh_addralign .
855 Only zero and positive integral powers of two are allowed.
856 Values of zero
857 or one mean the section has no alignment constraints.
858 .It Dv sh_entsize
859 Some sections hold a table of fixed-sized entries, such as a symbol table.
860 For such a section, this member gives the size in bytes for each entry.
861 This member contains zero if the section does not hold a table of
862 fixed-size entries.
863 .El
864 .Pp
865 Various sections hold program and control information:
866 .Bl -tag -width ".shstrtab" -compact
867 .It .bss
868 This section holds uninitialized data that contributes to the program's
869 memory image.
870 By definition, the system initializes the data with zeros
871 when the program begins to run.
872 This section is of type
873 .Sy SHT_NOBITS .
874 The attributes types are
875 .Sy SHF_ALLOC
876 and
877 .Sy SHF_WRITE .
878 .It .comment
879 This section holds version control information.
880 This section is of type
881 .Sy SHT_PROGBITS .
882 No attribute types are used.
883 .It .data
884 This section holds initialized data that contribute to the program's
885 memory image.
886 This section is of type
887 .Sy SHT_PROGBITS .
888 The attribute types are
889 .Sy SHF_ALLOC
890 and
891 .Sy SHF_WRITE .
892 .It .data1
893 This section holds initialized data that contribute to the program's
894 memory image.
895 This section is of type
896 .Sy SHT_PROGBITS .
897 The attribute types are
898 .Sy SHF_ALLOC
899 and
900 .Sy SHF_WRITE .
901 .It .debug
902 This section holds information for symbolic debugging.
903 The contents
904 are unspecified.
905 This section is of type
906 .Sy SHT_PROGBITS .
907 No attribute types are used.
908 .It .dynamic
909 This section holds dynamic linking information.
910 The section's attributes
911 will include the
912 .Sy SHF_ALLOC
913 bit.
914 Whether the
915 .Sy SHF_WRITE
916 bit is set is processor-specific.
917 This section is of type
918 .Sy SHT_DYNAMIC .
919 See the attributes above.
920 .It .dynstr
921 This section holds strings needed for dynamic linking, most commonly
922 the strings that represent the names associated with symbol table entries.
923 This section is of type
924 .Sy SHT_STRTAB .
925 The attribute type used is
926 .Sy SHF_ALLOC .
927 .It .dynsym
928 This section holds the dynamic linking symbol table.
929 This section is of type
930 .Sy SHT_DYNSYM .
931 The attribute used is
932 .Sy SHF_ALLOC .
933 .It .fini
934 This section holds executable instructions that contribute to the process
935 termination code.
936 When a program exits normally the system arranges to
937 execute the code in this section.
938 This section is of type
939 .Sy SHT_PROGBITS .
940 The attributes used are
941 .Sy SHF_ALLOC
942 and
943 .Sy SHF_EXECINSTR .
944 .It .got
945 This section holds the global offset table.
946 This section is of type
947 .Sy SHT_PROGBITS .
948 The attributes are processor-specific.
949 .It .hash
950 This section holds a symbol hash table.
951 This section is of type
952 .Sy SHT_HASH .
953 The attribute used is
954 .Sy SHF_ALLOC .
955 .It .init
956 This section holds executable instructions that contribute to the process
957 initialization code.
958 When a program starts to run the system arranges to
959 execute the code in this section before calling the main program entry point.
960 This section is of type
961 .Sy SHT_PROGBITS .
962 The attributes used are
963 .Sy SHF_ALLOC
964 and
965 .Sy SHF_EXECINSTR .
966 .It .interp
967 This section holds the pathname of a program interpreter.
968 If the file has
969 a loadable segment that includes the section, the section's attributes will
970 include the
971 .Sy SHF_ALLOC
972 bit.
973 Otherwise, that bit will be off.
974 This section is of type
975 .Sy SHT_PROGBITS .
976 .It .line
977 This section holds line number information for symbolic debugging, which
978 describes the correspondence between the program source and the machine code.
979 The contents are unspecified.
980 This section is of type
981 .Sy SHT_PROGBITS .
982 No attribute types are used.
983 .It .note
984 This section holds information in the
985 .Dq Note Section
986 format described below.
987 This section is of type
988 .Sy SHT_NOTE .
989 No attribute types are used.
990 .It .plt
991 This section holds the procedure linkage table.
992 This section is of type
993 .Sy SHT_PROGBITS .
994 The attributes are processor-specific.
995 .It .relNAME
996 This section holds relocation information as described below.
997 If the file
998 has a loadable segment that includes relocation, the section's attributes
999 will include the
1000 .Sy SHF_ALLOC
1001 bit.
1002 Otherwise the bit will be off.
1003 By convention,
1004 .Dq NAME
1005 is supplied by the section to which the relocations apply.
1006 Thus a relocation
1007 section for
1008 .Sy .text
1009 normally would have the name
1010 .Sy .rel.text .
1011 This section is of type
1012 .Sy SHT_REL .
1013 .It .relaNAME
1014 This section holds relocation information as described below.
1015 If the file
1016 has a loadable segment that includes relocation, the section's attributes
1017 will include the
1018 .Sy SHF_ALLOC
1019 bit.
1020 Otherwise the bit will be off.
1021 By convention,
1022 .Dq NAME
1023 is supplied by the section to which the relocations apply.
1024 Thus a relocation
1025 section for
1026 .Sy .text
1027 normally would have the name
1028 .Sy .rela.text .
1029 This section is of type
1030 .Sy SHT_RELA .
1031 .It .rodata
1032 This section holds read-only data that typically contributes to a
1033 non-writable segment in the process image.
1034 This section is of type
1035 .Sy SHT_PROGBITS .
1036 The attribute used is
1037 .Sy SHF_ALLOC .
1038 .It .rodata1
1039 This section hold read-only data that typically contributes to a
1040 non-writable segment in the process image.
1041 This section is of type
1042 .Sy SHT_PROGBITS .
1043 The attribute used is
1044 .Sy SHF_ALLOC .
1045 .It .shstrtab
1046 This section holds section names.
1047 This section is of type
1048 .Sy SHT_STRTAB .
1049 No attribute types are used.
1050 .It .strtab
1051 This section holds strings, most commonly the strings that represent the
1052 names associated with symbol table entries.
1053 If the file has a loadable
1054 segment that includes the symbol string table, the section's attributes
1055 will include the
1056 .Sy SHF_ALLOC
1057 bit.
1058 Otherwise the bit will be off.
1059 This section is of type
1060 .Sy SHT_STRTAB .
1061 .It .symtab
1062 This section holds a symbol table.
1063 If the file has a loadable segment
1064 that includes the symbol table, the section's attributes will include
1065 the
1066 .Sy SHF_ALLOC
1067 bit.
1068 Otherwise the bit will be off.
1069 This section is of type
1070 .Sy SHT_SYMTAB .
1071 .It .text
1072 This section holds the
1073 .Dq text ,
1074 or executable instructions, of a program.
1075 This section is of type
1076 .Sy SHT_PROGBITS .
1077 The attributes used are
1078 .Sy SHF_ALLOC
1079 and
1080 .Sy SHF_EXECINSTR .
1081 .El
1082 .Pp
1083 String table sections hold null-terminated character sequences, commonly
1084 called strings.
1085 The object file uses these strings to represent symbol
1086 and section names.
1087 One references a string as an index into the string
1088 table section.
1089 The first byte, which is index zero, is defined to hold
1090 a null character.
1091 Similarly, a string table's last byte is defined to
1092 hold a null character, ensuring null termination for all strings.
1093 .Pp
1094 An object file's symbol table holds information needed to locate and
1095 relocate a program's symbolic definitions and references.
1096 A symbol table
1097 index is a subscript into this array.
1098 .Pp
1099 .Bd -literal -offset indent
1100 typedef struct {
1101         Elf32_Word      st_name;
1102         Elf32_Addr      st_value;
1103         Elf32_Size      st_size;
1104         unsigned char   st_info;
1105         unsigned char   st_other;
1106         Elf32_Half      st_shndx;
1107 } Elf32_Sym;
1108 .Ed
1109 .Pp
1110 .Bd -literal -offset indent
1111 typedef struct {
1112         Elf64_Half      st_name;
1113         unsigned char   st_info;
1114         unsigned char   st_other;
1115         Elf64_Quarter   st_shndx;
1116         Elf64_Addr      st_value;
1117         Elf64_Size      st_size;
1118 } Elf64_Sym;
1119 .Ed
1120 .Pp
1121 .Bl -tag -width "st_value" -compact
1122 .It Dv st_name
1123 This member holds an index into the object file's symbol string table,
1124 which holds character representations of the symbol names.
1125 If the value
1126 is non-zero, it represents a string table index that gives the symbol
1127 name.
1128 Otherwise, the symbol table has no name.
1129 .It Dv st_value
1130 This member gives the value of the associated symbol.
1131 .It Dv st_size
1132 Many symbols have associated sizes.
1133 This member holds zero if the symbol
1134 has no size or an unknown size.
1135 .It Dv st_info
1136 This member specifies the symbol's type and binding attributes:
1137 .Pp
1138 .Bl -tag -width "STT_SECTION" -compact
1139 .It Dv STT_NOTYPE
1140 The symbol's type is not defined.
1141 .It Dv STT_OBJECT
1142 The symbol is associated with a data object.
1143 .It Dv STT_FUNC
1144 The symbol is associated with a function or other executable code.
1145 .It Dv STT_SECTION
1146 The symbol is associated with a section.
1147 Symbol table entries of
1148 this type exist primarily for relocation and normally have
1149 .Sy STB_LOCAL
1150 bindings.
1151 .It Dv STT_FILE
1152 By convention the symbol's name gives the name of the source file
1153 associated with the object file.
1154 A file symbol has
1155 .Sy STB_LOCAL
1156 bindings, its section index is
1157 .Sy SHN_ABS ,
1158 and it precedes the other
1159 .Sy STB_LOCAL
1160 symbols of the file, if it is present.
1161 .It Dv STT_LOPROC
1162 This value up to and including
1163 .Sy STT_HIPROC
1164 are reserved for processor-specific semantics.
1165 .It Dv STT_HIPROC
1166 This value down to and including
1167 .Sy STT_LOPROC
1168 are reserved for processor-specific semantics.
1169 .El
1170 .Pp
1171 .Bl -tag -width "STB_GLOBAL" -compact
1172 .It Dv STB_LOCAL
1173 Local symbols are not visible outside the object file containing their
1174 definition.
1175 Local symbols of the same name may exist in multiple file
1176 without interfering with each other.
1177 .It Dv STB_GLOBAL
1178 Global symbols are visible to all object files being combined.
1179 One file's
1180 definition of a global symbol will satisfy another file's undefined
1181 reference to the same symbol.
1182 .It Dv STB_WEAK
1183 Weak symbols resemble global symbols, but their definitions have lower
1184 precedence.
1185 .It Dv STB_LOPROC
1186 This value up to and including
1187 .Sy STB_HIPROC
1188 are reserved for processor-specific semantics.
1189 .It Dv STB_HIPROC
1190 This value down to and including
1191 .Sy STB_LOPROC
1192 are reserved for processor-specific semantics.
1193 .Pp
1194 There are macros for packing and unpacking the binding and type fields:
1195 .Pp
1196 .Bl -tag -width "ELF32_ST_INFO(bind, type)" -compact
1197 .It Xo
1198 .Fn ELF32_ST_BIND info
1199 .Xc
1200 or
1201 .Fn ELF64_ST_BIND info
1202 extract a binding from an st_info value.
1203 .It Xo
1204 .Fn ELF64_ST_TYPE info
1205 .Xc
1206 or
1207 .Fn ELF32_ST_TYPE info
1208 extract a type from an st_info value.
1209 .It Xo
1210 .Fn ELF32_ST_INFO bind type
1211 .Xc
1212 or
1213 .Fn ELF64_ST_INFO bind type
1214 convert a binding and a type into an st_info value.
1215 .El
1216 .El
1217 .Pp
1218 .It Dv st_other
1219 This member currently holds zero and has no defined meaning.
1220 .It Dv st_shndx
1221 Every symbol table entry is
1222 .Dq defined
1223 in relation to some action.
1224 This member holds the relevant section
1225 header table index.
1226 .El
1227 .Pp
1228 Relocation is the process of connecting symbolic references with
1229 symbolic definitions.
1230 Relocatable files must have information that
1231 describes how to modify their section contents, thus allowing executable
1232 and shared object files to hold the right information for a process'
1233 program image.
1234 Relocation entries are these data.
1235 .Pp
1236 Relocation structures that do not need an addend:
1237 .Pp
1238 .Bd -literal -offset indent
1239 typedef struct {
1240         Elf32_Addr      r_offset;
1241         Elf32_Word      r_info;
1242 } Elf32_Rel;
1243 .Ed
1244 .Bd -literal -offset indent
1245 typedef struct {
1246         Elf64_Addr      r_offset;
1247         Elf64_Size      r_info;
1248 } Elf64_Rel;
1249 .Ed
1250 .Pp
1251 Relocation structures that need an addend:
1252 .Pp
1253 .Bd -literal -offset indent
1254 typedef struct {
1255         Elf32_Addr      r_offset;
1256         Elf32_Word      r_info;
1257         Elf32_Sword     r_addend;
1258 } Elf32_Rela;
1259 .Ed
1260 .Bd -literal -offset indent
1261 typedef struct {
1262         Elf64_Addr      r_offset;
1263         Elf64_Size      r_info;
1264         Elf64_Off       r_addend;
1265 } Elf64_Rela;
1266 .Ed
1267 .Pp
1268 .Bl -tag -width "r_offset" -compact
1269 .It Dv r_offset
1270 This member gives the location at which to apply the relocation action.
1271 For a relocatable file, the value is the byte offset from the beginning
1272 of the section to the storage unit affected by the relocation.
1273 For an
1274 executable file or shared object, the value is the virtual address of
1275 the storage unit affected by the relocation.
1276 .It Dv r_info
1277 This member gives both the symbol table index with respect to which the
1278 relocation must be made and the type of relocation to apply.
1279 Relocation
1280 types are processor-specific.
1281 When the text refers to a relocation
1282 entry's relocation type or symbol table index, it means the result of
1283 applying
1284 .Sy ELF_[32|64]_R_TYPE
1285 or
1286 .Sy ELF[32|64]_R_SYM ,
1287 respectively to the entry's
1288 .Sy r_info
1289 member.
1290 .It Dv r_addend
1291 This member specifies a constant addend used to compute the value to be
1292 stored into the relocatable field.
1293 .El
1294 .Sh SEE ALSO
1295 .Xr as 1 ,
1296 .Xr gdb 1 ,
1297 .Xr ld 1 ,
1298 .Xr objdump 1 ,
1299 .Xr execve 2 ,
1300 .Xr core 5
1301 .Rs
1302 .%A Hewlett Packard
1303 .%B Elf-64 Object File Format
1304 .Re
1305 .Rs
1306 .%A Santa Cruz Operation
1307 .%B System V Application Binary Interface
1308 .Re
1309 .Rs
1310 .%A Unix System Laboratories
1311 .%T Object Files
1312 .%B "Executable and Linking Format (ELF)"
1313 .Re
1314 .Sh HISTORY
1315 The ELF header files made their appearance in
1316 .Fx 2.2.6 .
1317 ELF in itself first appeared in
1318 .At V .
1319 The ELF format is an adopted standard.
1320 .Sh AUTHORS
1321 This manual page was written by
1322 .An Jeroen Ruigrok van der Werven
1323 .Aq asmodai@FreeBSD.org
1324 with inspiration from BSDi's
1325 .Bsx
1326 .Xr elf 5
1327 manpage.