Dynamic linker

Dynamic linker

In computing, a dynamic linker is the part of an operating system (OS) that loads and links the shared libraries for an executable when it is executed. 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 at compile time of the executable while a dynamic linker is in actuality a special loader that loads external shared libraries into a running process and then binds those shared libraries dynamically to the running process. The specifics of how a dynamic linker functions is operating system dependent.

Contents

Implementations

Microsoft Windows

For the Microsoft Windows platform see the more detailed article titled Dynamic-link library.

ELF-based Unix-like systems

In most Unix-like systems that use ELF for executable images and dynamic libraries, most of the machine code that makes up the dynamic linker is actually an external executable that the operating system kernel loads and executes first in a newly constructed process address space. At compile time an executable has the path of the dynamic linker that should be used embedded into the .interp section. The operating system kernel reads this while creating the new process and in turn loads then executes this other executable binary. That binary then loads the executable image and all the dynamically-linked libraries on which it depends, and starts the executable. In Unix-like operating systems using ELF, dynamically-loaded shared libraries can be identified by the filename suffix .so.

The dynamic linker can be influenced into modifying its behavior during either the program's execution or the program's linking. Examples of this can be seen in the run-time linker manual pages for various Unix-like systems[1][2][3][4][5]. A typical modification of this behavior is the use of the LD_LIBRARY_PATH and LD_PRELOAD environment variables. These variables adjust the runtime linking process by searching for shared libraries at alternative locations and by forcefully loading and linking libraries that would otherwise not be loaded and linked, respectively.

GNU/Linux

The GNU/Linux based operating systems implement a dynamic linker model where a portion of the executable includes a very simple linker stub which causes the operating system to load an external library into memory. This linker stub is added at compile time for the target executable. The linker stub's purpose is to load the real dynamic linker machine code into memory and start the dynamic linker process by executing that newly loaded dynamic linker machine code. While the design of the operating system is to have the executable load the dynamic linker before the target executable's main function is started it however is implemented differently. The operating system knows the location of the dynamic linker and in turn loads that in memory during the process creation. Once the executable is loaded into memory the dynamic linker is already there and linker stub simply executes that code. The reason for this change is due to the fact that ELF binary format was designed for multiple Unix-like operating systems and not just the GNU/Linux operating system.[6]

The source code for the GNU/Linux linker is part of the glibc project and can be downloaded at the GNU website. The entire source code is available under the GNU LGPL.

Mac OS X and iOS

The Apple Darwin operating system, and the Mac OS X and iOS operating systems built atop it, implement a dynamic linker model where most of the machine code that make up the dynamic linker is actually an external executable that the operating system kernel loads and executes first in a newly constructed process address space. At compile time an executable has the path of the dynamic linker that should be used embedded into one of the Mach-O load commands. The operating system kernel reads this while creating the new process and in turn loads then executes this other executable binary. 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. Unlike other operating systems the executables on the Apple Mac OS X platform often interact with the dynamic linker during the execution of the process, it is even known that an executable will interact with the dynamic linker causing it to load more libraries and resolve more symbols hours after the initial launch of the executable. The reason a Mac OS X program interacts with the dynamic linker so often is due to Apple's Cocoa API and the language in which it is implemented, Objective-C. See the Cocoa main article for more information. On the Darwin-based operating systems, the dynamic loaded shared libraries can be identified by either the filename suffix .dylib or by its placement inside the bundle for a framework.

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 with the dyld manual page [7]. A typical modification of this behavior is the use of the DYLD_FRAMEWORK_PATH and DYLD_PRINT_LIBRARIES environment variables. The previously-mentioned variables adjust the executables' search path for the shared libraries, while another displays the names of the libraries as they are loaded and linked.

The source code for Apple's Mac OS X dynamic linker is open source and released as part of Darwin and can be found in the dyld project at Apple's open source web site [8]

See also

References

  1. ^ ld.so.1(1): Solaris dynamic linker/loader – Solaris 10 User Commands Reference Manual
  2. ^ ld-linux.so(8) – Linux Programmer's Manual – Administration and Privileged Commands
  3. ^ rtld(1): FreeBSD dynamic linker/loader – FreeBSD General Commands Manual
  4. ^ ld.elf_so(1): NetBSD dynamic linker/loader – NetBSD General Commands Manual
  5. ^ ld.so(1): OpenBSD dynamic linker/loader – OpenBSD General Commands Manual
  6. ^ Understanding the Linux Kernel, O'REILLY, 3rd Edition, Chapter 20
  7. ^ dyld(1): Darwin/Mac OS X dynamic linker/loader – Darwin and Mac OS X General Commands Manual
  8. ^ http://www.opensource.apple.com/

Wikimedia Foundation. 2010.

Игры ⚽ Нужно сделать НИР?

Look at other dictionaries:

  • Dynamic-link library — This article is about the OS/2 and Windows implementation. For dynamic linking of libraries in general, see Dynamic linker. Dynamic link library Filename extension .dll Internet media type application/x msd …   Wikipedia

  • Dynamic link library — (DLL) bezeichnet allgemein eine Dynamische Bibliothek, meist bezieht sich der Begriff jedoch auf die unter dem Betriebssystem Microsoft Windows verwendete Variante. Windows DLL Dateien verwenden das auch für ausführbare Windows Programme… …   Deutsch Wikipedia

  • Linker — In computer science, a linker or link editor is a program that takes one ormore objects generated by a compiler and assembles them into a single executable program.In IBM mainframe environments such as OS/360 this program is known as a linkage… …   Wikipedia

  • Dynamic Link Library — Vorlage:Infobox Dateiformat/Wartung/MagischeZahl fehltVorlage:Infobox Dateiformat/Wartung/Standard fehltVorlage:Infobox Dateiformat/Wartung/Website fehlt Dynamic Link Library Dateiendung: .dll, .DLL MIME Type …   Deutsch Wikipedia

  • Library (computing) — This article is about the programming concept. For Windows 7 Libraries, see Features new to Windows 7#Libraries. Illustration of an application which uses libvorbisfile to play an Ogg Vorbis file In computer science, a library is a collection of… …   Wikipedia

  • Direct binding — is a feature of the linker and dynamic linker on Solaris and OpenSolaris. It provides a method to allow libraries to directly bind symbols to other libraries, rather than weakly bind to them and leave the dynamic linker to figure out which… …   Wikipedia

  • Portable Executable — Not to be confused with Portable application. Portable Executable Filename extension .cpl, .exe, .dll, .ocx, .sys, .scr, .drv Developed by Microsoft Type of format Binary, executable, object, shared libraries …   Wikipedia

  • Environment variable — Environment variables are a set of dynamic named values that can affect the way running processes will behave on a computer. They can be said in some sense to create the operating environment in which a process runs. For example, an environment… …   Wikipedia

  • Position-independent code — In computing, position independent code (PIC) or position independent executable (PIE) is machine instruction code that executes properly regardless of where in memory it resides. PIC is commonly used for shared libraries, so that the same… …   Wikipedia

  • Objective-C — Paradigm(s) reflective, object oriented Appeared in 1983 Designed by Tom Love Brad Cox Developer Apple Inc. Typing discipline …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”