Share to: share facebook share twitter share wa share telegram print page

Linker (computing)

An illustration of the linking process. Object files and static libraries are assembled into a new library or executable

In computing, a linker or link editor is a computer system program that takes one or more object files (generated by a compiler or an assembler) and combines them into a single executable file, library file, or another "object" file.

A simpler version that writes its output directly to memory is called the loader, though loading is typically considered a separate process.[1][2]

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 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-level. Among these reasons are the ease of organizing several smaller pieces over a 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.

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 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 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). 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 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 III, the process performed by a linker (assembling object files into a program) was called loading (as in loading executable code onto a file).[3] Additionally, in some operating systems, the same program handles both the jobs of linking and loading a program (dynamic linking).

Dynamic linking

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 memory and disk space.
  • If a bug in a library function is corrected by replacing the library or 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).

Contained or virtual environments may further allow 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 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.

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.[4] 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.

Linkage editor

In IBM System/360 mainframe environments such as OS/360, including z/OS for the z/Architecture 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 decks), 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 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 cards, DASD, or magnetic tape.

Linkage editing (IBM nomenclature) or consolidation or collection (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.[2]

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.

Common 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.[5]

GNU linker

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.[6] 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 bfd, and a "streamlined" ELF-only version called 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, lld, is designed to be drop-in compatible,[7] 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.[8]

See also

References

  1. ^ IBM OS Linkage Editor and Loader (PDF). IBM Corporation. 1972. Archived (PDF) from the original on 2020-03-06. Retrieved 2020-03-07.
  2. ^ a b Barron, David William (1978) [1971, 1969]. "5.7. Linkage editors and consolidators". Written at University of Southampton, Southampton, UK. In Floretin, J. John (ed.). Assemblers and Loaders. Computer Monographs (3 ed.). New York, US: Elsevier North-Holland Inc. pp. 65–66. ISBN 0-444-19462-2. LCCN 78-19961. (xii+100 pages)
  3. ^ BRF-LINKER User Manual. August 1984. ND-60.196.01.
  4. ^ Salomon, David (February 1993) [1992]. "8.2.3 Automatic jump-sizing" (PDF). Written at California State University, Northridge, California, US. In Chivers, Ian D. (ed.). Assemblers and Loaders. Ellis Horwood Series In Computers And Their Applications (1 ed.). Chicester, West Sussex, UK: Ellis Horwood Limited / Simon & Schuster International Group. pp. 237–238. ISBN 0-13-052564-2. Archived (PDF) from the original on 2020-03-23. Retrieved 2008-10-01. (xiv+294+4 pages)
  5. ^ "1. ld". UNIX PROGRAMMER'S MANUAL (6 ed.). May 1975.
  6. ^ "GNU Binutils: Linker Scripts". 2018-07-18. Archived from the original on 2020-03-06. Retrieved 2019-01-18.
  7. ^ "LLD - The LLVM Linker — lld 14 documentation". lld.llvm.org.
  8. ^ "GCC 12 Adds Support For Using The Mold Linker". www.phoronix.com.

Further reading

Read other articles:

Johann Martin Chladenius Johann Martin Chladni latinizzato Chladenius (Lutherstadt Wittenberg, 17 aprile 1710 – Erlangen, 10 settembre 1759) è stato un teologo e storico tedesco che nell'ambito del razionalismo settecentesco di Gottfried Leibniz e Christian Wolff, è considerato il fondatore di una nuova ermeneutica che nella sua opera Einleitung zur richtigen Auslegung vernünftiger Reden und Schriften (Guida alla retta interpretazione di scritti ragionevoli) , egli definisce come hermene...

This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Legend of Fragrance – news · newspapers · books · scholar · JSTOR (June 2020) (Learn how and when to remove this template message)Chinese TV series or program Legend of FragranceAlso known asButterfly FragranceGenreRomanceMelodramaRepublicanWritten byLin Y...

Artikel ini tidak memiliki referensi atau sumber tepercaya sehingga isinya tidak bisa dipastikan. Tolong bantu perbaiki artikel ini dengan menambahkan referensi yang layak. Tulisan tanpa sumber dapat dipertanyakan dan dihapus sewaktu-waktu.Cari sumber: SMA Negeri 34 Jakarta – berita · surat kabar · buku · cendekiawan · JSTOR SMA Negeri 34 JakartaInformasiDidirikan13 September 1978JenisNegeriAkreditasiANomor Statistik Sekolah301016307051Nomor Pokok Seko...

Cet article est une ébauche concernant le droit et la Première Guerre mondiale. Vous pouvez partager vos connaissances en l’améliorant (comment ?) selon les recommandations des projets correspondants. Première séance, le 23 mai 1921. Le procès de Leipzig est une série de procès qui ont lieu en 1921, intentés contre des criminels de guerre allemands de la Première Guerre mondiale. Il se déroule au tribunal impérial de Leipzig. Il fait partie des pénalités imposées au gouv...

Hutan bakau di Muara Angke, Jakarta (2007) Salah Satu Penampakan Hutan Bakau Teluk Kendari Tahun 2013. Hutan bakau di Zambia, Afrika. Berkas:Hutan Bakau di Pesisir, Sumatera Barat 04.jpgHutan Bakau Di Sekitar Kawasan Wisata Mandeh, Sumatera Barat. Hutan Bakau Di Sekitar Kawasan Wisata Mandeh, Sumatera Barat. Hutan bakau (bahasa Inggris: mangrove) adalah hutan yang tumbuh di air payau, dan dipengaruhi oleh pasang-surut air laut.[1] Hutan ini tumbuh khususnya di tempat-tempat di man...

Bài viết này là một bài mồ côi vì không có bài viết khác liên kết đến nó. Vui lòng tạo liên kết đến bài này từ các bài viết liên quan; có thể thử dùng công cụ tìm liên kết. (tháng 7 năm 2018) Bài viết này cần thêm chú thích nguồn gốc để kiểm chứng thông tin. Mời bạn giúp hoàn thiện bài viết này bằng cách bổ sung chú thích tới các nguồn đáng tin cậy. Các nội dung không có nguồn có...

Brazilian TV series or program Éramos SeisAlso known asOnce We Were SixGenreTelenovelaCreated byÂngela ChavesBased onÉramos Seisby Maria José DupréWritten by Bernardo Guilherme Daisy Chaves Juliana Peres Directed by Pedro Peregrino Carlos Araújo Starring Glória Pires Danilo Mesquita Nicolas Prattes Giullia Buscacio André Luiz Frambach Cássio Gabus Mendes Simone Spoladore Ricardo Pereira Joana de Verona Carol Macedo Paulo Rocha Rayssa Bratillieri Susana Vieira Maria Eduarda de Ca...

مايكل نيمان (بالإنجليزية: Michael Laurence Nyman)‏  معلومات شخصية الميلاد 23 مارس 1944 (العمر 79 سنة)Stratford الجنسية إنجلترا الحياة العملية المدرسة الأم الأكاديمية الملكية للموسيقىكلية كينغز لندن  المهنة ملحن[1]،  ومختص بالموسيقى،  وعازف بيانو،  ومؤلف موسيقى تصويرية،  وم

Municipio de Upper Merion Municipio Municipio de Upper Merion Ubicación de Pensilvania en EE. UU.Coordenadas 40°05′00″N 75°20′59″O / 40.083333333333, -75.349722222222Entidad Municipio • País Estados Unidos • Estado  Pensilvania • Condado MontgomerySuperficie   • Total 44.5 km² • Tierra 44.0 km² • Agua (2,3%) 1,0 km²Altitud   • Media 52.1 m s. n. m.Población (2000)   • Total 26...

1974 strategy board wargame Box cover of original Gamma Two edition, 1974 Napoleon, subtitled The Waterloo Campaign, 1815, is a strategic-level block wargame published by Gamma Two Games in 1974 that simulates the Battle of Waterloo. A number of versions of the game have been produced by Avalon Hill and Columbia Games. Description Instead of cardboard counters, military units are represented by square blocks. The blocks are marked on one side by the unit designation; at the start of the game,...

Australian rules footballer Australian rules footballer Ben Kennedy Kennedy at training in November 2015Personal informationFull name Benjamin KennedyDate of birth (1994-03-03) 3 March 1994 (age 29)Original team(s) Glenelg (SANFL)Draft No. 19, 2012 national draftDebut Round 6, 2013, Collingwood vs. St Kilda, at MCGHeight 175 cm (5 ft 9 in)Weight 78 kg (172 lb)Position(s) Forward / midfielderPlaying career1Years Club Games (Goals)2013–2015 Collingw...

United States federal district court in Texas United States District Court for the Western District of Texas(W.D. Tex.)LocationSan AntonioMore locationsUnited States Courthouse(Austin)AlpineDel RioEl PasoFort CavazosMidlandPecosWacoAppeals toFifth CircuitEstablishedFebruary 21, 1857Judges13Chief JudgeAlia MosesOfficers of the courtU.S. AttorneyJaime E. EsparzaU.S. MarshalSusan Pamerleauwww.txwd.uscourts.gov The United States District Court for the Western District of Texas...

Division of the US National Aeronautics and Space Administration (NASA) which trains astronauts NASA space suits previously worn by the Astronaut Corps at the Johnson Space Center (center, Pete Conrad's suit worn during the 1969 Apollo 12 mission) Part of a series on theUnited States space program NASAU.S. Space Force Human spaceflight programs Mercury Gemini Apollo Skylab Space Shuttle Shuttle–Mir International Space Station Commercial Crew Constellation Artemis Lunar Gateway Robotic space...

Illustration von Carl Fahringer (1874–1952) Illustration von Otto Ubbelohde, 1909 Der Wolf und die sieben jungen Geißlein (oft nur Der Wolf und die sieben Geißlein) ist ein bekanntes Tiermärchen (ATU 123). Es steht in den Kinder- und Hausmärchen der Brüder Grimm an Stelle 5 (KHM 5) und ist ab der 5. Auflage beeinflusst durch Die sieben Gaislein in August Stöbers Elsässisches Volksbüchlein (1842, Nr. 242). Ludwig Bechstein übernahm es ebenfalls nach Stöber in sein Deutsches Märche...

هذه المقالة يتيمة إذ تصل إليها مقالات أخرى قليلة جدًا. فضلًا، ساعد بإضافة وصلة إليها في مقالات متعلقة بها. (يوليو 2019) بوس بيلي   معلومات شخصية الميلاد 14 أكتوبر 1979 (44 سنة)  فولكستون  مواطنة الولايات المتحدة  الطول 75 بوصة  الوزن 232 رطل  الحياة العملية المهنة لاعب ك...

Gold Coast-born American educator James Emman Kwegyir AggreyBorn(1875-10-18)18 October 1875Gold CoastDied30 July 1927(1927-07-30) (aged 51)NationalityGhanaianEducationWesleyan High SchoolLivingstone CollegeColumbia UniversityOccupation(s)Missionary and teacher James Emman Kwegyir Aggrey (18 October 1875 – 30 July 1927) was an intellectual, missionary, and teacher. He was born in the Gold Coast (modern Ghana) and later emigrated to the United States, but returned to Africa for several y...

Entrance gate of Wing Lung Wai. Central axis of Wing Lung Wai, with the Chung Shing Temple at the end. Chung Shing Temple is the village shrine of Wing Lung Wai. Kang Sam Tong in Wing Lung Wai. Wing Lung Wai (Chinese: 永隆圍; lit. 'Perpetuating Prosperity') is a walled village located in the Kam Tin area of Yuen Long District, in Hong Kong. Three other walled villages, Kat Hing Wai, Tai Hong Wai, and Kam Hing Wai are located nearby and were built around the same time.[1]...

This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Sandakan Harbour Square – news · newspapers · books · scholar · JSTOR (March 2022) (Learn how and when to remove this template message) Development in Sabah Malaysia Sandakan Harbour SquareProjectConstruction started2003Completed2012StatusCompletedDeveloperICSD...

Not to be confused with Kernel principal component analysis or Kernel ridge regression. Technique in statistics In statistics, kernel regression is a non-parametric technique to estimate the conditional expectation of a random variable. The objective is to find a non-linear relation between a pair of random variables X and Y. In any nonparametric regression, the conditional expectation of a variable Y {\displaystyle Y} relative to a variable X {\displaystyle X} may be written: E ⁡ ( Y ...

American basketball player (1990-) Mikaela RuefNo. 12 – Canberra CapitalsPositionForwardLeagueWNBLPersonal informationBorn (1990-10-20) 20 October 1990 (age 33)Dayton, OhioNationalityAmericanListed height6 ft 3 in (1.91 m)Career informationHigh schoolBeavercreek (Beavercreek, Ohio)CollegeStanford (2009–2014)WNBA draft2014: 3rd round, 31st overall pickSelected by the Seattle StormPlaying career2014–presentCareer history2014–2015Sydney Uni Flames2015–2016Ad...

Kembali kehalaman sebelumnya