diff --git a/README.md b/README.md index a903944..960b1c9 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ Here's a collection of links about the subject, I'm putting these here because people seem to find these useful. * [`elf(5)` manpage](https://linux.die.net/man/5/elf) -* [unofficial ELF docs](elf.html) (has +* [unofficial ELF docs](elf.md) (has more than the manpage, also has extra links) * [glibc internals](http://s.eresi-project.org/inc/articles/elf-rtld.txt) * [stuff about `.gnu.hash`](https://web.archive.org/web/20111022202443/http://blogs.oracle.com/ali/entry/gnu_hash_elf_sections) diff --git a/elf.md b/elf.md new file mode 100644 index 0000000..718e1c0 --- /dev/null +++ b/elf.md @@ -0,0 +1,2556 @@ +This page is a copy of the +[Archive.org](https://web.archive.org/web/20201202024834/https://web.archive.org/web/20120922073347/http://www.acsu.buffalo.edu/~charngda/elf.html) +copy of the now no longer availabel +[http://www.acsu.buffalo.edu/\~charngda/elf.html](https://web.archive.org/web/20201202024834/http://www.acsu.buffalo.edu/~charngda/elf.html). +It is kept here online as a reference only. + +------------------------------------------------------------------------ + +Acronyms relevant to Executable and Linkable Format (ELF) +--------------------------------------------------------- + +
ABI | +Application binary interface | +
a.out | +Assembler output file format | +
BSS | +Block started by symbol. The uninitialized data segment containing statically-allocated variables. | +
COFF | +Common object file format | +
DTV | +Dynamic thread vector (for TLS) | +
DWARF | +A standardized debugging data format | +
GD | +Global Dynamic (dynamic TLS) One of the Thread-Local Storage access models. | +
GOT | +Global offset table | +
IE | +Initial Executable (static TLS with assigned offsets) One of the Thread-Local Storage access models. | +
LD | +Local Dynamic (dynamic TLS of local symbols) One of the Thread-Local Storage access models. | +
LE | +Local Executable (static TLS) One of the Thread-Local Storage access models. | +
Mach-O | +Mach object file format | +
PC | +Program counter. On x86, this is the same as IP (Instruction Pointer) register. | +
PE | +Portable executable | +
PHT | +Program header table | +
PIC | +Position independent code | +
PIE | +Position independent executable | +
PLT | +Procedure linkage table | +
REL +RELA |
+Relocation | +
RVA | +Relative virtual address | +
SHF | +Section header flag | +
SHT | +Section header table | +
SO | +Shared object (another name for dynamic link library) | +
VMA | +Virtual memory area/address | +
ELF Segment | +Purpose | +
---|---|
DYNAMIC |
+For dynamic binaries, this segment hold dynamic linking information and is usually the same as .dynamic section in ELF's linking view. See paragraph below. |
+
GNU_EH_FRAME |
+Frame unwind information (EH = Exception Handling). This segment is usually the same as .eh_frame_hdr section in ELF's linking view. |
+
GNU_RELRO |
+This segment indicates the memory region which should be made Read-Only after relocation is done. This segment usually appears in a dynamic link library and it contains .ctors , .dtors , .dynamic , .got sections. See paragraph below. |
+
GNU_STACK |
+The permission flag of this segment indicates whether the stack is executable or not. This segment does not have any content; it is just an indicator. | +
INTERP |
+For dynamic binaries, this holds the full pathname of runtime linker ld.so
+This segement is the same as |
+
LOAD |
+Loadable program segment. Only segments of this type are loaded into memory during execution. | +
NOTE |
+Auxiliary information.
+ For core dumps, this segment contains the status of the process (when the core dump is created), such as the signal (the process received and caused it to dump core), pending & held signals, process ID, parent process ID, user ID, nice value, cumulative user & system time, values of registers (including the program counter!) +For more info, see |
+
TLS |
+Thread-Local Storage | +
ELF Section | +Purpose | +
---|---|
.bss |
+Uninitialized global data ("Block Started by Symbol").
+ Depending on the compilers, uninitialized global variables could be stored in a nameness section called
+Compile with gcc -c , then on x86_64, the resulting object file has the following structure:
+
+so only the file-scope and local-scope global variables are in the .bss section.
+If one wants
+Not only there is no error message about redefinition of the same symbol in both source files (notice we did not use the extern keyword here), there is no complaint about their different data types and sizes either. However, if one uses -fno-common , the compiler will complain:
+
|
+
.comment |
+A series of NULL-terminated strings containing compiler information. | +
.ctors |
+Pointers to functions which are marked as __attribute__ ((constructor)) as well as static C++ objects' constructors. They will be used by __libc_global_ctors function.
+See paragraphs below. |
+
.data |
+Initialized data. | +
.data.rel.ro |
+Similar to .data section, but this section should be made Read-Only after relocation is done. |
+
.debug_XXX |
+Debugging information (for the programs which are compiled with -g option) which is in the DWARF 2.0 format.
+See here for DWARF debugging format. |
+
.dtors |
+Pointers to functions which are marked as __attribute__ ((destructor)) as well as static C++ objects' destructors.
+See paragraphs below. |
+
.dynamic |
+For dynamic binaries, this section holds dynamic linking information used by ld.so . See paragraphs below. |
+
.dynstr |
+NULL-terminated strings of names of symbols in .dynsym section.
+One can use commands such as |
+
.dynsym |
+Runtime/Dynamic symbol table. For dynamic binaries, this section is the symbol table of globally visible symbols. For example, if a dynamic link library wants to export its symbols, these symbols will be stored here. On the other hand, if a dynamic executable binary uses symbols from a dynamic link library, then these symbols are stored here too.
+ The symbol names (as NULL-terminated strings) are stored in |
+
.eh_frame + .eh_frame_hdr |
+Frame unwind information (EH = Exception Handling).
+ See here for details. +To see the content of
|
+
.fini |
+Code which will be executed when program exits normally. See paragraphs below. | +
.fini_array |
+Pointers to functions which will be executed when program exits normally. See paragraphs below. | +
.GCC.command.line |
+A series of NULL-terminated strings containing GCC command-line (that is used to compile the code) options.
+ This feature is supported since GCC 4.5 and the program must be compiled with |
+
.gnu.hash |
+GNU's extension to hash table for symbols.
+ See here for its structure and the hash algorithm. +The link editor The runtime linker |
+
.gnu.linkonceXXX |
+GNU's extension. It means only a single copy of the section will be used in linking. This is used to by g++. g++ will emit each template expansion in its own section. The symbols will be defined as weak, so that multiple definitions are permitted. | +
.gnu.version |
+Versions of symbols.
+ See here, here, here, and here for details of symbol versioning. |
+
.gnu.version_d |
+Version definitions of symbols. | +
.gnu.version_r |
+Version references (version needs) of symbols. | +
.got |
+For dynamic binaries, this Global Offset Table holds the addresses of variables which are relocated upon loading. See paragraphs below. | +
.got.plt |
+For dynamic binaries, this Global Offset Table holds the addresses of functions in dynamic libraries. They are used by trampoline code in .plt section. If .got.plt section is present, it contains at least three entries, which have special meanings. See paragraphs below. |
+
.hash |
+Hash table for symbols.
+ See here for its structure and the hash algorithm. +The link editor The runtime linker |
+
.init |
+Code which will be executed when program initializes. See paragraphs below. | +
.init_array |
+Pointers to functions which will be executed when program starts. See paragraphs below. | +
.interp |
+For dynamic binaries, this holds the full pathname of runtime linker ld.so |
+
.jcr |
+Java class registration information.
+ Like |
+
.note.ABI-tag |
+This Linux-specific section is structured as a note section in ELF specification. Its content is mandated here. | +
.note.gnu.build-id |
+A unique build ID. See here and here | +
.note.GNU-stack |
+See here | +
.nvFatBinSegment |
+This segment contains information of nVidia's CUDA fat binary container. Its format is described by struct __cudaFatCudaBinaryRec in __cudaFatFormat.h |
+
.plt |
+For dynamic binaries, this Procedure Linkage Table holds the trampoline/linkage code. See paragraphs below. | +
.preinit_array |
+Similar to .init_array section. See paragraphs below. |
+
.rela.dyn |
+Runtime/Dynamic relocation table.
+ For dynamic binaries, this relocation table holds information of variables which must be relocated upon loading. Each entry in this table is a
|
+
.rela.plt |
+Runtime/Dynamic relocation table.
+ This relocation table is similar to the one in The relocation type of entries in this table is Simply put, this table holds information to relocate entries in |
+
.rel.text + .rela.text |
+Compile-time/Static relocation table.
+ For programs compiled with The difference between Whether to use |
+
.rel.XXX + .rela.XXX |
+Compile-time/Static relocation table for other sections. For example, .rela.init_array is the relocation table for .init_array section. |
+
.rodata |
+Read-only data. | +
.shstrtab |
+NULL-terminated strings of section names.
+ One can use commands such as |
+
.strtab |
+NULL-terminated strings of names of symbols in .symtab section.
+One can use commands such as |
+
.symtab |
+Compile-time/Static symbol table.
+ This is the main symbol table used in compile-time linking or runtime debugging. +The symbol names (as NULL-terminated strings) are stored in Both |
+
.tbss |
+Similar to .bss section, but for Thread-Local data. See paragraphs below. |
+
.tdata |
+Similar to .data section, but for Thread-Local data. See paragraphs below. |
+
.text |
+User's executable code | +