Understanding dynamic linker











up vote
-2
down vote

favorite












I am wondering why dynamic linker have to search which function in which library.



Can this information be put into elf file by the compile time linker?



If this is done, dynamic linker can find a function directly instead searching.










share|improve this question




















  • 1




    Well that wouldn't be dynamic anymore, would it?
    – Cyber Niki
    Nov 8 at 15:45










  • No. Just linker will know which function in which shared library. Linking still be done run time.
    – overlord
    Nov 8 at 15:51










  • That's literally what dynamic linking does.
    – Cyber Niki
    Nov 8 at 15:55










  • If I say about ld.so; Maps a shared library to excutable address space.If lazy binding is active, when a function is called, linker finds where that function and update the global offset table
    – overlord
    Nov 8 at 16:02












  • You can't just call lazy loading "dynamic linking" and expect anyone to understand what you're talking about. Anyway, the main purpose is to speed up the startup time and reduce memory consumption. Of course calling the function is a bit slower as a tradeoff.
    – Cyber Niki
    Nov 8 at 16:25















up vote
-2
down vote

favorite












I am wondering why dynamic linker have to search which function in which library.



Can this information be put into elf file by the compile time linker?



If this is done, dynamic linker can find a function directly instead searching.










share|improve this question




















  • 1




    Well that wouldn't be dynamic anymore, would it?
    – Cyber Niki
    Nov 8 at 15:45










  • No. Just linker will know which function in which shared library. Linking still be done run time.
    – overlord
    Nov 8 at 15:51










  • That's literally what dynamic linking does.
    – Cyber Niki
    Nov 8 at 15:55










  • If I say about ld.so; Maps a shared library to excutable address space.If lazy binding is active, when a function is called, linker finds where that function and update the global offset table
    – overlord
    Nov 8 at 16:02












  • You can't just call lazy loading "dynamic linking" and expect anyone to understand what you're talking about. Anyway, the main purpose is to speed up the startup time and reduce memory consumption. Of course calling the function is a bit slower as a tradeoff.
    – Cyber Niki
    Nov 8 at 16:25













up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











I am wondering why dynamic linker have to search which function in which library.



Can this information be put into elf file by the compile time linker?



If this is done, dynamic linker can find a function directly instead searching.










share|improve this question















I am wondering why dynamic linker have to search which function in which library.



Can this information be put into elf file by the compile time linker?



If this is done, dynamic linker can find a function directly instead searching.







linker elf






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 8 at 15:44









Neil Butterworth

26.7k54679




26.7k54679










asked Nov 8 at 15:43









overlord

114213




114213








  • 1




    Well that wouldn't be dynamic anymore, would it?
    – Cyber Niki
    Nov 8 at 15:45










  • No. Just linker will know which function in which shared library. Linking still be done run time.
    – overlord
    Nov 8 at 15:51










  • That's literally what dynamic linking does.
    – Cyber Niki
    Nov 8 at 15:55










  • If I say about ld.so; Maps a shared library to excutable address space.If lazy binding is active, when a function is called, linker finds where that function and update the global offset table
    – overlord
    Nov 8 at 16:02












  • You can't just call lazy loading "dynamic linking" and expect anyone to understand what you're talking about. Anyway, the main purpose is to speed up the startup time and reduce memory consumption. Of course calling the function is a bit slower as a tradeoff.
    – Cyber Niki
    Nov 8 at 16:25














  • 1




    Well that wouldn't be dynamic anymore, would it?
    – Cyber Niki
    Nov 8 at 15:45










  • No. Just linker will know which function in which shared library. Linking still be done run time.
    – overlord
    Nov 8 at 15:51










  • That's literally what dynamic linking does.
    – Cyber Niki
    Nov 8 at 15:55










  • If I say about ld.so; Maps a shared library to excutable address space.If lazy binding is active, when a function is called, linker finds where that function and update the global offset table
    – overlord
    Nov 8 at 16:02












  • You can't just call lazy loading "dynamic linking" and expect anyone to understand what you're talking about. Anyway, the main purpose is to speed up the startup time and reduce memory consumption. Of course calling the function is a bit slower as a tradeoff.
    – Cyber Niki
    Nov 8 at 16:25








1




1




Well that wouldn't be dynamic anymore, would it?
– Cyber Niki
Nov 8 at 15:45




Well that wouldn't be dynamic anymore, would it?
– Cyber Niki
Nov 8 at 15:45












No. Just linker will know which function in which shared library. Linking still be done run time.
– overlord
Nov 8 at 15:51




No. Just linker will know which function in which shared library. Linking still be done run time.
– overlord
Nov 8 at 15:51












That's literally what dynamic linking does.
– Cyber Niki
Nov 8 at 15:55




That's literally what dynamic linking does.
– Cyber Niki
Nov 8 at 15:55












If I say about ld.so; Maps a shared library to excutable address space.If lazy binding is active, when a function is called, linker finds where that function and update the global offset table
– overlord
Nov 8 at 16:02






