Linker (computing): Difference between revisions

Content deleted Content added
ce
 
(8 intermediate revisions by 4 users not shown)
Line 1:
{{Short description|ComputerProgram program whichthat combines multipleintermediate objectbuild files into aan singleexecutable file}}
{{Use dmy dates|date=January 2020|cs1-dates=y}}
[[File:Linker.svg|thumb|An illustration of the linking process. Object files and [[static library|static libraries]] are assembled into a new library or executable]]
 
In [[computing]], aA '''linker''' or '''link editor''' is a computer [[System software|systemcomputer program]] that takescombines one or moreintermediate [[objectsoftware filebuild]]s (generatedfiles bysuch aas [[compilerobject file|object]] or anand [[assemblerlibrary (computing)|assemblerlibrary]]) and combines themfiles into a single [[executable]] file, such as a program or library. A linker is often part of a [[librarytoolchain]] that includes a [[compiler]] and/or [[assembler (computing)|libraryassembler]] file,that orgenerates anotherintermediate "object"files filethat the linker processes. The linker may be integrated with other toolchain [[development tool|tools]] such that the user does not interact with the linker directly.
 
A simpler version that writes its [[Input/output|output]] directly to [[Computer memory|memory]] is called the ''loader'', though [[loader (computing)|loading]] is typically considered a separate process.<ref name="IBM_1972"/><ref name="Barron_1978_Consolidator"/>
Line 26:
The executable output by the linker may need another relocation pass when it is finally loaded into memory (just before execution). This pass is usually omitted on [[computer hardware|hardware]] offering [[virtual memory]]: every program is put into its own address space, so there is no conflict even if all programs load at the same base address. This pass may also be omitted if the executable is a [[position independent]] executable.
 
On some [[Unix]] variants, such as [[SINTRAN&nbsp;III]], the process performed by a linker (assembling object files into a program) was called ''[[loader (computing)|loading]]'' (as in loading executable code onto a file).<ref name="BRF_1984"/> Additionally, in some operating systems, the same program handles both the jobs of linking and loading a program ([[dynamic linking]]).
 
== Dynamic linking ==
Line 53:
 
== {{anchor|Consolidator}}Linkage editor ==
In IBM [[System/360]] through [[IBM Z]] [[Mainframe computer|mainframe]] environmentsoperating systems such as [[OS/360]], includingand [[z/successors|OS]]/360 forand theits [[z/Architecturesuccessors]] mainframes, this type of program is known as a ''linkage editor''. As the name implies a linkage ''editor'' has the additional capability of allowing the addition, replacement, and/or deletion of individual program sections. Operating systems such as OS/360 have format for executable load-modules containing supplementary data about the component sections of a program, so that an individual program section can be replaced, and other parts of the program updated so that relocatable addresses and other references can be corrected by the linkage editor, as part of the process.
 
One advantage of this is that it allows a program to be maintained without having to keep all of the intermediate object files, or without having to re-compile program sections that haven't changed. It also permits program updates to be distributed in the form of small files (originally [[card deck (computing)|card deck]]s), containing only the object module to be replaced. In such systems, object code is in the form and format of 80-byte punched-card images, so that updates can be introduced into a system using that medium. In later releases of OS/360 and in subsequent systems, load-modules contain additional data about versions of components modules, to create a traceable record of updates. It also allows one to add, change, or remove an [[overlay (programming)|overlay]] structure from an already linked load module.
Line 64:
In the beginning linkers gave users very limited control over the arrangement of generated output object files. As the target systems became complex with different memory requirements such as embedded systems, it became necessary to give users control to generate output object files with their specific requirements such as defining base addresses' of segments. Linkers control scripts were used for this.
 
== Common implementationsImplementations ==
 
Notable implementations:
On Unix and Unix-like systems, the linker is known as "ld". Origins of the name "ld" are "LoaDer" and "Link eDitor". The term "loader" was used to describe the process of loading external symbols from other programs during the process of linking.<ref name="UNIX_V6_manuals"/>
 
=== GNUUnix linker& Unix-like ===
On Unix and Unix-like systems, the static linker is knownusually asinvoked "ld". Origins ofvia the namecommand "<code>ld"</code> arewhich is an abbreviation of "''LoaDer"'' andor "''Link eDitor"''. The term "loader" was used to describe the process of loading external symbols from other programs during the process of linking.<ref name="UNIX_V6_manuals"/>
The GNU linker (or GNU ld) is the [[GNU Project]]'s [[free software]] implementation of the Unix command ld. GNU ld runs the linker, which creates an executable file (or a library) from object files created during compilation of a software project. A ''linker script'' may be passed to GNU ld to exercise greater control over the linking process.<ref name="GNU_2018_Binutils"/> The GNU linker is part of the [[GNU Binary Utilities]] (binutils). Two versions of ld are provided in binutils: the traditional GNU ld based on [[Binary File Descriptor library|bfd]], and a "streamlined" ELF-only version called [[gold (linker)|gold]].
 
