Partially Linked to Dynamic Linking in C











up vote
2
down vote

favorite












I'm still struggling to understand the core difference between dynamic linking and static linking, below is a picture and sample code from my textbook:



/* main2.c */
#include <stdio.h>
#include "vector.h"

int x[2] = {1, 2};
int y[2] = {3, 4};
int z[2];

int main()
{
addvec(x, y, z, 2);
printf("z = [%d %d]n", z[0], z[1]);
return 0;
}


and libvector.so just a DLL that provides definition needed by main2.c



enter image description here



So my questions are:



Why p2 is a 'partially linked executable object file'? Since it is called 'partially linked', so it must have done some static linking. But since none of the code or data sections from libvector.so or libc.so are actually copied into the executable p2 at this point. So why p2 is still 'partially linked'? Isn't the static linking is about copying code and data sections from objects files, if there is no copy, then there is no static linking involved?










share|improve this question




















  • 1




    The two object files have been incorporated into the executable, along with information about the functions that they call that are, presumably, supplied by the shared objects. Most people would call p2 and executable, and leave the 'partially linked' out of the equation. I suppose it is only partially linked by comparison with what runs after the dynamic loader (linker) has finished, but that's not relevant to most people.
    – Jonathan Leffler
    Nov 8 at 6:49










  • There is only one object file in the partially linked executable itself (main.o)
    – Antti Haapala
    Nov 8 at 7:02










  • @AnttiHaapala: OK — that should have started "The object file has"… Many (most?) programs have more than one object file (though "more than one" often means "more than two", too).
    – Jonathan Leffler
    Nov 8 at 7:20

















up vote
2
down vote

favorite












I'm still struggling to understand the core difference between dynamic linking and static linking, below is a picture and sample code from my textbook:



/* main2.c */
#include <stdio.h>
#include "vector.h"

int x[2] = {1, 2};
int y[2] = {3, 4};
int z[2];

int main()
{
addvec(x, y, z, 2);
printf("z = [%d %d]n", z[0], z[1]);
return 0;
}


and libvector.so just a DLL that provides definition needed by main2.c



enter image description here



So my questions are:



Why p2 is a 'partially linked executable object file'? Since it is called 'partially linked', so it must have done some static linking. But since none of the code or data sections from libvector.so or libc.so are actually copied into the executable p2 at this point. So why p2 is still 'partially linked'? Isn't the static linking is about copying code and data sections from objects files, if there is no copy, then there is no static linking involved?










share|improve this question




















  • 1




    The two object files have been incorporated into the executable, along with information about the functions that they call that are, presumably, supplied by the shared objects. Most people would call p2 and executable, and leave the 'partially linked' out of the equation. I suppose it is only partially linked by comparison with what runs after the dynamic loader (linker) has finished, but that's not relevant to most people.
    – Jonathan Leffler
    Nov 8 at 6:49










  • There is only one object file in the partially linked executable itself (main.o)
    – Antti Haapala
    Nov 8 at 7:02










  • @AnttiHaapala: OK — that should have started "The object file has"… Many (most?) programs have more than one object file (though "more than one" often means "more than two", too).
    – Jonathan Leffler
    Nov 8 at 7:20















up vote
2
down vote

favorite









up vote
2
down vote

favorite











I'm still struggling to understand the core difference between dynamic linking and static linking, below is a picture and sample code from my textbook:



/* main2.c */
#include <stdio.h>
#include "vector.h"

int x[2] = {1, 2};
int y[2] = {3, 4};
int z[2];

int main()
{
addvec(x, y, z, 2);
printf("z = [%d %d]n", z[0], z[1]);
return 0;
}


and libvector.so just a DLL that provides definition needed by main2.c



enter image description here



So my questions are:



Why p2 is a 'partially linked executable object file'? Since it is called 'partially linked', so it must have done some static linking. But since none of the code or data sections from libvector.so or libc.so are actually copied into the executable p2 at this point. So why p2 is still 'partially linked'? Isn't the static linking is about copying code and data sections from objects files, if there is no copy, then there is no static linking involved?










share|improve this question















I'm still struggling to understand the core difference between dynamic linking and static linking, below is a picture and sample code from my textbook:



/* main2.c */
#include <stdio.h>
#include "vector.h"

int x[2] = {1, 2};
int y[2] = {3, 4};
int z[2];

int main()
{
addvec(x, y, z, 2);
printf("z = [%d %d]n", z[0], z[1]);
return 0;
}


and libvector.so just a DLL that provides definition needed by main2.c



enter image description here



So my questions are:



