Program execution |
---|
General concepts |
Types of code |
Compilation strategies |
Notable runtimes |
|
Notable compilers & toolchains |
|
Incomputing, anexecutable is aresource that acomputer can use to control its behavior. As with all information in computing, it isdata, but distinct from data that does not imply aflow of control.[2] Terms such asexecutable code,executable file,executable program, andexecutable image describe forms in which the information is represented and stored. Anative executable ismachine code and is directly executable at theinstruction level of aCPU.[3][4] Ascript is also executable although indirectly via aninterpreter. Intermediate executable code (such asbytecode) may be interpreted or converted to native code at runtime viajust-in-time compilation.
Even though it is technically possible to write a native executable directly in machine language, it is generally not done. It is far more convenient to develop software ashuman readablesource code and to automate the generation of machine code via abuildtoolchain. Today, most source code is ahigh-level language although it is still possible to useassembly language which is closely associated with machine code instructions. Many toolchains consist of acompiler that generates native code as a set ofobject files and alinker that generates a native executable from the object and other files. For assembly language, typically the translation tool is called anassembler instead of a compiler.
Object files are typically stored in adigital container format that supports structure in the machine code – such asExecutable and Linkable Format (ELF) orPortable Executable (PE), depending on the computing context.[5] The format may support segregating code 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 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 may contain significant code beyond that directly generated from the source code. In some cases, it is desirable to omit this, for example for embedded systems. 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]
To be executable, a 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 additionalmetadata, which may specifyrelocations to be performed when the program is loaded, or theentry point address at which to start execution.[9]