Program execution |
---|
General concepts |
Types of code |
Compilation strategies |
Notable runtimes |
|
Notable compilers & toolchains |
|
Incomputer science,executable code, anexecutable file, or anexecutable program, sometimes simply referred to as anexecutable orbinary, causes a computer "to perform indicated tasks according to encodedinstructions",[2] as opposed to adata file that must be interpreted (parsed) by aninterpreter to be functional.[3]
The exact interpretation depends upon the use. "Instructions" is traditionally taken to meanmachine code instructions for a physicalCPU.[4] In some contexts, a file containing scripting instructions (such asbytecode) may also be considered executable.
Executable files can be hand-coded in machine language, although it is far more convenient to develop software assource code in ahigh-level language that can be easily understood by humans. In some cases, source code might be specified inassembly language instead, which remains human-readable while being closely associated with machine code instructions.
The high-level language iscompiled 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 calledassembly. Several object files arelinked to create the executable. Object files—executable or not—are typically stored in acontainer format, such asExecutable and Linkable Format (ELF) orPortable Executable (PE) which isoperating system-specific.[5] 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 aruntime system, which implements runtime language features (such astask scheduling,exception handling, calling static constructors and destructors, etc.) and interactions with the operating system, notably passing arguments, environment, and returning anexit status, together with other startup and shutdown features such as releasing resources likefile handles. For C, this is done by linking in thecrt0 object, which contains the actual entry point and does setup and shutdown by calling theruntime library.[6]
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 callingmain
to start and returning exit status to the kernel at the end.[7]
In order to be executed by the system (such as anoperating system,firmware[citation needed], orboot loader), an executable file must conform to the system'sapplication 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.[8] In more complicated interfaces, executable files have additional metadata specifying a separateentry point. For example, in ELF, the entry point is defined in the header'se_entry
field, which specifies the (virtual) memory address at which to start execution.[9] In theGNU Compiler Collection, this field is set by the linker based on the_start
symbol.[10]