Machine code (or executable code) are binary instructions that tell processors what to do. Machine code is produced by compilers, who do all the intermediate steps between human-readable code (i.e., in C/C++) and parse and optimise the code before generating the executable code.
Executable and linkable format (.elf)
On Unix/Linux systems, machine code (including executable files, object code, shared libraries) is stored in .elf
files. It has a magic number of 0x7F 'E' 'L' 'F'
. To output the hex contents of an .elf
file, we can use readelf -a <FILE>
.
The first segment of the .elf
file after the magic number is the file header. It consists of 52 bytes (32-bit system) or 64 bytes (64-bit system), and specifies:
- Endianness
- Target operating system ABI
- Type of object file (i.e., an executable, object file)
- Target instruction set architecture
- Entry point memory address, i.e., where the process starts executing
- Pointer to the start of the program header table
The segment after this is the program header, stored in 56 bytes.