1ELF(5) Linux Programmer's Manual ELF(5)
2
3
4
6 elf - format of Executable and Linking Format (ELF) files
7
9 #include <elf.h>
10
12 The header file <elf.h> defines the format of ELF executable binary
13 files. Amongst these files are normal executable files, relocatable
14 object files, core files and shared libraries.
15
16 An executable file using the ELF file format consists of an ELF header,
17 followed by a program header table or a section header table, or both.
18 The ELF header is always at offset zero of the file. The program
19 header table and the section header table's offset in the file are
20 defined in the ELF header. The two tables describe the rest of the
21 particularities of the file.
22
23 This header file describes the above mentioned headers as C structures
24 and also includes structures for dynamic sections, relocation sections
25 and symbol tables.
26
27 The following types are used for N-bit architectures (N=32,64, ElfN
28 stands for Elf32 or Elf64, uintN_t stands for uint32_t or uint64_t):
29
30 ElfN_Addr Unsigned program address, uintN_t
31 ElfN_Off Unsigned file offset, uintN_t
32 ElfN_Section Unsigned section index, uint16_t
33 ElfN_Versym Unsigned version symbol information, uint16_t
34 Elf_Byte unsigned char
35 ElfN_Half uint16_t
36 ElfN_Sword int32_t
37 ElfN_Word uint32_t
38 ElfN_Sxword int64_t
39 ElfN_Xword uint64_t
40
41 (Note: The *BSD terminology is a bit different. There Elf64_Half is
42 twice as large as Elf32_Half, and Elf64Quarter is used for uint16_t.
43 In order to avoid confusion these types are replaced by explicit ones
44 in the below.)
45
46 All data structures that the file format defines follow the "natural"
47 size and alignment guidelines for the relevant class. If necessary,
48 data structures contain explicit padding to ensure 4-byte alignment for
49 4-byte objects, to force structure sizes to a multiple of 4, etc.
50
51 The ELF header is described by the type Elf32_Ehdr or Elf64_Ehdr:
52
53 #define EI_NIDENT 16
54
55 typedef struct {
56 unsigned char e_ident[EI_NIDENT];
57 uint16_t e_type;
58 uint16_t e_machine;
59 uint32_t e_version;
60 ElfN_Addr e_entry;
61 ElfN_Off e_phoff;
62 ElfN_Off e_shoff;
63 uint32_t e_flags;
64 uint16_t e_ehsize;
65 uint16_t e_phentsize;
66 uint16_t e_phnum;
67 uint16_t e_shentsize;
68 uint16_t e_shnum;
69 uint16_t e_shstrndx;
70 } ElfN_Ehdr;
71
72 The fields have the following meanings:
73
74 e_ident This array of bytes specifies to interpret the file, inde‐
75 pendent of the processor or the file's remaining contents.
76 Within this array everything is named by macros, which
77 start with the prefix EI_ and may contain values which
78 start with the prefix ELF. The following macros are
79 defined:
80
81 EI_MAG0 The first byte of the magic number. It must be
82 filled with ELFMAG0. (0: 0x7f)
83
84 EI_MAG1 The second byte of the magic number. It must
85 be filled with ELFMAG1. (1: 'E')
86
87 EI_MAG2 The third byte of the magic number. It must be
88 filled with ELFMAG2. (2: 'L')
89
90 EI_MAG3 The fourth byte of the magic number. It must
91 be filled with ELFMAG3. (3: 'F')
92
93 EI_CLASS The fifth byte identifies the architecture for
94 this binary:
95
96 ELFCLASSNONE This class is invalid.
97 ELFCLASS32 This defines the 32-bit architec‐
98 ture. It supports machines with
99 files and virtual address spaces
100 up to 4 Gigabytes.
101 ELFCLASS64 This defines the 64-bit architec‐
102 ture.
103
104 EI_DATA The sixth byte specifies the data encoding of
105 the processor-specific data in the file. Cur‐
106 rently these encodings are supported:
107
108 ELFDATANONE Unknown data format.
109 ELFDATA2LSB Two's complement, little-endian.
110 ELFDATA2MSB Two's complement, big-endian.
111
112 EI_VERSION The version number of the ELF specification:
113 EV_NONE Invalid version.
114 EV_CURRENT Current version.
115
116 EI_OSABI This byte identifies the operating system and
117 ABI to which the object is targeted. Some
118 fields in other ELF structures have flags and
119 values that have platform-specific meanings;
120 the interpretation of those fields is deter‐
121 mined by the value of this byte. E.g.:
122
123 ELFOSABI_NONE Same as ELFOSABI_SYSV
124 ELFOSABI_SYSV UNIX System V ABI.
125 ELFOSABI_HPUX HP-UX ABI.
126 ELFOSABI_NETBSD NetBSD ABI.
127 ELFOSABI_LINUX Linux ABI.
128 ELFOSABI_SOLARIS Solaris ABI.
129 ELFOSABI_IRIX IRIX ABI.
130 ELFOSABI_FREEBSD FreeBSD ABI.
131 ELFOSABI_TRU64 TRU64 UNIX ABI.
132 ELFOSABI_ARM ARM architecture ABI.
133 ELFOSABI_STANDALONE Stand-alone (embedded) ABI.
134
135 EI_ABIVERSION
136 This byte identifies the version of the ABI to
137 which the object is targeted. This field is
138 used to distinguish among incompatible versions
139 of an ABI. The interpretation of this version
140 number is dependent on the ABI identified by
141 the EI_OSABI field. Applications conforming to
142 this specification use the value 0.
143
144 EI_PAD Start of padding. These bytes are reserved and
145 set to zero. Programs which read them should
146 ignore them. The value for EI_PAD will change
147 in the future if currently unused bytes are
148 given meanings.
149
150 EI_NIDENT The size of the e_ident array.
151
152 e_type This member of the structure identifies the object file
153 type:
154
155 ET_NONE An unknown type.
156 ET_REL A relocatable file.
157 ET_EXEC An executable file.
158 ET_DYN A shared object.
159 ET_CORE A core file.
160
161 e_machine This member specifies the required architecture for an
162 individual file. E.g.:
163
164 EM_NONE An unknown machine.
165 EM_M32 AT&T WE 32100.
166 EM_SPARC Sun Microsystems SPARC.
167 EM_386 Intel 80386.
168 EM_68K Motorola 68000.
169 EM_88K Motorola 88000.
170 EM_860 Intel 80860.
171 EM_MIPS MIPS RS3000 (big-endian only).
172 EM_PARISC HP/PA.
173 EM_SPARC32PLUS
174 SPARC with enhanced instruction set.
175 EM_PPC PowerPC.
176 EM_PPC64 PowerPC 64-bit.
177 EM_S390 IBM S/390
178 EM_ARM Advanced RISC Machines
179 EM_SH Renesas SuperH
180 EM_SPARCV9 SPARC v9 64-bit.
181 EM_IA_64 Intel Itanium
182 EM_X86_64 AMD x86-64
183 EM_VAX DEC Vax.
184
185 e_version This member identifies the file version:
186
187 EV_NONE Invalid version.
188 EV_CURRENT Current version.
189
190 e_entry This member gives the virtual address to which the system
191 first transfers control, thus starting the process. If the
192 file has no associated entry point, this member holds zero.
193
194 e_phoff This member holds the program header table's file offset in
195 bytes. If the file has no program header table, this mem‐
196 ber holds zero.
197
198 e_shoff This member holds the section header table's file offset in
199 bytes. If the file has no section header table this member
200 holds zero.
201
202 e_flags This member holds processor-specific flags associated with
203 the file. Flag names take the form EF_`machine_flag'.
204 Currently no flags have been defined.
205
206 e_ehsize This member holds the ELF header's size in bytes.
207
208 e_phentsize This member holds the size in bytes of one entry in the
209 file's program header table; all entries are the same size.
210
211 e_phnum This member holds the number of entries in the program
212 header table. Thus the product of e_phentsize and e_phnum
213 gives the table's size in bytes. If a file has no program
214 header, e_phnum holds the value zero.
215
216 If the number of entries in the program header table is
217 larger than or equal to PN_XNUM (0xffff), this member holds
218 PN_XNUM (0xffff) and the real number of entries in the pro‐
219 gram header table is held in the sh_info member of the ini‐
220 tial entry in section header table. Otherwise, the sh_info
221 member of the initial entry contains the value zero.
222
223 PN_XNUM This is defined as 0xffff, the largest number
224 e_phnum can have, specifying where the actual num‐
225 ber of program headers is assigned.
226
227 e_shentsize This member holds a sections header's size in bytes. A
228 section header is one entry in the section header table;
229 all entries are the same size.
230
231 e_shnum This member holds the number of entries in the section
232 header table. Thus the product of e_shentsize and e_shnum
233 gives the section header table's size in bytes. If a file
234 has no section header table, e_shnum holds the value of
235 zero.
236
237 If the number of entries in the section header table is
238 larger than or equal to SHN_LORESERVE [22m(0xff00), e_shnum
239 holds the value zero and the real number of entries in the
240 section header table is held in the sh_size member of the
241 initial entry in section header table. Otherwise, the
242 sh_size member of the initial entry in the section header
243 table holds the value zero.
244
245 e_shstrndx This member holds the section header table index of the
246 entry associated with the section name string table. If
247 the file has no section name string table, this member
248 holds the value SHN_UNDEF.
249
250 If the index of section name string table section is larger
251 than or equal to SHN_LORESERVE (0xff00), this member holds
252 SHN_XINDEX (0xffff) and the real index of the section name
253 string table section is held in the sh_link member of the
254 initial entry in section header table. Otherwise, the
255 sh_link member of the initial entry in section header table
256 contains the value zero.
257
258 SHN_UNDEF This value marks an undefined, missing,
259 irrelevant, or otherwise meaningless section
260 reference. For example, a symbol "defined"
261 relative to section number SHN_UNDEF is an
262 undefined symbol.
263
264 SHN_LORESERVE This value specifies the lower bound of the
265 range of reserved indices.
266
267 SHN_LOPROC Values greater than or equal to SHN_HIPROC
268 are reserved for processor-specific seman‐
269 tics.
270
271 SHN_HIPROC Values less than or equal to SHN_LOPROC are
272 reserved for processor-specific semantics.
273
274 SHN_ABS This value specifies absolute values for the
275 corresponding reference. For example, sym‐
276 bols defined relative to section number
277 SHN_ABS have absolute values and are not
278 affected by relocation.
279
280 SHN_COMMON Symbols defined relative to this section are
281 common symbols, such as Fortran COMMON or
282 unallocated C external variables.
283
284 SHN_HIRESERVE This value specifies the upper bound of the
285 range of reserved indices between SHN_LORE‐
286 SERVE and SHN_HIRESERVE, inclusive; the val‐
287 ues do not reference the section header ta‐
288 ble. That is, the section header table does
289 not contain entries for the reserved indices.
290
291 An executable or shared object file's program header table is an array
292 of structures, each describing a segment or other information the sys‐
293 tem needs to prepare the program for execution. An object file segment
294 contains one or more sections. Program headers are meaningful only for
295 executable and shared object files. A file specifies its own program
296 header size with the ELF header's e_phentsize and e_phnum members. The
297 ELF program header is described by the type Elf32_Phdr or Elf64_Phdr
298 depending on the architecture:
299
300 typedef struct {
301 uint32_t p_type;
302 Elf32_Off p_offset;
303 Elf32_Addr p_vaddr;
304 Elf32_Addr p_paddr;
305 uint32_t p_filesz;
306 uint32_t p_memsz;
307 uint32_t p_flags;
308 uint32_t p_align;
309 } Elf32_Phdr;
310
311 typedef struct {
312 uint32_t p_type;
313 uint32_t p_flags;
314 Elf64_Off p_offset;
315 Elf64_Addr p_vaddr;
316 Elf64_Addr p_paddr;
317 uint64_t p_filesz;
318 uint64_t p_memsz;
319 uint64_t p_align;
320 } Elf64_Phdr;
321
322 The main difference between the 32-bit and the 64-bit program header
323 lies in the location of the p_flags member in the total struct.
324
325 p_type This member of the Phdr struct tells what kind of segment
326 this array element describes or how to interpret the array
327 element's information.
328
329 PT_NULL The array element is unused and the other mem‐
330 bers' values are undefined. This lets the pro‐
331 gram header have ignored entries.
332
333 PT_LOAD The array element specifies a loadable segment,
334 described by p_filesz and p_memsz. The bytes
335 from the file are mapped to the beginning of
336 the memory segment. If the segment's memory
337 size p_memsz is larger than the file size
338 p_filesz, the "extra" bytes are defined to hold
339 the value 0 and to follow the segment's ini‐
340 tialized area. The file size may not be larger
341 than the memory size. Loadable segment entries
342 in the program header table appear in ascending
343 order, sorted on the p_vaddr member.
344
345 PT_DYNAMIC The array element specifies dynamic linking
346 information.
347
348 PT_INTERP The array element specifies the location and
349 size of a null-terminated pathname to invoke as
350 an interpreter. This segment type is meaning‐
351 ful only for executable files (though it may
352 occur for shared objects). However it may not
353 occur more than once in a file. If it is
354 present, it must precede any loadable segment
355 entry.
356
357 PT_NOTE The array element specifies the location and
358 size for auxiliary information.
359
360 PT_SHLIB This segment type is reserved but has unspeci‐
361 fied semantics. Programs that contain an array
362 element of this type do not conform to the ABI.
363
364 PT_PHDR The array element, if present, specifies the
365 location and size of the program header table
366 itself, both in the file and in the memory
367 image of the program. This segment type may
368 not occur more than once in a file. Moreover,
369 it may only occur if the program header table
370 is part of the memory image of the program. If
371 it is present, it must precede any loadable
372 segment entry.
373
374 PT_LOPROC Values greater than or equal to PT_HIPROC are
375 reserved for processor-specific semantics.
376
377 PT_HIPROC Values less than or equal to PT_LOPROC are
378 reserved for processor-specific semantics.
379 PT_GNU_STACK GNU extension which is used by the
380 Linux kernel to control the state of the stack
381 via the flags set in the p_flags member.
382
383 p_offset This member holds the offset from the beginning of the file
384 at which the first byte of the segment resides.
385
386 p_vaddr This member holds the virtual address at which the first
387 byte of the segment resides in memory.
388
389 p_paddr On systems for which physical addressing is relevant, this
390 member is reserved for the segment's physical address.
391 Under BSD this member is not used and must be zero.
392
393 p_filesz This member holds the number of bytes in the file image of
394 the segment. It may be zero.
395
396 p_memsz This member holds the number of bytes in the memory image
397 of the segment. It may be zero.
398
399 p_flags This member holds a bitmask of flags relevant to the seg‐
400 ment:
401
402 PF_X An executable segment.
403 PF_W A writable segment.
404 PF_R A readable segment.
405
406 A text segment commonly has the flags PF_X and PF_R. A
407 data segment commonly has PF_X, PF_W and PF_R.
408
409 p_align This member holds the value to which the segments are
410 aligned in memory and in the file. Loadable process seg‐
411 ments must have congruent values for p_vaddr and p_offset,
412 modulo the page size. Values of zero and one mean no
413 alignment is required. Otherwise, p_align should be a pos‐
414 itive, integral power of two, and p_vaddr should equal
415 p_offset, modulo p_align.
416
417 A file's section header table lets one locate all the file's sections.
418 The section header table is an array of Elf32_Shdr or Elf64_Shdr struc‐
419 tures. The ELF header's e_shoff member gives the byte offset from the
420 beginning of the file to the section header table. e_shnum holds the
421 number of entries the section header table contains. e_shentsize holds
422 the size in bytes of each entry.
423
424 A section header table index is a subscript into this array. Some sec‐
425 tion header table indices are reserved: the initial entry and the
426 indices between SHN_LORESERVE and SHN_HIRESERVE. The initial entry is
427 used in ELF extensions for e_phnum, e_shnum and e_strndx; in other
428 cases, each field in the initial entry is set to zero. An object file
429 does not have sections for these special indices:
430
431 SHN_UNDEF This value marks an undefined, missing, irrelevant
432 or otherwise meaningless section reference.
433
434 SHN_LORESERVE This value specifies the lower bound of the range
435 of reserved indices.
436
437 SHN_LOPROC Values greater than or equal to SHN_HIPROC are
438 reserved for processor-specific semantics.
439
440 SHN_HIPROC Values less than or equal to SHN_LOPROC are
441 reserved for processor-specific semantics.
442
443 SHN_ABS This value specifies the absolute value for the
444 corresponding reference. For example, a symbol
445 defined relative to section number SHN_ABS has an
446 absolute value and is not affected by relocation.
447
448 SHN_COMMON Symbols defined relative to this section are com‐
449 mon symbols, such as FORTRAN COMMON or unallocated
450 C external variables.
451
452 SHN_HIRESERVE This value specifies the upper bound of the range
453 of reserved indices. The system reserves indices
454 between SHN_LORESERVE and SHN_HIRESERVE, inclu‐
455 sive. The section header table does not contain
456 entries for the reserved indices.
457
458 The section header has the following structure:
459
460 typedef struct {
461 uint32_t sh_name;
462 uint32_t sh_type;
463 uint32_t sh_flags;
464 Elf32_Addr sh_addr;
465 Elf32_Off sh_offset;
466 uint32_t sh_size;
467 uint32_t sh_link;
468 uint32_t sh_info;
469 uint32_t sh_addralign;
470 uint32_t sh_entsize;
471 } Elf32_Shdr;
472
473 typedef struct {
474 uint32_t sh_name;
475 uint32_t sh_type;
476 uint64_t sh_flags;
477 Elf64_Addr sh_addr;
478 Elf64_Off sh_offset;
479 uint64_t sh_size;
480 uint32_t sh_link;
481 uint32_t sh_info;
482 uint64_t sh_addralign;
483 uint64_t sh_entsize;
484 } Elf64_Shdr;
485
486 No real differences exist between the 32-bit and 64-bit section head‐
487 ers.
488
489 sh_name This member specifies the name of the section. Its value is
490 an index into the section header string table section, giving
491 the location of a null-terminated string.
492
493 sh_type This member categorizes the section's contents and semantics.
494
495 SHT_NULL This value marks the section header as inac‐
496 tive. It does not have an associated section.
497 Other members of the section header have unde‐
498 fined values.
499
500 SHT_PROGBITS This section holds information defined by the
501 program, whose format and meaning are deter‐
502 mined solely by the program.
503
504 SHT_SYMTAB This section holds a symbol table. Typically,
505 SHT_SYMTAB provides symbols for link editing,
506 though it may also be used for dynamic link‐
507 ing. As a complete symbol table, it may con‐
508 tain many symbols unnecessary for dynamic
509 linking. An object file can also contain a
510 SHT_DYNSYM section.
511
512 SHT_STRTAB This section holds a string table. An object
513 file may have multiple string table sections.
514
515 SHT_RELA This section holds relocation entries with
516 explicit addends, such as type Elf32_Rela for
517 the 32-bit class of object files. An object
518 may have multiple relocation sections.
519
520 SHT_HASH This section holds a symbol hash table. An
521 object participating in dynamic linking must
522 contain a symbol hash table. An object file
523 may have only one hash table.
524
525 SHT_DYNAMIC This section holds information for dynamic
526 linking. An object file may have only one
527 dynamic section.
528
529 SHT_NOTE This section holds information that marks the
530 file in some way.
531
532 SHT_NOBITS A section of this type occupies no space in
533 the file but otherwise resembles SHT_PROGBITS.
534 Although this section contains no bytes, the
535 sh_offset member contains the conceptual file
536 offset.
537
538 SHT_REL This section holds relocation offsets without
539 explicit addends, such as type Elf32_Rel for
540 the 32-bit class of object files. An object
541 file may have multiple relocation sections.
542
543 SHT_SHLIB This section is reserved but has unspecified
544 semantics.
545
546 SHT_DYNSYM This section holds a minimal set of dynamic
547 linking symbols. An object file can also con‐
548 tain a SHT_SYMTAB section.
549
550 SHT_LOPROC This value up to and including SHT_HIPROC is
551 reserved for processor-specific semantics.
552
553 SHT_HIPROC This value down to and including SHT_LOPROC is
554 reserved for processor-specific semantics.
555
556 SHT_LOUSER This value specifies the lower bound of the
557 range of indices reserved for application pro‐
558 grams.
559
560 SHT_HIUSER This value specifies the upper bound of the
561 range of indices reserved for application pro‐
562 grams. Section types between SHT_LOUSER and
563 SHT_HIUSER may be used by the application,
564 without conflicting with current or future
565 system-defined section types.
566
567 sh_flags Sections support one-bit flags that describe miscellaneous
568 attributes. If a flag bit is set in sh_flags, the attribute
569 is "on" for the section. Otherwise, the attribute is "off"
570 or does not apply. Undefined attributes are set to zero.
571
572 SHF_WRITE This section contains data that should be
573 writable during process execution.
574
575 SHF_ALLOC This section occupies memory during process
576 execution. Some control sections do not
577 reside in the memory image of an object file.
578 This attribute is off for those sections.
579
580 SHF_EXECINSTR This section contains executable machine
581 instructions.
582
583 SHF_MASKPROC All bits included in this mask are reserved
584 for processor-specific semantics.
585
586 sh_addr If this section appears in the memory image of a process,
587 this member holds the address at which the section's first
588 byte should reside. Otherwise, the member contains zero.
589
590 sh_offset This member's value holds the byte offset from the beginning
591 of the file to the first byte in the section. One section
592 type, SHT_NOBITS, occupies no space in the file, and its
593 sh_offset member locates the conceptual placement in the
594 file.
595
596 sh_size This member holds the section's size in bytes. Unless the
597 section type is SHT_NOBITS, the section occupies sh_size
598 bytes in the file. A section of type SHT_NOBITS may have a
599 nonzero size, but it occupies no space in the file.
600
601 sh_link This member holds a section header table index link, whose
602 interpretation depends on the section type.
603
604 sh_info This member holds extra information, whose interpretation
605 depends on the section type.
606
607 sh_addralign
608 Some sections have address alignment constraints. If a sec‐
609 tion holds a doubleword, the system must ensure doubleword
610 alignment for the entire section. That is, the value of
611 sh_addr must be congruent to zero, modulo the value of
612 sh_addralign. Only zero and positive integral powers of two
613 are allowed. Values of zero or one mean the section has no
614 alignment constraints.
615
616 sh_entsize
617 Some sections hold a table of fixed-sized entries, such as a
618 symbol table. For such a section, this member gives the size
619 in bytes for each entry. This member contains zero if the
620 section does not hold a table of fixed-size entries.
621
622 Various sections hold program and control information:
623
624 .bss This section holds uninitialized data that contributes to the
625 program's memory image. By definition, the system initial‐
626 izes the data with zeros when the program begins to run.
627 This section is of type SHT_NOBITS. The attribute types are
628 SHF_ALLOC and SHF_WRITE.
629
630 .comment This section holds version control information. This section
631 is of type SHT_PROGBITS. No attribute types are used.
632
633 .ctors This section holds initialized pointers to the C++ construc‐
634 tor functions. This section is of type SHT_PROGBITS. The
635 attribute types are SHF_ALLOC and SHF_WRITE.
636
637 .data This section holds initialized data that contribute to the
638 program's memory image. This section is of type SHT_PROG‐
639 BITS. The attribute types are SHF_ALLOC and SHF_WRITE.
640
641 .data1 This section holds initialized data that contribute to the
642 program's memory image. This section is of type SHT_PROG‐
643 BITS. The attribute types are SHF_ALLOC and SHF_WRITE.
644
645 .debug This section holds information for symbolic debugging. The
646 contents are unspecified. This section is of type SHT_PROG‐
647 BITS. No attribute types are used.
648
649 .dtors This section holds initialized pointers to the C++ destructor
650 functions. This section is of type SHT_PROGBITS. The
651 attribute types are SHF_ALLOC and SHF_WRITE.
652
653 .dynamic This section holds dynamic linking information. The sec‐
654 tion's attributes will include the SHF_ALLOC bit. Whether
655 the SHF_WRITE bit is set is processor-specific. This section
656 is of type SHT_DYNAMIC. See the attributes above.
657
658 .dynstr This section holds strings needed for dynamic linking, most
659 commonly the strings that represent the names associated with
660 symbol table entries. This section is of type SHT_STRTAB.
661 The attribute type used is SHF_ALLOC.
662
663 .dynsym This section holds the dynamic linking symbol table. This
664 section is of type SHT_DYNSYM. The attribute used is
665 SHF_ALLOC.
666
667 .fini This section holds executable instructions that contribute to
668 the process termination code. When a program exits normally
669 the system arranges to execute the code in this section.
670 This section is of type SHT_PROGBITS. The attributes used
671 are SHF_ALLOC and SHF_EXECINSTR.
672
673 .gnu.version
674 This section holds the version symbol table, an array of
675 ElfN_Half elements. This section is of type SHT_GNU_versym.
676 The attribute type used is SHF_ALLOC.
677
678 .gnu.version_d
679 This section holds the version symbol definitions, a table of
680 ElfN_Verdef structures. This section is of type
681 SHT_GNU_verdef. The attribute type used is SHF_ALLOC.
682
683 .gnu.version_r
684 This section holds the version symbol needed elements, a ta‐
685 ble of ElfN_Verneed structures. This section is of type
686 SHT_GNU_versym. The attribute type used is SHF_ALLOC.
687
688 .got This section holds the global offset table. This section is
689 of type SHT_PROGBITS. The attributes are processor specific.
690
691 .hash This section holds a symbol hash table. This section is of
692 type SHT_HASH. The attribute used is SHF_ALLOC.
693
694 .init This section holds executable instructions that contribute to
695 the process initialization code. When a program starts to
696 run the system arranges to execute the code in this section
697 before calling the main program entry point. This section is
698 of type SHT_PROGBITS. The attributes used are SHF_ALLOC and
699 SHF_EXECINSTR.
700
701 .interp This section holds the pathname of a program interpreter. If
702 the file has a loadable segment that includes the section,
703 the section's attributes will include the SHF_ALLOC bit.
704 Otherwise, that bit will be off. This section is of type
705 SHT_PROGBITS.
706
707 .line This section holds line number information for symbolic
708 debugging, which describes the correspondence between the
709 program source and the machine code. The contents are
710 unspecified. This section is of type SHT_PROGBITS. No
711 attribute types are used.
712
713 .note This section holds information in the "Note Section" format.
714 This section is of type SHT_NOTE. No attribute types are
715 used. OpenBSD native executables usually contain a
716 .note.openbsd.ident section to identify themselves, for the
717 kernel to bypass any compatibility ELF binary emulation tests
718 when loading the file.
719
720 .note.GNU-stack
721 This section is used in Linux object files for declaring
722 stack attributes. This section is of type SHT_PROGBITS. The
723 only attribute used is SHF_EXECINSTR. This indicates to the
724 GNU linker that the object file requires an executable stack.
725
726 .plt This section holds the procedure linkage table. This section
727 is of type SHT_PROGBITS. The attributes are processor spe‐
728 cific.
729
730 .relNAME This section holds relocation information as described below.
731 If the file has a loadable segment that includes relocation,
732 the section's attributes will include the SHF_ALLOC bit.
733 Otherwise the bit will be off. By convention, "NAME" is sup‐
734 plied by the section to which the relocations apply. Thus a
735 relocation section for .text normally would have the name
736 .rel.text. This section is of type SHT_REL.
737
738 .relaNAME This section holds relocation information as described below.
739 If the file has a loadable segment that includes relocation,
740 the section's attributes will include the SHF_ALLOC bit.
741 Otherwise the bit will be off. By convention, "NAME" is sup‐
742 plied by the section to which the relocations apply. Thus a
743 relocation section for .text normally would have the name
744 .rela.text. This section is of type SHT_RELA.
745
746 .rodata This section holds read-only data that typically contributes
747 to a nonwritable segment in the process image. This section
748 is of type SHT_PROGBITS. The attribute used is SHF_ALLOC.
749
750 .rodata1 This section holds read-only data that typically contributes
751 to a nonwritable segment in the process image. This section
752 is of type SHT_PROGBITS. The attribute used is SHF_ALLOC.
753
754 .shstrtab This section holds section names. This section is of type
755 SHT_STRTAB. No attribute types are used.
756
757 .strtab This section holds strings, most commonly the strings that
758 represent the names associated with symbol table entries. If
759 the file has a loadable segment that includes the symbol
760 string table, the section's attributes will include the
761 SHF_ALLOC bit. Otherwise the bit will be off. This section
762 is of type SHT_STRTAB.
763
764 .symtab This section holds a symbol table. If the file has a load‐
765 able segment that includes the symbol table, the section's
766 attributes will include the SHF_ALLOC bit. Otherwise the bit
767 will be off. This section is of type SHT_SYMTAB.
768
769 .text This section holds the "text", or executable instructions, of
770 a program. This section is of type SHT_PROGBITS. The
771 attributes used are SHF_ALLOC and SHF_EXECINSTR.
772
773 String table sections hold null-terminated character sequences, com‐
774 monly called strings. The object file uses these strings to represent
775 symbol and section names. One references a string as an index into the
776 string table section. The first byte, which is index zero, is defined
777 to hold a null byte ('\0'). Similarly, a string table's last byte is
778 defined to hold a null byte, ensuring null termination for all strings.
779
780 An object file's symbol table holds information needed to locate and
781 relocate a program's symbolic definitions and references. A symbol ta‐
782 ble index is a subscript into this array.
783
784 typedef struct {
785 uint32_t st_name;
786 Elf32_Addr st_value;
787 uint32_t st_size;
788 unsigned char st_info;
789 unsigned char st_other;
790 uint16_t st_shndx;
791 } Elf32_Sym;
792
793 typedef struct {
794 uint32_t st_name;
795 unsigned char st_info;
796 unsigned char st_other;
797 uint16_t st_shndx;
798 Elf64_Addr st_value;
799 uint64_t st_size;
800 } Elf64_Sym;
801
802 The 32-bit and 64-bit versions have the same members, just in a differ‐
803 ent order.
804
805 st_name This member holds an index into the object file's symbol
806 string table, which holds character representations of the
807 symbol names. If the value is nonzero, it represents a
808 string table index that gives the symbol name. Otherwise,
809 the symbol table has no name.
810
811 st_value This member gives the value of the associated symbol.
812
813 st_size Many symbols have associated sizes. This member holds zero
814 if the symbol has no size or an unknown size.
815
816 st_info This member specifies the symbol's type and binding
817 attributes:
818
819 STT_NOTYPE The symbol's type is not defined.
820
821 STT_OBJECT The symbol is associated with a data object.
822
823 STT_FUNC The symbol is associated with a function or other
824 executable code.
825
826 STT_SECTION The symbol is associated with a section. Symbol
827 table entries of this type exist primarily for
828 relocation and normally have STB_LOCAL bindings.
829
830 STT_FILE By convention, the symbol's name gives the name
831 of the source file associated with the object
832 file. A file symbol has STB_LOCAL bindings, its
833 section index is SHN_ABS, and it precedes the
834 other STB_LOCAL symbols of the file, if it is
835 present.
836
837 STT_LOPROC This value up to and including STT_HIPROC is
838 reserved for processor-specific semantics.
839
840 STT_HIPROC This value down to and including STT_LOPROC is
841 reserved for processor-specific semantics.
842
843 STB_LOCAL Local symbols are not visible outside the object
844 file containing their definition. Local symbols
845 of the same name may exist in multiple files
846 without interfering with each other.
847
848 STB_GLOBAL Global symbols are visible to all object files
849 being combined. One file's definition of a
850 global symbol will satisfy another file's unde‐
851 fined reference to the same symbol.
852
853 STB_WEAK Weak symbols resemble global symbols, but their
854 definitions have lower precedence.
855
856 STB_LOPROC This value up to and including STB_HIPROC is
857 reserved for processor-specific semantics.
858
859 STB_HIPROC This value down to and including STB_LOPROC is
860 reserved for processor-specific semantics.
861
862 There are macros for packing and unpacking the
863 binding and type fields:
864
865 ELF32_ST_BIND(info) or ELF64_ST_BIND(info)
866 extract a binding from an st_info value.
867
868 ELF32_ST_TYPE(info) or ELF64_ST_TYPE(info)
869 extract a type from an st_info value.
870
871 ELF32_ST_INFO(bind, type) or ELF64_ST_INFO(bind,
872 type)
873 convert a binding and a type into an st_info
874 value.
875
876 st_other This member defines the symbol visibility.
877
878 STV_DEFAULT Default symbol visibility rules.
879 STV_INTERNAL Processor-specific hidden class.
880 STV_HIDDEN Symbol is unavailable in other modules.
881 STV_PROTECTED Not preemptible, not exported.
882
883 There are macros for extracting the visibility type:
884
885 ELF32_ST_VISIBILITY(other) or ELF64_ST_VISIBILITY(other)
886
887 st_shndx Every symbol table entry is "defined" in relation to some
888 section. This member holds the relevant section header table
889 index.
890
891 Relocation is the process of connecting symbolic references with sym‐
892 bolic definitions. Relocatable files must have information that
893 describes how to modify their section contents, thus allowing exe‐
894 cutable and shared object files to hold the right information for a
895 process's program image. Relocation entries are these data.
896
897 Relocation structures that do not need an addend:
898
899 typedef struct {
900 Elf32_Addr r_offset;
901 uint32_t r_info;
902 } Elf32_Rel;
903
904 typedef struct {
905 Elf64_Addr r_offset;
906 uint64_t r_info;
907 } Elf64_Rel;
908
909 Relocation structures that need an addend:
910
911 typedef struct {
912 Elf32_Addr r_offset;
913 uint32_t r_info;
914 int32_t r_addend;
915 } Elf32_Rela;
916
917 typedef struct {
918 Elf64_Addr r_offset;
919 uint64_t r_info;
920 int64_t r_addend;
921 } Elf64_Rela;
922
923 r_offset This member gives the location at which to apply the relo‐
924 cation action. For a relocatable file, the value is the
925 byte offset from the beginning of the section to the stor‐
926 age unit affected by the relocation. For an executable
927 file or shared object, the value is the virtual address of
928 the storage unit affected by the relocation.
929
930 r_info This member gives both the symbol table index with respect
931 to which the relocation must be made and the type of relo‐
932 cation to apply. Relocation types are processor specific.
933 When the text refers to a relocation entry's relocation
934 type or symbol table index, it means the result of applying
935 ELF_[32|64]_R_TYPE or ELF[32|64]_R_SYM, respectively, to
936 the entry's r_info member.
937
938 r_addend This member specifies a constant addend used to compute the
939 value to be stored into the relocatable field.
940
941 The .dynamic section contains a series of structures that hold relevant
942 dynamic linking information. The d_tag member controls the interpreta‐
943 tion of d_un.
944
945 typedef struct {
946 Elf32_Sword d_tag;
947 union {
948 Elf32_Word d_val;
949 Elf32_Addr d_ptr;
950 } d_un;
951 } Elf32_Dyn;
952 extern Elf32_Dyn _DYNAMIC[];
953
954 typedef struct {
955 Elf64_Sxword d_tag;
956 union {
957 Elf64_Xword d_val;
958 Elf64_Addr d_ptr;
959 } d_un;
960 } Elf64_Dyn;
961 extern Elf64_Dyn _DYNAMIC[];
962
963 d_tag This member may have any of the following values:
964
965 DT_NULL Marks end of dynamic section
966
967 DT_NEEDED String table offset to name of a needed library
968
969 DT_PLTRELSZ Size in bytes of PLT relocs
970
971 DT_PLTGOT Address of PLT and/or GOT
972
973 DT_HASH Address of symbol hash table
974
975 DT_STRTAB Address of string table
976
977 DT_SYMTAB Address of symbol table
978
979 DT_RELA Address of Rela relocs table
980
981 DT_RELASZ Size in bytes of Rela table
982
983 DT_RELAENT Size in bytes of a Rela table entry
984
985 DT_STRSZ Size in bytes of string table
986
987 DT_SYMENT Size in bytes of a symbol table entry
988
989 DT_INIT Address of the initialization function
990
991 DT_FINI Address of the termination function
992
993 DT_SONAME String table offset to name of shared object
994
995 DT_RPATH String table offset to library search path (dep‐
996 recated)
997
998 DT_SYMBOLIC Alert linker to search this shared object before
999 the executable for symbols
1000
1001 DT_REL Address of Rel relocs table
1002
1003 DT_RELSZ Size in bytes of Rel table
1004
1005 DT_RELENT Size in bytes of a Rel table entry
1006
1007 DT_PLTREL Type of reloc the PLT refers (Rela or Rel)
1008
1009 DT_DEBUG Undefined use for debugging
1010
1011 DT_TEXTREL Absence of this indicates no relocs should apply
1012 to a nonwritable segment
1013
1014 DT_JMPREL Address of reloc entries solely for the PLT
1015
1016 DT_BIND_NOW Instruct dynamic linker to process all relocs
1017 before transferring control to the executable
1018
1019 DT_RUNPATH String table offset to library search path
1020
1021 DT_LOPROC Start of processor-specific semantics
1022
1023 DT_HIPROC End of processor-specific semantics
1024
1025 d_val This member represents integer values with various interpre‐
1026 tations.
1027
1028 d_ptr This member represents program virtual addresses. When
1029 interpreting these addresses, the actual address should be
1030 computed based on the original file value and memory base
1031 address. Files do not contain relocation entries to fixup
1032 these addresses.
1033
1034 _DYNAMIC Array containing all the dynamic structures in the .dynamic
1035 section. This is automatically populated by the linker.
1036
1038 ELF first appeared in System V. The ELF format is an adopted standard.
1039
1040 The extensions for e_phnum, e_shnum and e_strndx respectively are Linux
1041 extensions. Sun, BSD and AMD64 also support them; for further informa‐
1042 tion, look under SEE ALSO.
1043
1045 as(1), gdb(1), ld(1), objdump(1), execve(2), core(5)
1046
1047 Hewlett-Packard, Elf-64 Object File Format.
1048
1049 Santa Cruz Operation, System V Application Binary Interface.
1050
1051 Unix System Laboratories, "Object Files", Executable and Linking Format
1052 (ELF).
1053
1054 Sun Microsystems, Linker and Libraries Guide.
1055
1056 AMD64 ABI Draft, System V Application Binary Interface AMD64 Architec‐
1057 ture Processor Supplement.
1058
1060 This page is part of release 3.25 of the Linux man-pages project. A
1061 description of the project, and information about reporting bugs, can
1062 be found at http://www.kernel.org/doc/man-pages/.
1063
1064
1065
1066Linux 2010-06-19 ELF(5)