EmbLogic's Blog

What is the difference between Dynamic Loading and Dynamic Linking..?

Can any one help in solving this confusion between dynamic loading and dynamic linking. These terms are purely related with .so files I think but I am not getting the exact difference. Any guidance…??

Thank you

5 Responses to What is the difference between Dynamic Loading and Dynamic Linking..?

  1. Sudipto says:

    I guess what you need to understand is the way a program is executed. I am assuming that you are using Linux.

    Dynamic linker is a run time program that loads and binds all of the dynamic dependencies of a program before starting to execute that program. Dynamic linker will find what dynamic libraries a program requires, what libraries those libraries require (and so on), then it will load all those libraries and make sure that all references to functions then correctly point to the right place. For example, even the most basic “hello world” program will usually require the C library to display the output and so the dynamic linker will load the C library before loading the hello world program and will make sure that any calls to printf() go to the right code.

    In fact, not only is it called at program initialisation time, but it may also be called throughout the lifetime of a program to resolve functions known as Lazy Binding.

    Dynamic linker is found in /lib and is usually called something like ld-.so, ld-linux.so.2 (32 bit systems) or ld-linux-x86-64.so.2 (64 bit systems). Although found in /lib, it can actually be executed. At command prompt run

    /lib/ld-linux.so.2

    Dynamic libraries can be shared between different programs saving both filesystem space and run-time memory;
    A single library can have a bug fixed and can then be replaced (e.g. through an over-the-internet download) without replacing the whole program;
    It allows programs and libraries with different license constraints to be used together. For example a proprietary program can be linked with a LGPL library;
    Dynamic libraries can be loaded and unloaded at run-time to provide “plug-in” features.

    at command prompt run the following command and see

    $> readelf -l /bin/bash
    also run this
    $> readelf -d /bin/bash

    probably that should give you some insight into your doubt.

  2. Manoj says:

    Thank u sir, I need to get deeper into these commands output. Still confuse between the naming convention of Dynamic Linker and Dynamic Loader..?

  3. Dynamic linker is actually the part of OS that loads and links (fills jump tables and relocates pointers) the shared libraries needed by 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.

    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.

    • pankaj says:

      basically sir whats the difference between linlkng and loading??

      • vinodh says:

        Loading refers to placing the subroutine into the main memory from secondary. Dynamic Loading means This loading is done only when the subroutine is called i.e. if its not called it wont be loaded. Linking refers to add the reference to dll to the project. It is performed before Execution.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>