
In
computer science
Computer science is the study of computation, information, and automation. Computer science spans Theoretical computer science, theoretical disciplines (such as algorithms, theory of computation, and information theory) to Applied science, ...
, 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
A data file is a computer file which stores data to be used by a computer application or system, including input and output data. A data file usually does not contain instructions or code to be executed (that is, a computer program).
Most of th ...
that must be interpreted (
parsed) by an
interpreter to be functional.
The exact interpretation depends upon the use. "Instructions" is traditionally taken to mean
machine code
In computer programming, machine code is computer code consisting of machine language instructions, which are used to control a computer's central processing unit (CPU). For conventional binary computers, machine code is the binaryOn nonb ...
instructions for a physical
CPU.
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 (normal ...
) 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 computing, source code, or simply code or source, is a plain text computer program written in a programming language. A programmer writes the human readable source code to control the behavior of a computer.
Since a computer, at base, only ...
in a
high-level language that can be easily understood by humans. In some cases, source code might be specified in
assembly language
In computing, assembly language (alternatively 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 bet ...
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
An object file is a file that contains machine code or bytecode, as well as other data and metadata, generated by a compiler or assembler from source code during the compilation or assembly process. The machine code that is generated is kno ...
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, such as
Executable and Linkable Format (ELF) or
Portable Executable
The Portable Executable (PE) format is a file format for executables, object file, object code, Dynamic-link library, dynamic-link-libraries (DLLs), and binary files used on 32-bit and 64-bit Microsoft Windows, Windows operating systems, as well ...
(PE) which is
operating system
An operating system (OS) is system software that manages computer hardware and software resources, and provides common daemon (computing), services for computer programs.
Time-sharing operating systems scheduler (computing), schedule tasks for ...
-specific.
This gives structure to the generated machine code, for example dividing it into sections such as
.text (executable code),
.data (initialized global and static variables), and
.rodata (read-only data, such as constants and strings).
Executable files typically also include a
runtime system
In computer programming, a runtime system or runtime environment is a sub-system that exists in the computer where a program is created, as well as in the computers where the program is intended to be run. The name comes from the compile time ...
, which implements runtime language features (such as
task scheduling
In computing, scheduling is the action of assigning resources to perform tasks. The resources may be processors, network links or expansion cards. The tasks may be threads, processes or data flows.
The scheduling activity is carried out by ...
,
exception handling
In computing and computer programming, exception handling is the process of responding to the occurrence of ''exceptions'' – anomalous or exceptional conditions requiring special processing – during the execution of a program. In general, an ...
, calling static constructors and destructors, etc.) and interactions with the operating system, notably passing arguments, environment, and returning an
exit status
In computing, the exit status (also exit code or exit value) of a terminated process is an integer number that is made available to its parent process (or caller). In DOS, this may be referred to as an errorlevel.
When computer programs ar ...
, together with other startup and shutdown features such as releasing resources like
file handle
In Unix and Unix-like computer operating systems, a file descriptor (FD, less frequently fildes) is a process-unique identifier (handle) for a file or other input/output resource, such as a pipe or network socket.
File descriptors typically ha ...
s. For C, this is done by linking in the
crt0
(also known as ) is a set of execution startup routines linked into a C program that performs any initialization work required before calling the program's main function. After the main function completes the control returns to crt0, which c ...
object, which contains the actual entry point and does setup and shutdown by calling the
runtime library
A runtime library is a library that provides access to the runtime environment that is available to a computer program tailored to the host platform. A runtime environment implements the execution model as required for a development environme ...
.
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
An operating system (OS) is system software that manages computer hardware and software resources, and provides common daemon (computing), services for computer programs.
Time-sharing operating systems scheduler (computing), schedule tasks for ...
, , or
boot loader
A bootloader, also spelled as boot loader or called bootstrap loader, is a computer program that is responsible for booting a computer and booting an operating system. If it also provides an interactive menu with multiple boot choices then it's o ...
), an executable file must conform to the system's
application binary interface
An application binary interface (ABI) is an interface exposed by software that is defined for in-process machine code access. Often, the exposing software is a library, and the consumer is a program.
An ABI is at a relatively low-level of a ...
(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
In computer programming, an entry point is the place in a program where the execution of a program begins, and where the program has access to command line arguments.
To start a program's execution, the loader or operating system passes co ...
. For example, in ELF, the entry point is defined in the header's
e_entry
field, which specifies the (virtual) memory address at which to start execution.
In the
GNU Compiler Collection
The GNU Compiler Collection (GCC) is a collection of compilers from the GNU Project that support various programming languages, Computer architecture, hardware architectures, and operating systems. The Free Software Foundation (FSF) distributes ...
, 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 ...
*
Executable compression
*
Executable text
References
External links
EXE File Formatat What Is
{{Executables
Computer file systems
Programming language implementation