Executable and Linkable Format (ELF)

Executable and Linkable Format (ELF)

Executable and Linkable Format (ELF)

The Executable and Linkable Format (ELF) is a file format used for executables, object code, shared libraries, and core dumps. ELF is widely used in Unix and Unix-like operating systems, including Linux, FreeBSD, and Solaris. It is designed to be flexible, extensible, and portable.

History of ELF

ELF was created as a replacement for the older a.out format, which was used in the early versions of Unix. The ELF format was first introduced in System V Release 4 (SVR4) Unix in 1988. It was later adopted by other Unix-based systems and became the de facto standard for executable and object code files.

Structure of ELF

ELF files consist of a header and a series of sections. The header contains information about the file format, such as the type of file, the target architecture, and the entry point. The sections contain the actual code and data of the file.

Header

The ELF header contains the following fields:

  • Identification: A 16-byte field that identifies the file format.
  • Type: The type of the file, such as executable or shared library.
  • Machine: The target architecture for the file, such as x86 or ARM.
  • Entry point: The memory address where the program begins execution.
  • Program header table offset and size: The location and size of the program header table.
  • Section header table offset and size: The location and size of the section header table.

Sections

ELF files are divided into sections, each of which contains a specific type of data. The most common sections are:

  • .text: Contains the executable code.
  • .data: Contains initialized data.
  • .bss: Contains uninitialized data.
  • .rodata: Contains read-only data.
  • .symtab: Contains symbol table information.
  • .strtab: Contains string table information.

ELF File Types

ELF supports several file types, including:

  • Executable files: These are files that can be executed directly by the operating system.
  • Shared libraries: These are files that can be dynamically linked at runtime by multiple executables.
  • Object files: These are files that contain compiled code and data, but are not yet linked into an executable or shared library.
  • Core dumps: These are files that contain the memory image of a program at the time it crashed.

ELF Linking and Loading

ELF files are linked and loaded at runtime by the operating system or the dynamic linker. Linking is the process of combining object files and shared libraries into an executable or shared library. Loading is the process of loading the executable or shared library into memory and resolving the symbols that are used by the program.

Static Linking

Static linking is the process of linking all the object files and libraries used by an executable into a single executable file. This creates a self-contained executable that can be run on any system that supports the same architecture and operating system.

Dynamic Linking

Dynamic linking is the process of linking shared libraries at runtime, rather than at compile time. This allows multiple executables to share the same libraries, reducing the disk space and memory required for each executable. Dynamic linking also allows libraries to be updated without recompiling all the executables that use them.

ELF Symbols and Relocations

ELF files use symbols and relocations to allow dynamic linking and loading. Symbols are names that represent functions, variables, and other data defined in object files and shared libraries. Relocations are instructions that tell the dynamic linker how to modify the symbol addresses when the program is loaded into memory.

Conclusion

The Executable and Linkable Format (ELF) is a widely used file format for executables, object code, shared libraries, and core dumps in Unix and Unix-like operating systems. ELF files are structured into headers and sections, and support several file types, including executables, shared libraries, object files, and core dumps. ELF files can be statically or dynamically linked and loaded, and use symbols and relocations to enable dynamic linking and loading.

Comments

Popular posts from this blog

OpenSolaris and Linux virtual memory and address space structures

Tagged architectures and multi-level UNIX

Tying top-down and bottom-up object and memory page lookups with the actual x86 page translation and segmentation