In
computing, executable code, an executable file, or an executable program, sometimes simply referred to as an executable or binary, causes a computer "to perform indicated tasks according to encoded
instructions",
as opposed to a
data file that must be interpreted (
parsed) by a program to be meaningful.
The exact interpretation depends upon the use. "Instructions" is traditionally taken to mean
machine code instructions for a physical
CPU
A central processing unit (CPU), also called a central processor, main processor or just processor, is the electronic circuitry that executes instructions comprising a computer program. The CPU performs basic arithmetic, logic, controlling, and ...
.
In some contexts, a file containing scripting instructions (such as
bytecode
Bytecode (also called portable code or p-code) is a form of instruction set designed for efficient execution by a software interpreter. Unlike human-readable source code, bytecodes are compact numeric codes, constants, and references (norma ...
) may also be considered executable.
Generation of executable files
Executable files can be hand-coded in machine language, although it is far more convenient to develop software as
source code in a
high-level language that can be easily understood by humans. In some cases, source code might be specified in
assembly language
In computer programming, assembly language (or assembler language, or symbolic machine code), often referred to simply as Assembly and commonly abbreviated as ASM or asm, is any low-level programming language with a very strong correspondence be ...
instead, which remains human-readable while being closely associated with machine code instructions.
The high-level language is
compiled into either an executable machine code file or a non-executable machine code –
object file of some sort; the equivalent process on assembly language source code is called ''assembly''. Several object files are
linked to create the executable. Object files -- executable or not -- are typically stored in a
container format
A container format (informally, sometimes called a wrapper) or metafile is a file format that allows multiple data streams to be embedded into a single file, usually along with metadata for identifying and further detailing those streams. Notab ...
, such as
Executable and Linkable Format (ELF) or
Portable Executable (PE) which is
operating system-specific.
This gives structure to the generated machine code, for example dividing it into sections such as
.text
In computing, a code segment, also known as a text segment or simply as text, is a portion of an object file or the corresponding section of the program's virtual address space that contains executable instructions.
Segment
The term "segment" c ...
(executable code),
.data (initialized global and static variables), and
.rodata
In computing, a data segment (often denoted .data) is a portion of an object file or the corresponding address space of a program that contains initialized static variables, that is, global variables and static local variables. The size of this se ...
(read-only data, such as constants and strings).
Executable files typically also include a
runtime system, which implements runtime language features (such as
task scheduling,
exception handling, calling static constructors and destructors, etc.) and interactions with the operating system, notably passing arguments, environment, and returning an
exit status, together with other startup and shutdown features such as releasing resources like
file handles. For C, this is done by linking in the
crt0 object, which contains the actual entry point and does setup and shutdown by calling the
runtime library.
Executable files thus normally contain significant additional machine code beyond that directly generated from the specific source code. In some cases, it is desirable to omit this, for example for embedded systems development, or simply to understand how compilation, linking, and loading work. In C, this can be done by omitting the usual runtime, and instead explicitly specifying a linker script, which generates the entry point and handles startup and shutdown, such as calling
main
to start and returning exit status to the kernel at the end.
Execution
In order to be executed by the system (such as an operating system,
firmware
In computing, firmware is a specific class of computer software that provides the low-level control for a device's specific hardware. Firmware, such as the BIOS of a personal computer, may contain basic functions of a device, and may provide h ...
, or
boot loader), an executable file must conform to the system's
application binary interface (ABI).
In simple interfaces, a file is executed by loading it into memory and jumping to the start of the address space and executing from there. In more complicated interfaces, executable files have additional metadata specifying a separate
entry point. For example, in ELF, the entry point is specified in the header's
e_entry
field, which specifies the (virtual) memory address at which to start execution. In the GCC (
GNU Compiler Collection) this field is set by the linker based on the
_start
symbol.
See also
*
Comparison of executable file formats
This is a comparison of binary executable file formats which, once loaded by a suitable executable loader, can be directly executed by the CPU rather than being interpreted by software. In addition to the binary application code, the executables ma ...
*
Executable compression
*
Executable text
References
External links
EXE File Formatat What Is
{{Executables
Computer file systems
Programming language implementation