the executable file format (ELF, Mach-O, PE)
/ ELF; MACK-oh; P-E /
An executable is not a raw dump of machine code that the processor reads from the first byte. It is a structured file with a strict layout: a header at the front, a table of contents, and then the code and data arranged in labelled sections. The executable file format is the agreed-upon shape of that file, the rulebook both the linker (which writes it) and the loader (which reads it) follow so they can understand each other. Without a shared format, the loader would not know which bytes are code, which are data, or where to start running.
Three formats dominate, one per major platform, and they describe the same ideas in different dialects. ELF (Executable and Linkable Format) is used on Linux and most Unix systems. Mach-O is used on macOS and other Apple systems. PE (Portable Executable) is used on Windows (the familiar .exe and .dll files). Each begins with a header containing a magic number, a few bytes that identify the format at a glance, followed by information the loader needs: the entry point address where execution begins, a list of the segments or sections and where each should be placed in memory, what permissions each region needs (readable, writable, executable), and which shared libraries must be loaded alongside.
This is the main reason a program built for one operating system will not simply run on another, even on the same processor: a Linux ELF binary and a Windows PE binary package the very same kind of machine instructions, but the surrounding format and the operating-system services they expect differ entirely. You normally never read these files directly, but tools like readelf and objdump (for ELF), otool (for Mach-O), and dumpbin (for PE) let you inspect the header and sections, which makes the otherwise invisible structure of a finished program concrete.
$ readelf -h app # read the ELF header Magic: 7f 45 4c 46 ... # the bytes 0x7f 'E' 'L' 'F' -> this is an ELF file Type: EXEC (Executable file) Entry point address: 0x401050 # where the loader jumps to start running
The header's magic number identifies the format, and the entry point tells the loader where to begin.
Same machine instructions, different wrapper: a Linux ELF and a Windows PE hold comparable code, but the format and the OS services they assume differ, so one will not run on the other unmodified.