Executable: Difference between revisions

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
imported>InklingF
m Reverted 1 edit by Bargere69 (talk) to last revision by Sdkb
 
imported>DreamRimmer bot II
m Standardise list-defined references format (bot)
 
Line 1: Line 1:
{{Short description|File that causes a computer to follow indicated instructions}}
{{Short description|Data that causes a computer to follow indicated instructions}}
{{About|a general type of computer file|the specific file type used in some operating systems|.exe}}
{{About|a general type of data|the specific file type used in some operating systems|.exe}}
{{Use dmy dates|date=December 2021|cs1-dates=y}}
{{Use dmy dates|date=December 2021|cs1-dates=y}}
{{Use list-defined references|date=December 2021}}
{{Use list-defined references|date=December 2021}}
Line 6: Line 6:
[[File:Binary executable file2.png|thumb|A [[hex dump]] of an executable [[real mode]] loader. The first column consists of [[byte address|address]]es of the first byte in the second column, which comprises bytes of data in [[hexadecimal]] notation ([[Bit numbering#Bit significance and indexing|least significant byte]] first), and the last column consists of the corresponding [[ASCII]] form.<ref name="Celovi_2022"/>]]
[[File:Binary executable file2.png|thumb|A [[hex dump]] of an executable [[real mode]] loader. The first column consists of [[byte address|address]]es of the first byte in the second column, which comprises bytes of data in [[hexadecimal]] notation ([[Bit numbering#Bit significance and indexing|least significant byte]] first), and the last column consists of the corresponding [[ASCII]] form.<ref name="Celovi_2022"/>]]


In [[computer 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 [[instruction (computer science)|instruction]]s",<ref name="MW_2008"/> as opposed to a [[data (computing)|data file]] that must be interpreted ([[parser|parsed]]) by an [[interpreter (computing)|interpreter]] to be functional.<ref name="Mueller_2007" />
In [[computing]], an '''executable''' is a [[computer resource|resource]] that a [[computer]] can use to control its behavior. As with all information in computing, it is [[data]], but distinct from data that does not imply a [[control flow|flow of control]].<ref name="Mueller_2007" /> Terms such as '''executable code''', '''executable file''', '''executable program''', and '''executable image''' describe forms in which the information is represented and stored. A '''native executable''' is [[machine code]] and is directly executable at the [[instruction (computer science)|instruction level]] of a [[central processing unit|CPU]].<ref name="MW_2008"/><ref name="GFG_2015"/> A [[Script (computer programming)|script]] is also executable although indirectly via an [[interpreter (computing)|interpreter]]. Intermediate executable code (such as [[bytecode]]) may be interpreted or converted to native code at runtime via [[just-in-time compilation]].


The exact interpretation depends upon the use. "Instructions" is traditionally taken to mean [[machine code]] instructions for a physical [[central processing unit|CPU]].<ref name="GFG_2015"/> In some contexts, a file containing scripting instructions (such as [[bytecode]]) may also be considered executable.
==Native executable==
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 as [[human readable]] [[source code]] and to automate the generation of machine code via a [[software build|build]] [[toolchain]]. Today, most source code is a [[high-level language]] although it is still possible to use [[assembly language]] which is closely associated with machine code instructions. Many toolchains consist of a [[compiler]] that generates native code as a set of [[object file]]s and a [[linker (computing)|linker]] that generates a native executable from the object and other files. For assembly language, typically the translation tool is called an [[Assembler (computing)|assembler]] instead of a compiler.


==Generation of executable files==
Object files are typically stored in a [[digital container format]] that supports structure in the machine code {{endash}} such as [[Executable and Linkable Format]] (ELF) or [[Portable Executable]] (PE), depending on the computing context.<ref name="LB_2019"/> 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).
{{See also|Object file}}


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]] instead, which remains human-readable while being closely associated with machine code instructions.
Executable files typically 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 handle]]s. 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]].<ref name="Fisher_2019"/> 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 calling <code>main</code> to start and returning exit status to the kernel at the end.<ref name="McKellar_2010"/>


The high-level language is [[Compiler|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 [[linker (computing)|linked]] to create the executable. Object files—executable or not—are typically stored in a [[digital container format|container format]], such as [[Executable and Linkable Format]] (ELF) or [[Portable Executable]] (PE) which is [[operating system]]-specific.<ref name="LB_2019"/> 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).
To be executable, a 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.<ref name="Computer_2005"/> In more complicated interfaces, executable files have additional [[metadata]], which may specify [[Relocation (computing)|relocations]] to be performed when the program is loaded, or the [[entry point]] address at which to start execution.<ref name="Rusling_1999"/>
 
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 handle]]s. 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]].<ref name="Fisher_2019"/>
 
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 <code>main</code> to start and returning exit status to the kernel at the end.<ref name="McKellar_2010"/>
 
== Execution ==
In order to be executed by the system (such as an [[operating system]], {{citation needed span|[[firmware]]|date=March 2023}}, 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.<ref name="Computer_2005"/> In more complicated interfaces, executable files have additional metadata specifying a separate [[entry point]]. For example, in ELF, the entry point is defined in the header's <code>e_entry</code> field, which specifies the (virtual) memory address at which to start execution.<ref name="Rusling_1999"/> In the [[GNU Compiler Collection]], this field is set by the linker based on the <code>_start</code> symbol.<ref name="Page_2009"/>


==See also==
==See also==
* [[Comparison of executable file formats]]
* {{Annotated link|Comparison of executable file formats}}
* [[Executable compression]]
* {{Annotated link|Executable compression}}
* [[Executable text]]
* {{Annotated link|Executable text}}
* {{Annotated link|Object file}}


==References==
==References==
{{reflist|refs=
<references>
<ref name="Celovi_2022">{{cite book|url=https://books.google.com/books?id=E4SFkfsOVaoC&pg=PA188|title=Embedded FreeBSD Cookbook|last=Celovi|first=Paul|publisher=[[Elsevier]]|date=2002|access-date=2022-03-06|pages=108, 187–188|isbn=1-5899-5004-6}}</ref>
<ref name="Celovi_2022">{{cite book|url=https://books.google.com/books?id=E4SFkfsOVaoC&pg=PA188|title=Embedded FreeBSD Cookbook|last=Celovi|first=Paul|publisher=[[Elsevier]]|date=2002|access-date=2022-03-06|pages=108, 187–188|isbn=1-5899-5004-6}}</ref>
<ref name="Computer_2005">{{cite journal|title=The Architecture of Virtual Machines|last1=Smith|first1=James E.|author1-link=James E. Smith (engineer)|last2=Nair|first2=Ravi|journal=[[Computer (magazine)|Computer]]|date=2005-05-16|volume=38|issue=5|pages=33–34|doi=10.1109/MC.2005.173|url=http://digital.library.wisc.edu/1793/11154 }}</ref>
<ref name="Computer_2005">{{cite journal|title=The Architecture of Virtual Machines|last1=Smith|first1=James E.|author1-link=James E. Smith (engineer)|last2=Nair|first2=Ravi|journal=[[Computer (magazine)|Computer]]|date=2005-05-16|volume=38|issue=5|pages=33–34|doi=10.1109/MC.2005.173|url=http://digital.library.wisc.edu/1793/11154 }}</ref>
Line 39: Line 33:
<ref name="Mueller_2007">{{cite book|url=https://books.google.com/books?id=Ua819DVKQPwC&pg=PA24|title=Windows Administration at the Command Line for Windows Vista, Windows 2003, Windows XP, and Windows 2000|last=Mueller|first=John Paul|publisher=[[John Wiley & Sons]]|date=2007|access-date=2023-03-06|page=24|isbn=978-0-470-04616-6}}</ref>
<ref name="Mueller_2007">{{cite book|url=https://books.google.com/books?id=Ua819DVKQPwC&pg=PA24|title=Windows Administration at the Command Line for Windows Vista, Windows 2003, Windows XP, and Windows 2000|last=Mueller|first=John Paul|publisher=[[John Wiley & Sons]]|date=2007|access-date=2023-03-06|page=24|isbn=978-0-470-04616-6}}</ref>
<ref name="MW_2008">{{cite web |url=http://www.merriam-webster.com/dictionary/executable |title=executable |access-date=2008-07-19 |work=Merriam-Webster's Online Dictionary |publisher=[[Merriam-Webster]]}}</ref>
<ref name="MW_2008">{{cite web |url=http://www.merriam-webster.com/dictionary/executable |title=executable |access-date=2008-07-19 |work=Merriam-Webster's Online Dictionary |publisher=[[Merriam-Webster]]}}</ref>
<ref name="Page_2009">{{cite book|url=https://books.google.com/books?id=XH4sIpY1D70C&pg=PA415|title=A Practical Introduction to Computer Architecture|last=Page|first=Daniel|publisher=[[Springer Science+Business Media]]|date=2009|access-date=2023-03-06|pages=415–416|isbn=978-1-84882-255-9}}</ref>
<ref name="Rusling_1999">{{cite book|chapter-url=https://tldp.org/LDP/tlk/kernel/processes.html|chapter=Chapter 4 – Processes|title=The Linux Kernel|last=Rusling|first=David A.|date=1999|access-date=2023-03-06|at=sec. 4.8.1 – ELF}}</ref>
<ref name="Rusling_1999">{{cite book|chapter-url=https://tldp.org/LDP/tlk/kernel/processes.html|chapter=Chapter 4 – Processes|title=The Linux Kernel|last=Rusling|first=David A.|date=1999|access-date=2023-03-06|at=sec. 4.8.1 – ELF}}</ref>
}}
</references>


==External links==
==External links==

Latest revision as of 14:34, 18 November 2025

Template:Short description Script error: No such module "about". Template:Use dmy dates Template:Use list-defined references Template:Program execution

File:Binary executable file2.png
A hex dump of an executable real mode loader. The first column consists of addresses of the first byte in the second column, which comprises bytes of data in hexadecimal notation (least significant byte first), and the last column consists of the corresponding ASCII form.[1]

In computing, an executable is a resource that a computer can use to control its behavior. As with all information in computing, it is data, but distinct from data that does not imply a flow of control.[2] Terms such as executable code, executable file, executable program, and executable image describe forms in which the information is represented and stored. A native executable is machine code and is directly executable at the instruction level of a CPU.[3][4] A script is also executable although indirectly via an interpreter. Intermediate executable code (such as bytecode) may be interpreted or converted to native code at runtime via just-in-time compilation.

Native executable

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 as human readable source code and to automate the generation of machine code via a build toolchain. Today, most source code is a high-level language although it is still possible to use assembly language which is closely associated with machine code instructions. Many toolchains consist of a compiler that generates native code as a set of object files and a linker that generates a native executable from the object and other files. For assembly language, typically the translation tool is called an assembler instead of a compiler.

Object files are typically stored in a digital container format that supports structure in the machine code Template:Endash such as Executable and Linkable Format (ELF) or Portable 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 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.[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 calling main to start and returning exit status to the kernel at the end.[7]

To be executable, a 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.[8] In more complicated interfaces, executable files have additional metadata, which may specify relocations to be performed when the program is loaded, or the entry point address at which to start execution.[9]

See also

References

  1. Script error: No such module "citation/CS1".
  2. Script error: No such module "citation/CS1".
  3. Script error: No such module "citation/CS1".
  4. Script error: No such module "citation/CS1".
  5. Script error: No such module "citation/CS1".
  6. Script error: No such module "citation/CS1".
  7. Script error: No such module "citation/CS1".
  8. Script error: No such module "Citation/CS1".
  9. Script error: No such module "citation/CS1".

External links

Template:Executables