Beruflich Dokumente
Kultur Dokumente
Outline
What is ELF
Basics Executables
Linking View
Execution View Example Loading and Executing and ELF executable Various Conclusions
What is ELF?
Stands for Executable and Linking Format
Standarized executable file format used in most Unix sytems Subsitute of traditional a.out due to efficiency issues (i.e dynamic linking) Developed originally in Unix Systems Laboratory (USL) and adopted by The Tool Interface Standard (TIS) committe.
Basics
Three main types of ELF object files
Relocatable files: code and data to be linked with other object files Executable files Shared object files: Libraries
Executables
Static vs Dynamic Executables Static: Self contained. Too large files due to static inclussion of library code Dynamic: Using external code or data at run time. More convinient Two views of executables according to their participation: Linking view: Executable participation in program linking Execution view: Executable participation in program execution
Executables
Link View: Used at static linking time for relocatable file combination
Execution View: Used at run time to load and execute programs
Executables
Elf Header describes the files organization and resides always at the beginning Program Header Table, if present, tells the system how to create a process image
Section Header Table, if present, contains information describing the filess sections
Relocatable files have section headers tables. Executable files have program headers tables. Shared object files have both.
Linking View
Divides the object files into a collection of sections
Sections have :
Name and type Requested memory ocation at run time Permissions Each section contains a single type of information and can contain flags (writable data, memory space during execution or executable machine instructions)
Linking View
Important Sections:
.interp .text Path name of program interpreter (Dynamic linker) Code (executable instructions) of a program
.data
.bss .init
Initialized data
Uninitilized data Executable instruction for process initilization
.fini
.ptl .re.<x> .dynamic
Execution View
Simpler view that divides the object file into segments Segments have: Simple type
Execution View
Segment Types:
LOAD INTERP Portion of file to be loaded into memory Pointer to dynamic linker for this executable (.interp section)
DYNAMIC
Example
int x = 5; int main() { int r = x +funtion (); exit (0); }
Relocatable file 1
Relocatable file 2
Example
Relocatable Object files
main () int x = 5
funtion () int v = 10 int u = 32
System Code
System Data int x = 5 int v = 10 int u = 32
Uninitialized data
.data
.bss
int y
others
Dynamic Linker
Executing
Various
Shared Libraries
Need to be compiled memory position independent (PIC) Uses a Global Offset table (GOT) with pointers to variables created at compile and linking time Uses the Procedure Linkage Table (PLT) for procedure library calling Implies some performance disadvantages
Various
Others
Relocations tell dynamic linker to rewrite parts of the excutable to refer to external resources
Exists a dynamic debugging structure offering information about process memory layout and binaries loaded
Conclusions
Logical evolution of old executable formats
References
For an exhaustive review of ELF specification please refer to: Executable and Linkable Format (ELF)
Tool Interface Standards (TIS), Portable Formats Specification, Version 1.1