Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Linker (computing)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Program that combines intermediate build files into an executable 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]] A '''linker''' or '''link editor''' is a [[computer program]] that combines intermediate [[software build]] files such as [[object file|object]] and [[library (computing)|library]] files into a single [[executable]] file such as a program or library. A linker is often part of a [[toolchain]] that includes a [[compiler]] and/or [[assembler (computing)|assembler]] that generates intermediate files that 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"/> == Overview == Computer programs typically are composed of several parts or modules; these parts/modules do not need to be contained within a single [[object file]], and in such cases refer to each other using [[symbol (computing)|symbols]] as addresses into other modules, which are mapped into memory addresses when linked for execution. While the process of linking is meant to ultimately combine these independent parts, there are many good reasons to develop those separately at the [[Source code|source]]-level. Among these reasons are the ease of organizing several smaller pieces over a [[Monolithic codebase|monolithic]] whole and the ability to better define the purpose and responsibilities of each individual piece, which is essential for managing complexity and increasing long-term maintainability in [[software architecture]]. Typically, an object file can contain three kinds of symbols: * defined "external" symbols, sometimes called "public" or "entry" symbols, which allow it to be called by other modules, * undefined "external" symbols, which reference other modules where these symbols are defined, and * local symbols, used internally within the object file to facilitate [[relocation (computer science)|relocation]]. For most compilers, each object file is the result of compiling one input source code file. When a program comprises multiple object files, the linker combines these files into a unified executable program, resolving the symbols as it goes along. Linkers can take objects from a collection called a [[library (computing)|library]] or [[runtime library]]. Most linkers do not include all the object files in a [[static library]] in the output executable; they include only those object files from the library that are referenced by other object files or libraries directly or indirectly. But for a [[shared libraries|shared library]], the entire library has to be loaded during runtime as it is not known which functions or methods will be called during runtime. Library linking may thus be an iterative process, with some referenced modules requiring additional modules to be linked, and so on. Libraries exist for diverse purposes, and one or more system libraries are usually linked in by default. The linker also takes care of arranging the objects in a program's [[address space]]. This may involve ''relocating'' code that assumes a specific [[base address]] into another base. Since a compiler seldom knows where an object will reside, it often assumes a fixed base location (for example, [[zero base|zero]]). Relocating machine code may involve re-targeting absolute jumps, loads, and stores. 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. Additionally, in some operating systems, the same program handles both the jobs of linking and loading a program ([[dynamic linking]]). == Dynamic linking == {{See also|Dynamic linker}} Many [[operating system]] environments allow dynamic linking, deferring the resolution of some undefined symbols until a program is run. That means that the executable code still contains undefined symbols, plus a list of objects or libraries that will provide definitions for these. Loading the program will load these objects/libraries as well, and perform a final linking. This approach offers two advantages: * Often-used libraries (for example the standard system libraries) need to be stored in only one location, not duplicated in every single executable file, thus saving limited [[computer memory|memory]] and [[disk storage|disk]] space. * If a bug in a library function is corrected by replacing the library or [[Computer performance|performance]] is improved, all programs using it dynamically will benefit from the correction after restarting them. Programs that included this function by static linking would have to be re-linked first. There are also disadvantages: * Known on the [[Windows]] platform as "[[DLL hell]]", an incompatible updated library will break executables that depended on the behavior of the previous version of the library if the newer version is not correctly [[backward compatible]]. * A program, together with the libraries it uses, might be certified (e.g. as to correctness, documentation requirements, or performance) as a package, but not if components can be replaced (this also argues against automatic OS updates in critical systems; in both cases, the OS and libraries form part of a ''qualified'' environment). [[Containerization (computing)|Contained]] or [[OS-level virtualization|virtual]] environments may further allow [[System administrator|system administrators]] to mitigate or trade-off these individual pros and cons. == Static linking == Static linking is the result of the linker copying all library routines used in the program into the executable image. This may require more disk space and memory than dynamic linking, but is more portable, since it does not require the presence of the [[dynamic-link library|library]] on the system where it runs. Static linking also prevents "DLL hell", since each program includes exactly the versions of library routines that it requires, with no conflict with other programs. A program using just a few routines from a library does not require the entire library to be installed. == {{Anchor|Relaxation|Jump-sizing}}Relocation == As the compiler has no information on the layout of objects in the final output, it cannot take advantage of shorter or more efficient instructions that place a requirement on the address of another object. For example, a jump instruction can reference an absolute address or an offset from the current location, and the offset could be expressed with different lengths depending on the distance to the target. By first generating the most conservative instruction (usually the largest relative or absolute variant, depending on platform) and adding ''relaxation hints'', it is possible to substitute shorter or more efficient instructions during the final link. In regard to jump optimizations this is also called ''automatic jump-sizing''.<ref name="Salomon_1992"/> This step can be performed only after all input objects have been read and assigned temporary addresses; the '''linker relaxation''' pass subsequently reassigns addresses, which may in turn allow more potential relaxations to occur. In general, the substituted sequences are shorter, which allows this process to always converge on the best solution given a fixed order of objects; if this is not the case, relaxations can conflict, and the linker needs to weigh the advantages of either option. While instruction relaxation typically occurs at link-time, inner-module relaxation can already take place as part of the optimizing process at [[compile-time]]. In some cases, relaxation can also occur at [[load-time]] as part of the relocation process or combined with [[dynamic dead-code elimination]] techniques. == {{anchor|Consolidator}}Linkage editor == In IBM [[System/360]] through [[IBM Z]] [[Mainframe computer|mainframe]] operating systems such as [[OS/360 and successors|OS/360 and its successors]], 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. The term "linkage editor" should not be construed as implying that the program operates in a user-interactive mode like a text editor. It is intended for batch-mode execution, with the editing commands being supplied by the user in sequentially organized files, such as [[punched card]]s, [[direct-access storage device|DASD]], or [[magnetic tape]]. ''Linkage editing'' ([[IBM]] nomenclature) or ''consolidation'' or ''collection'' ([[International Computers Limited|ICL]] nomenclature) refers to the ''linkage editor's'' or ''consolidator's'' act of combining the various pieces into a relocatable binary, whereas the loading and relocation into an absolute binary at the target address is normally considered a separate step.<ref name="Barron_1978_Consolidator"/> == Linker control scripts == 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. == Implementations == Notable implementations: === Unix & Unix-like === On Unix and Unix-like systems, the static linker is usually invoked via the command <code>ld</code> which is an abbreviation of ''LoaDer'' or ''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"/> For example, on [[SINTRAN 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"/> === GNU === GNU ld, part of the [[GNU Binary Utilities]] (binutils), is the [[GNU Project]] version of the Unix static linker. A ''linker script'' may be passed to GNU ld to exercise fine grain control of the linking process.<ref name="GNU_2018_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 [[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== {{Portal|Computer programming|Free and open-source software}} {{Div col|colwidth=20em}} * [[Binary File Descriptor library]] (libbfd) * [[Build (computing)]] * [[Compile and go system]] * [[DLL hell]] * [[Direct binding]] * [[Dynamic binding (computing)|Dynamic binding]] * [[Dynamic dead code elimination]] * [[Dynamic dispatch]] * [[Dynamic library]] * [[Dynamic linker]] * [[Dynamic loading]] * [[Dynamic-link library]] * [[External variable]] * [[Library (computing)|Library]] * [[Loader (computing)|Loader]] * [[Name decoration]] * [[Prelinking]] (prebinding) * [[Relocation (computing)|Relocation]] * [[Smart linking]] * [[Static library]] * [[Gold (linker)]] {{div col end}} == References == {{Reflist|refs= <ref name="IBM_1972">{{cite book |publisher=[[IBM Corporation]] |title=IBM OS Linkage Editor and Loader |date=1972 |url=http://bitsavers.informatik.uni-stuttgart.de/pdf/ibm/360/os/R21.0_Mar72/GC28-6538-9_OS_Linkage_Editor_and_Loader_Release_21_Jan72.pdf |access-date=2020-03-07 |url-status=live |archive-url=https://web.archive.org/web/20200306230227/http://bitsavers.informatik.uni-stuttgart.de/pdf/ibm/360/os/R21.0_Mar72/GC28-6538-9_OS_Linkage_Editor_and_Loader_Release_21_Jan72.pdf |archive-date=2020-03-06}}</ref> <ref name="BRF_1984">{{cite book |title=BRF-LINKER User Manual |id=ND-60.196.01. |date=August 1984}}</ref> <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}}</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> }} == Further reading == * {{cite journal |author-first1=Christopher W. |author-last1=Fraser |author-first2=David R. |author-last2=Hanson |author-link2=David Hanson (computer scientist) |title=A Machine Independent Linker |journal=Software: Practice and Experience |volume=12 |issue=4 |date=April 1982 |publisher=[[John Wiley & Sons Ltd]] |issn=1097-024X |pages=351β366 |doi=10.1002/spe.4380120407 |s2cid=206508204 }} * {{cite book |publisher=[[International Business Machines Corporation]] |title=Operating System 360 - Linkage Editor (E) - Program Logic Manual |id=Program number 360S-ED-510. File No. S360-31. Form Y28-6610-2. |date=1969-07-23 |orig-year=June 1967 |edition=3 |url=http://www.bitsavers.org/pdf/ibm/360/Y28-6610_LinkEdit(E)_PLM.pdf |access-date=2020-03-07 |url-status=dead |archive-url=https://web.archive.org/web/20071001000734/http://www.bitsavers.org/pdf/ibm/360/Y28-6610_LinkEdit(E)_PLM.pdf |archive-date=2007-10-01}} * {{cite journal |author-first=Douglas W. |author-last=Jones |author-link=Douglas W. Jones |title=Assembly Language as Object Code |journal=Software: Practice and Experience |volume=13 |issue=8 |date=August 1983 |publisher=[[John Wiley & Sons Ltd]] |issn=1097-024X |pages=715β725 |doi=10.1002/spe.4380130806 |s2cid=42995338 }} * {{cite book |author-last=Levine |author-first=John R. |author-link=John R. Levine |title=Linkers and Loaders |date=2000 |orig-year=October 1999 |edition=1 |publisher=[[Morgan Kaufmann]] |series=The Morgan Kaufmann Series in Software Engineering and Programming |location=San Francisco, US |isbn=1-55860-496-0 |oclc=42413382 |url=https://www.iecc.com/linker/ |access-date=2020-01-12}} Code: [https://linker.iecc.com/code.html] Errata: [https://linker.iecc.com/] * {{cite journal |author-first1=Leon |author-last1=Presser |author-link1=Leon Presser |author-first2=John R. |author-last2=White |title=Linkers and Loaders |journal=[[ACM Computing Surveys]] |volume=4 |number=3 |location=University of California, Santa Barbara, California, US |date=September 1972 |pages=149β167 |doi=10.1145/356603.356605 |s2cid=5694671 |url=https://inst.eecs.berkeley.edu/~cs162/sp06/hand-outs/p149-presser-linker-loader.pdf |access-date=2020-03-07 |url-status=live |archive-url=https://web.archive.org/web/20200307001527/http://www-inst.eecs.berkeley.edu/~cs162/sp06/hand-outs/p149-presser-linker-loader.pdf |archive-date=2020-03-07}} (19 pages) * {{cite journal |author-first=Norman |author-last=Ramsey |title=Relocating Machine Instructions by Currying |date=May 1996 |url=https://www.cs.tufts.edu/~nr/pubs/relocating.pdf |periodical=ACM SIGPLAN Notices |volume=31 |issue=5 |pages=226β236 |doi=10.1145/249069.231429 |archive-url=https://web.archive.org/web/20200518103430/https://www.cs.tufts.edu/~nr/pubs/relocating.pdf |archive-date=18 May 2020 |url-status=live}} == External links == {{Wiktionary|linker}} * [https://www.google.com/search?q=site%3Awww.airs.com%2Fblog%2Farchives+%22linkers+part%22 Ian Lance Taylor'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] * [https://sourceware.org/binutils/docs/ld/index.html GNU linker manual] * [https://lld.llvm.org/ LLD - The LLVM Linker] * {{man|1|ld|Linux|The GNU linker}} {{Application binary interface}} {{Executables}} {{Unix commands}} {{Authority control}} [[Category:Compilers]] [[Category:Computer libraries]] [[Category:Programming language implementation]] [[Category:Utility software types]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Anchor
(
edit
)
Template:Application binary interface
(
edit
)
Template:Authority control
(
edit
)
Template:Cite book
(
edit
)
Template:Cite journal
(
edit
)
Template:Cite web
(
edit
)
Template:Div col
(
edit
)
Template:Div col end
(
edit
)
Template:Endash
(
edit
)
Template:Executables
(
edit
)
Template:Man
(
edit
)
Template:Portal
(
edit
)
Template:Reflist
(
edit
)
Template:See also
(
edit
)
Template:Short description
(
edit
)
Template:Unix commands
(
edit
)
Template:Use dmy dates
(
edit
)
Template:Vanchor
(
edit
)
Template:Wiktionary
(
edit
)