Why p2 is a 'partially linked executable object file'? Since it is called 'partially linked', so it must have done some static linking. But since none of the code or data sections from libvector.so or libc.so are actually copied into the executable p2 at this point. So why p2 is still 'partially linked'? Isn't the static linking is about copying code and data sections from objects files, if there is no copy, then there is no static linking involved?







c linker dynamic-linking






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 8 at 7:26









Antti Haapala

79k16148191




79k16148191










asked Nov 8 at 6:37









amjad

3047




3047








  • 1




    The two object files have been incorporated into the executable, along with information about the functions that they call that are, presumably, supplied by the shared objects. Most people would call p2 and executable, and leave the 'partially linked' out of the equation. I suppose it is only partially linked by comparison with what runs after the dynamic loader (linker) has finished, but that's not relevant to most people.
    – Jonathan Leffler
    Nov 8 at 6:49










  • There is only one object file in the partially linked executable itself (main.o)
    – Antti Haapala
    Nov 8 at 7:02










  • @AnttiHaapala: OK — that should have started "The object file has"… Many (most?) programs have more than one object file (though "more than one" often means "more than two", too).
    – Jonathan Leffler
    Nov 8 at 7:20
















  • 1




    The two object files have been incorporated into the executable, along with information about the functions that they call that are, presumably, supplied by the shared objects. Most people would call p2 and executable, and leave the 'partially linked' out of the equation. I suppose it is only partially linked by comparison with what runs after the dynamic loader (linker) has finished, but that's not relevant to most people.
    – Jonathan Leffler
    Nov 8 at 6:49










  • There is only one object file in the partially linked executable itself (main.o)
    – Antti Haapala
    Nov 8 at 7:02










  • @AnttiHaapala: OK — that should have started "The object file has"… Many (most?) programs have more than one object file (though "more than one" often means "more than two", too).
    – Jonathan Leffler
    Nov 8 at 7:20










1




1




The two object files have been incorporated into the executable, along with information about the functions that they call that are, presumably, supplied by the shared objects. Most people would call p2 and executable, and leave the 'partially linked' out of the equation. I suppose it is only partially linked by comparison with what runs after the dynamic loader (linker) has finished, but that's not relevant to most people.
– Jonathan Leffler
Nov 8 at 6:49




The two object files have been incorporated into the executable, along with information about the functions that they call that are, presumably, supplied by the shared objects. Most people would call p2 and executable, and leave the 'partially linked' out of the equation. I suppose it is only partially linked by comparison with what runs after the dynamic loader (linker) has finished, but that's not relevant to most people.
– Jonathan Leffler
Nov 8 at 6:49












There is only one object file in the partially linked executable itself (main.o)
– Antti Haapala
Nov 8 at 7:02




There is only one object file in the partially linked executable itself (main.o)
– Antti Haapala
Nov 8 at 7:02












@AnttiHaapala: OK — that should have started "The object file has"… Many (most?) programs have more than one object file (though "more than one" often means "more than two", too).
– Jonathan Leffler
Nov 8 at 7:20






@AnttiHaapala: OK — that should have started "The object file has"… Many (most?) programs have more than one object file (though "more than one" often means "more than two", too).
– Jonathan Leffler
Nov 8 at 7:20














1 Answer
1






active

oldest

votes

















up vote
1
down vote













The partially linked executable would have all of the .o object files (here only main.o) linked together, and possibly linking stubs, relocation tables and such to facilitate dynamic linking. The dynamic linker does just the remaining "n %" just before running the program.






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%2f53202594%2fpartially-linked-to-dynamic-linking-in-c%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
    1
    down vote













    The partially linked executable would have all of the .o object files (here only main.o) linked together, and possibly linking stubs, relocation tables and such to facilitate dynamic linking. The dynamic linker does just the remaining "n %" just before running the program.






    share|improve this answer

























      up vote
      1
      down vote













      The partially linked executable would have all of the .o object files (here only main.o) linked together, and possibly linking stubs, relocation tables and such to facilitate dynamic linking. The dynamic linker does just the remaining "n %" just before running the program.






      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        The partially linked executable would have all of the .o object files (here only main.o) linked together, and possibly linking stubs, relocation tables and such to facilitate dynamic linking. The dynamic linker does just the remaining "n %" just before running the program.






        share|improve this answer












        The partially linked executable would have all of the .o object files (here only main.o) linked together, and possibly linking stubs, relocation tables and such to facilitate dynamic linking. The dynamic linker does just the remaining "n %" just before running the program.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 8 at 7:07









        Antti Haapala

        79k16148191




        79k16148191






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53202594%2fpartially-linked-to-dynamic-linking-in-c%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







            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()