Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Dynamic linker

From Wikipedia, the free encyclopedia
(Redirected fromLD PRELOAD)
Part of a computer's operating system
This articlerelies excessively onreferences toprimary sources. Please improve this article by addingsecondary or tertiary sources.
Find sources: "Dynamic linker" – news ·newspapers ·books ·scholar ·JSTOR
(March 2011) (Learn how and when to remove this message)

Incomputing, adynamic linker is the part of anoperating system thatloads andlinks theshared libraries needed by anexecutable when it is executed (at "run time"), by copying the content of libraries frompersistent storage toRAM, fillingjump tables and relocatingpointers. The specific operating system and executable format determine how the dynamic linker functions and how it is implemented.

Linking is often referred to as a process that is performed when the executable iscompiled, while a dynamic linker is a special part of an operating system that loads external shared libraries into a runningprocess and thenbinds those shared libraries dynamically to the running process. This approach is also calleddynamic linking orlate linking.

Implementations

[edit]

Microsoft Windows

[edit]
Main article:Dynamic-link library

Dynamic-link library, or DLL, isMicrosoft's implementation of theshared library concept in theMicrosoft Windows andOS/2operating systems. These libraries usually have thefile extensionDLL,OCX (for libraries containingActiveX controls), orDRV (for legacysystem drivers). The file formats for DLLs are the same as for WindowsEXE files – that is,Portable Executable (PE) for32-bit and64-bit Windows, andNew Executable (NE) for16-bit Windows. As with EXEs, DLLs can containcode,data, andresources, in any combination.

Datafiles with the samefile format as a DLL, but with different file extensions and possibly containing only resource sections, can be called resource DLLs. Examples of such DLLs include multi-language user interface libraries with extensionMUI,icon libraries, sometimes having the extensionICL, andfont files, having the extensionsFON andFOT.[1]

Unix-like systems using ELF, and Darwin-based systems

[edit]

In mostUnix-like systems, most of the machine code that makes up the dynamic linker is actually an external executable that the operating systemkernel loads and executes first in a process address space newly constructed as a result of callingexec orposix_spawn functions. At link time, the path of the dynamic linker that should be used is embedded into the executable image.

When an executable file is loaded, the operating system kernel reads the path of the dynamic linker from it and then attempts to load and execute this other executable binary; if that attempt fails because, for example, there is no file with that path, the attempt to execute the original executable fails. The dynamic linker then loads the initial executable image and all the dynamically-linked libraries on which it depends and starts the executable. As a result, the pathname of the dynamic linker is part of the operating system'sapplication binary interface.

Systems using ELF

[edit]

In Unix-like systems that useELF for executable images and dynamic libraries, such asSolaris, 64-bit versions ofHP-UX,Linux,FreeBSD,NetBSD,OpenBSD, andDragonFly BSD, the path of the dynamic linker that should be used is embedded at link time into the.interp section of the executable'sPT_INTERP segment. In those systems, dynamically loaded shared libraries can be identified by the filename suffix.so (shared object).

The dynamic linker can be influenced into modifying its behavior during either the program's execution or the program's linking, and the examples of this can be seen in the run-time linker manual pages for various Unix-like systems.[2][3][4][5][6] A typical modification of this behavior is the use ofLD_LIBRARY_PATH andLD_PRELOADenvironment variables, which adjust the runtime linking process by searching for shared libraries at alternate locations and by forcibly loading and linking libraries that would otherwise not be, respectively. An example is zlibc,[7] also known asuncompress.so,[a] which facilitates transparent decompression when used through theLD_PRELOADhack; consequently, it is possible to read pre-compressed (gzipped) file data on BSD and Linux systems as if the files were not compressed, essentially allowing a user to add transparent compression to the underlying filesystem, although with some caveats. The mechanism is flexible, allowing trivial adaptation of the same code to perform additional or alternate processing of data during the file read, prior to the provision of said data to the user process that has requested it.[8][9]

macOS and iOS

[edit]

In the AppleDarwin operating system, and in themacOS andiOS operating systems built on top of it, the path of the dynamic linker that should be used is embedded at link time into one of theMach-O load commands in the executable image. In those systems, dynamically loaded shared libraries can be identified either by the filename suffix.dylib or by their placement inside thebundle for a framework.

The dynamic linker not only links the target executable to the shared libraries but also places machine code functions at specific address points in memory that the target executable knows about at link time. When an executable wishes to interact with the dynamic linker, it simply executes the machine-specific call or jump instruction to one of those well-known address points. The executables on the macOS and iOS platforms often interact with the dynamic linker during the execution of the process; it is even known that an executable might interact with the dynamic linker, causing it to load more libraries and resolve more symbols, hours after it initially launches. The reason that a macOS or iOS program interacts with the dynamic linker so often is due both to Apple'sCocoa andCocoa Touch APIs andObjective-C, the language in which they are implemented (see their main articles for more information).