If I say about ld.so; Maps a shared library to excutable address space.If lazy binding is active, when a function is called, linker finds where that function and update the global offset table
– overlord
Nov 8 at 16:02














You can't just call lazy loading "dynamic linking" and expect anyone to understand what you're talking about. Anyway, the main purpose is to speed up the startup time and reduce memory consumption. Of course calling the function is a bit slower as a tradeoff.
– Cyber Niki
Nov 8 at 16:25




You can't just call lazy loading "dynamic linking" and expect anyone to understand what you're talking about. Anyway, the main purpose is to speed up the startup time and reduce memory consumption. Of course calling the function is a bit slower as a tradeoff.
– Cyber Niki
Nov 8 at 16:25












1 Answer
1






active

oldest

votes

















up vote
0
down vote














I am wondering why dynamic linker have to search which function in which library.




As opposed to recording at static link time which shared library the symbol was defined in, and searching only that library, similar to what happens on Windows?



There are a few reasons:




  1. Originally, shared libraries were designed to emulate archive libraries, and it was common to have several archive libraries define the same symbol.

  2. It turns out that not recording the library name allows for symbol interpositioning at runtime, especially with LD_PRELOAD.

  3. In the usual case of a few shared libraries, searching the additional libraries doesn't cost that much (searching is done via hash table, not linearly).


For (1), you could still record the first library the symbol was defined in.



For (3), it turns out that some build systems violate the usual case (with 10,000 shared libraries), and the overhead of searching them all becomes significant. There are ways to avoid that overhead without invalidating the usual symbol lookup rules though.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53211207%2funderstanding-dynamic-linker%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote














    I am wondering why dynamic linker have to search which function in which library.




    As opposed to recording at static link time which shared library the symbol was defined in, and searching only that library, similar to what happens on Windows?



    There are a few reasons:




    1. Originally, shared libraries were designed to emulate archive libraries, and it was common to have several archive libraries define the same symbol.

    2. It turns out that not recording the library name allows for symbol interpositioning at runtime, especially with LD_PRELOAD.

    3. In the usual case of a few shared libraries, searching the additional libraries doesn't cost that much (searching is done via hash table, not linearly).


    For (1), you could still record the first library the symbol was defined in.



    For (3), it turns out that some build systems violate the usual case (with 10,000 shared libraries), and the overhead of searching them all becomes significant. There are ways to avoid that overhead without invalidating the usual symbol lookup rules though.






    share|improve this answer

























      up vote
      0
      down vote














      I am wondering why dynamic linker have to search which function in which library.




      As opposed to recording at static link time which shared library the symbol was defined in, and searching only that library, similar to what happens on Windows?



      There are a few reasons:




      1. Originally, shared libraries were designed to emulate archive libraries, and it was common to have several archive libraries define the same symbol.

      2. It turns out that not recording the library name allows for symbol interpositioning at runtime, especially with LD_PRELOAD.

      3. In the usual case of a few shared libraries, searching the additional libraries doesn't cost that much (searching is done via hash table, not linearly).


      For (1), you could still record the first library the symbol was defined in.



      For (3), it turns out that some build systems violate the usual case (with 10,000 shared libraries), and the overhead of searching them all becomes significant. There are ways to avoid that overhead without invalidating the usual symbol lookup rules though.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote










        I am wondering why dynamic linker have to search which function in which library.




        As opposed to recording at static link time which shared library the symbol was defined in, and searching only that library, similar to what happens on Windows?



        There are a few reasons:




        1. Originally, shared libraries were designed to emulate archive libraries, and it was common to have several archive libraries define the same symbol.

        2. It turns out that not recording the library name allows for symbol interpositioning at runtime, especially with LD_PRELOAD.

        3. In the usual case of a few shared libraries, searching the additional libraries doesn't cost that much (searching is done via hash table, not linearly).


        For (1), you could still record the first library the symbol was defined in.



        For (3), it turns out that some build systems violate the usual case (with 10,000 shared libraries), and the overhead of searching them all becomes significant. There are ways to avoid that overhead without invalidating the usual symbol lookup rules though.






        share|improve this answer













        I am wondering why dynamic linker have to search which function in which library.




        As opposed to recording at static link time which shared library the symbol was defined in, and searching only that library, similar to what happens on Windows?



        There are a few reasons:




        1. Originally, shared libraries were designed to emulate archive libraries, and it was common to have several archive libraries define the same symbol.

        2. It turns out that not recording the library name allows for symbol interpositioning at runtime, especially with LD_PRELOAD.

        3. In the usual case of a few shared libraries, searching the additional libraries doesn't cost that much (searching is done via hash table, not linearly).


        For (1), you could still record the first library the symbol was defined in.



        For (3), it turns out that some build systems violate the usual case (with 10,000 shared libraries), and the overhead of searching them all becomes significant. There are ways to avoid that overhead without invalidating the usual symbol lookup rules though.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 11 at 2:08









        Employed Russian

        121k19163232




        121k19163232






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53211207%2funderstanding-dynamic-linker%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python