For example, on [[SINTRAN&nbsp;III]], linking (assembling object files into a program) was called <!--do not link to [[loader (computing)]] since that's different-->''loading'' {{endash}} as in loading executable code onto a file.<ref name="BRF_1984"/>
The command-line and linker script syntaxes of GNU ld is the ''de facto'' standard in much of the [[Unix-like]] world. The [[LLVM]] project's linker, ''{{vanchor|lld}}'', is designed to be drop-in compatible,<ref>{{cite web |title=LLD - The LLVM Linker — lld 14 documentation |url=https://lld.llvm.org/ |website=lld.llvm.org}}</ref> and may be used directly with the GNU compiler. Another drop-in replacement, mold, is a highly parallelized and faster alternative which is also supported by GNU tools.<ref>{{cite web |title=GCC 12 Adds Support For Using The Mold Linker |url=https://www.phoronix.com/scan.php?page=news_item&px=GCC-12-Mold-Linker |website=www.phoronix.com}}</ref>
 
=== GNU ===
The GNU linkerld, (orpart of the [[GNU ldBinary Utilities]] (binutils), is the [[GNU Project]]'s [[free software]] implementationversion of the Unix command ld. GNU ld runs thestatic linker, which creates an executable file (or a library) from object files created during compilation of a software project. A ''linker script'' may be passed to GNU ld to exercise greaterfine grain control overof the linking process.<ref name="GNU_2018_Binutils"/> The GNU linker is part of the [[GNU Binary Utilities]] (binutils). Two versions of ld are provided in binutils: the traditional GNU ld based on [[Binary File Descriptor library|bfd]], and a "streamlined" ELF-only version called [[gold (linker)|gold]].
 
The command-line and linker script syntaxes of GNU ld is the ''de facto'' standard in much of the [[Unix-like]] world. The [[LLVM]] project's linker, ''{{vanchor|lld}}'', is designed to be drop-in compatible,<ref>{{cite web |title=LLD - The LLVM Linker — lld 14 documentation |url=https://lld.llvm.org/ |website=lld.llvm.org}}</ref> and may be used directly with the GNU compiler. Another drop-in replacement, mold, is a highly parallelized and faster alternative which is also supported by GNU tools.<ref>{{cite web |title=GCC 12 Adds Support For Using The Mold Linker |url=https://www.phoronix.com/scan.php?page=news_item&px=GCC-12-Mold-Linker |website=www.phoronix.com}}</ref>
 
==See also==
Line 105 ⟶ 110:
<ref name="GNU_2018_Binutils">{{cite web |title=GNU Binutils: Linker Scripts |date=2018-07-18 |url=https://sourceware.org/binutils/docs/ld/Scripts.html |access-date=2019-01-18 |url-status=live |archive-url=https://web.archive.org/web/20200306230349/https://sourceware.org/binutils/docs/ld/Scripts.html |archive-date=2020-03-06}}</ref>
<ref name="UNIX_V6_manuals">{{cite book |title=UNIX PROGRAMMER'S MANUAL |date=May 1975 |edition=6 |chapter=1. ld }}</ref>
<ref name="Barron_1978_Consolidator">{{cite book |author-first=David William |author-last=Barron |author-link=David W. Barron |editor-first=J. John |editor-last=Floretin |title=Assemblers and Loaders |date=1978 |orig-year=1971, 1969 |edition=3 |publisher=[[Elsevier North-Holland Inc.]] |series=Computer Monographs |publication-place=New York, US |___location=[[University of Southampton]], Southampton, UK |isbn=0-444-19462-2 |lccn=78-19961 |chapter=5.7. Linkage editors and consolidators |pages=65–66}} (xii+100 pages)</ref>
<ref name="Salomon_1992">{{cite book |author-first=David |author-last=Salomon |editor-first=Ian D. |editor-last=Chivers |title=Assemblers and Loaders |date=February 1993 |chapter=8.2.3 Automatic jump-sizing |pages=237–238 |orig-year=1992 |edition=1 |series=Ellis Horwood Series In Computers And Their Applications |publisher=[[Ellis Horwood Limited]] / [[Simon & Schuster International Group]] |___location=California State University, Northridge, California, US |publication-place=Chicester, West Sussex, UK |isbn=0-13-052564-2 |chapter-url=http://www.davidsalomon.name/assem.advertis/asl.pdf |access-date=2008-10-01 |url-status=live |archive-url=https://web.archive.org/web/20200323010358/http://www.davidsalomon.name/assem.advertis/asl.pdf |archive-date=2020-03-23}} (xiv+294+4 pages)</ref>
}}
Line 119 ⟶ 124:
== External links ==
{{Wiktionary|linker}}
* [https://www.google.com/search?q=site%3Awww.airs.com%2Fblog%2Farchives+%22linkers+part%22 Ian Lance JustinTaylor's ''Linkers'' blog entries]
* [http://www.linuxjournal.com/article/6463 Linkers and Loaders], a [[Linux Journal]] article by Sandeep Grover
* [https://web.archive.org/web/20060808184333/http://www.dpgraph.com/assembly.html Another Listing of Where to Get a Complete Collection of Free Tools for Assembly Language Development]