The dynamic linker can be coerced into modifying some of its behavior; however, unlike other Unix-like operating systems, these modifications are hints that can be (and sometimes are) ignored by the dynamic linker. Examples of this can be seen indyld's manual page.[10] A typical modification of this behavior is the use of theDYLD_FRAMEWORK_PATH andDYLD_PRINT_LIBRARIES environment variables. The former of the previously-mentioned variables adjusts the executables' search path for the shared libraries, while the latter displays the names of the libraries as they are loaded and linked.

Apple's macOS dynamic linker is an open-source project released as part ofDarwin and can be found in the Apple's open-sourcedyld project.[11]

XCOFF-based Unix-like systems

[edit]

In Unix-like operating systems usingXCOFF, such asAIX, dynamically-loaded shared libraries use the filename suffix.a.

The dynamic linker can be influenced into modifying its behavior during either the program's execution or the program's linking.A typical modification of this behavior is the use of theLIBPATHenvironment variable.This variable adjusts the runtime linking process by searching for shared libraries at alternate locations and by forcibly loading and linking libraries that would otherwise not be, respectively.

OS/360 and successors

[edit]

Dynamic linking from Assembler language programs inIBM OS/360 and its successors is done typically using a LINK macro instruction containing aSupervisor Call instruction that activates the operating system routines that makes the library module to be linked available to the program. Library modules may reside in a "STEPLIB" or "JOBLIB" specified in control cards and only available to a specific execution of the program, in a library included in the LINKLIST in the PARMLIB (specified at system startup time), or in the "link pack area" where specific reentrant modules are loaded at system startup time.

Multics

[edit]

In theMultics operating system all files, including executables, aresegments. A call to a routine not part of the current segment will cause the system to find the referenced segment, in memory or on disk, and add it to the address space of the running process. Dynamic linking is the normal method of operation, and static linking (using thebinder) is the exception.

Efficiency

[edit]

Dynamic linking is generally slower (requires more CPU cycles) than linking during compilation time,[12] as is the case for most processes executed at runtime. However, dynamic linking is often more space-efficient (on disk and in memory at runtime). When a library is linked statically, every process being run is linked with its own copy of the library functions being called upon. Therefore, if a library is called upon many times by different programs, the same functions in that library are duplicated in several places in the system's memory. Using shared, dynamic libraries means that, instead of linking each file to its own copy of a library at compilation time and potentially wasting memory space, only one copy of the library is ever stored in memory at a time, freeing up memory space to be used elsewhere.[13] Additionally, in dynamic linking, a library is only loaded if it is actually being used.[14]

See also

[edit]

Notes

[edit]
  1. ^Not to be confused with thezlib compression library.

References

[edit]
  1. ^Microsoft Corporation."Creating a Resource-Only DLL".Microsoft Developer Network Library.
  2. ^ld.so.1(1): Solaris dynamic linker/loader – Solaris 11.4 User Commands ReferenceManual
  3. ^ld-linux.so(8) – Linux Programmer'sManual – Administration and Privileged Commands
  4. ^rtld(1): FreeBSD dynamic linker/loader – FreeBSD General CommandsManual
  5. ^ld.elf_so(1): NetBSD dynamic linker/loader – NetBSD General CommandsManual
  6. ^ld.so(1): OpenBSD dynamic linker/loader – OpenBSD General CommandsManual
  7. ^"ZLIBC - Transparent access to compressed files". Archived fromthe original on 2000-06-04.
  8. ^"uncompress.so".delorie.com. Retrieved2014-07-04.
  9. ^"zlibc.conf". delorie.com. Retrieved2014-07-04.
  10. ^dyld(1): Darwin/Mac OS X dynamic linker/loader – Darwin andmacOS General CommandsManual
  11. ^Apple Inc."Open Source - Releases". apple.com. Retrieved2014-07-04.
  12. ^Xuxian, Jiang (2009)."Operating Systems Principles: Linking and Loading"(PDF).North Carolina State University. Retrieved2020-09-24.
  13. ^Jones, M. (2008-08-28)."Anatomy of Linux dynamic libraries".IBM. Retrieved2020-09-24.
  14. ^Sivilotti, Paul (August 2012)."Dynamic Linking and Loading"(PDF).Ohio State University. Retrieved2020-09-24.

Further reading

[edit]

External links

[edit]
Parts,
conventions
Related topics
Retrieved from "https://en.wikipedia.org/w/index.php?title=Dynamic_linker&oldid=1264800137#Systems_using_ELF"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp