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