BINARY_DISSECTION_COURSE

ELF (Executable and Linkable Format)

Ever thought why even a the smallest possible piece of code you compile results in some thousands of bytes in size?

Any file is made up of at least 2 components -

ELF is the content stored at very begining of an executable and is responsible to direct the OS on how to load the executable into memory for execution. ELF’s are the replacement to older object file formats used like COFF (Common Object File Format) and a.out (Assembler Output) formats.

There are 4 type of ELF binaries on *NIX type systems.

An ELF binary is made up of 4 main components -

  1. ELF HEADER : It describes attributes of an ELF binary which include information useful to the loaders & linkers. It includes location to other body parts of an ELF binary which is helpful while implementing parsers for the binary.
  2. PROGRAM HEADER TABLE : A PHT describes the segments of an ELF binary. It is useful to the loader and the runtime linker (ld-Linux.so).
  3. SECTION HEADER TABLE : A SHT describes the sections of an ELF binary. It is useful to the compile-time linker (ld) and its presence is optional for program execution.
  4. SECTIONS AND SEGMENTS : It is the actual content of the binary. Sections are just blocks of bytes present in linking view (on-disk view) to produce segment (which provide a runtime/in-memory view). Segments are blocks composed of one or more sections and are produced by linker.

NOTE: ELF header has a field - e_type which specifies type of any ELF binary.

Before the loading and execution stage, the ELF contains code and data arranged in sectons. At the loding and execution stage, those sections are organised and put up into correspoding segments. One or more sections may end up getting fitted into a segment in memory depending on the instructions passed to compile-time linker. Linker scripts can be made which assists linker on how to combine sections into segments. Later on, I plan to cover writing linker scripts in some depth.

Have a look at the overall detailed structure of the elf - IMAGE. Next, we move on towards the actual dissection part :)


PREV - INTRODUCTION
NEXT - ELF HEADER