When are shared library functions loaded into the heap?What and where are the stack and heap?Which is faster: Stack allocation or Heap allocationHow do function pointers in C work?How do I use extern to share variables between source files?Improve INSERT-per-second performance of SQLite?Difference between static and shared libraries?Issue with threads: value stored in heapInstruction Type and CountIs it possible to identify whether an address reference belongs to static/heap/stack in the process address spaceDeleting a heap variable giving munmap_chunk(): invalid pointer error

Using font to highlight a god's speech in dialogue

Inserting command output into multiline string

Is the mnemonic in Winter's Tale real?

Updating multiple vector points at once with vertex editor in QGIS?

Ways you can end up paying interest on a credit card if you pay the full amount back in due time

Why can't I summon my friend to help me?

Heuristic argument for the Riemann Hypothesis

Meaning of "educating the ice"

Calculate Landau's function

How Total raw is calculated for Science pack 2?

Babies - are we talking about their birth, arrival or delivery?

Received email from ISP saying one of my devices has malware

Why KVM VPS is slower then OPENVZ

Datasets of Large Molecules

Blogging in LaTeX

When making yogurt, why doesn't bad bacteria grow as well?

One hour 10 min layover in Newark; International -> Domestic connection. Enough time to clear customs?

How to check status of Wi-Fi adapter through command line?

Design of 50 ohms RF trace for 2.4GHz...Double layer FR-4 PCB

Function of the separated, individual solar cells on Telstar 1 and 2? Why were they "special"?

If the UK government illegally doesn't ask for article 50 extension, can parliament do it instead?

What is the definition of Product

Tiny image scraper for xkcd.com

Why did the VIC-II and SID use 6 µm technology in the era of 3 µm and 1.5 µm?



When are shared library functions loaded into the heap?


What and where are the stack and heap?Which is faster: Stack allocation or Heap allocationHow do function pointers in C work?How do I use extern to share variables between source files?Improve INSERT-per-second performance of SQLite?Difference between static and shared libraries?Issue with threads: value stored in heapInstruction Type and CountIs it possible to identify whether an address reference belongs to static/heap/stack in the process address spaceDeleting a heap variable giving munmap_chunk(): invalid pointer error






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















(This question concerns only the logical addresses)



I was experimenting with some code where I print out the addresses of different types/scopes of variables to better visualize the process image.



My confusion arose when I printed the addresses a few variables that have been allocated on the heap by malloc, and then also printed the address of the printf function out of curiosity.



What I discovered is that printf was being stored at a much higher address (ie closer to the stack) on the heap than my malloc allocated variables. This doesn't make sense to me because I assumed that the library functions would be loaded on the heap first thing at runtime before any other instructions are executed. I even put a printf statement before any malloc statements, in case library functions were loaded on the fly as they were needed, but it didn't change anything.



Thanks.










share|improve this question



















  • 2





    With virtual memory management, there's no reason to have any expectations about the addresses of the stack, heap, and code. And in fact, Address space layout randomization (ASLR) is specifically designed to foil attempts at predicting address relationships.

    – user3386109
    Mar 28 at 2:05

















1















(This question concerns only the logical addresses)



I was experimenting with some code where I print out the addresses of different types/scopes of variables to better visualize the process image.



My confusion arose when I printed the addresses a few variables that have been allocated on the heap by malloc, and then also printed the address of the printf function out of curiosity.



What I discovered is that printf was being stored at a much higher address (ie closer to the stack) on the heap than my malloc allocated variables. This doesn't make sense to me because I assumed that the library functions would be loaded on the heap first thing at runtime before any other instructions are executed. I even put a printf statement before any malloc statements, in case library functions were loaded on the fly as they were needed, but it didn't change anything.



Thanks.










share|improve this question



















  • 2





    With virtual memory management, there's no reason to have any expectations about the addresses of the stack, heap, and code. And in fact, Address space layout randomization (ASLR) is specifically designed to foil attempts at predicting address relationships.

    – user3386109
    Mar 28 at 2:05













1












1








1








(This question concerns only the logical addresses)



I was experimenting with some code where I print out the addresses of different types/scopes of variables to better visualize the process image.



My confusion arose when I printed the addresses a few variables that have been allocated on the heap by malloc, and then also printed the address of the printf function out of curiosity.



What I discovered is that printf was being stored at a much higher address (ie closer to the stack) on the heap than my malloc allocated variables. This doesn't make sense to me because I assumed that the library functions would be loaded on the heap first thing at runtime before any other instructions are executed. I even put a printf statement before any malloc statements, in case library functions were loaded on the fly as they were needed, but it didn't change anything.



Thanks.










share|improve this question














(This question concerns only the logical addresses)



I was experimenting with some code where I print out the addresses of different types/scopes of variables to better visualize the process image.



My confusion arose when I printed the addresses a few variables that have been allocated on the heap by malloc, and then also printed the address of the printf function out of curiosity.



What I discovered is that printf was being stored at a much higher address (ie closer to the stack) on the heap than my malloc allocated variables. This doesn't make sense to me because I assumed that the library functions would be loaded on the heap first thing at runtime before any other instructions are executed. I even put a printf statement before any malloc statements, in case library functions were loaded on the fly as they were needed, but it didn't change anything.



Thanks.







c memory heap






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 28 at 1:51









Luke4211Luke4211

143 bronze badges




143 bronze badges










  • 2





    With virtual memory management, there's no reason to have any expectations about the addresses of the stack, heap, and code. And in fact, Address space layout randomization (ASLR) is specifically designed to foil attempts at predicting address relationships.

    – user3386109
    Mar 28 at 2:05












  • 2





    With virtual memory management, there's no reason to have any expectations about the addresses of the stack, heap, and code. And in fact, Address space layout randomization (ASLR) is specifically designed to foil attempts at predicting address relationships.

    – user3386109
    Mar 28 at 2:05







2




2





With virtual memory management, there's no reason to have any expectations about the addresses of the stack, heap, and code. And in fact, Address space layout randomization (ASLR) is specifically designed to foil attempts at predicting address relationships.

– user3386109
Mar 28 at 2:05





With virtual memory management, there's no reason to have any expectations about the addresses of the stack, heap, and code. And in fact, Address space layout randomization (ASLR) is specifically designed to foil attempts at predicting address relationships.

– user3386109
Mar 28 at 2:05












1 Answer
1






active

oldest

votes


















3















(This answer concerns Unix only. I don't know how it is on Windows.)



Most shared libraries are loaded into RAM before control reaches main, and the library containing printf definitely will be. The functions in dlfcn.h can be used to load more shared libraries during execution of the program, that's the most important exception.



Shared libraries have never been loaded as part of the "heap", if by that you mean the region of memory used to satisfy malloc requests. They are loaded using the system primitive mmap, and could be placed anywhere at all in memory. As user3386109 pointed out in a comment on the question, on modern systems, their locations are intentionally randomized as a countermeasure for various exploits.






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',
    autoActivateHeartbeat: false,
    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%2f55389035%2fwhen-are-shared-library-functions-loaded-into-the-heap%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









    3















    (This answer concerns Unix only. I don't know how it is on Windows.)



    Most shared libraries are loaded into RAM before control reaches main, and the library containing printf definitely will be. The functions in dlfcn.h can be used to load more shared libraries during execution of the program, that's the most important exception.



    Shared libraries have never been loaded as part of the "heap", if by that you mean the region of memory used to satisfy malloc requests. They are loaded using the system primitive mmap, and could be placed anywhere at all in memory. As user3386109 pointed out in a comment on the question, on modern systems, their locations are intentionally randomized as a countermeasure for various exploits.






    share|improve this answer





























      3















      (This answer concerns Unix only. I don't know how it is on Windows.)



      Most shared libraries are loaded into RAM before control reaches main, and the library containing printf definitely will be. The functions in dlfcn.h can be used to load more shared libraries during execution of the program, that's the most important exception.



      Shared libraries have never been loaded as part of the "heap", if by that you mean the region of memory used to satisfy malloc requests. They are loaded using the system primitive mmap, and could be placed anywhere at all in memory. As user3386109 pointed out in a comment on the question, on modern systems, their locations are intentionally randomized as a countermeasure for various exploits.






      share|improve this answer



























        3














        3










        3









        (This answer concerns Unix only. I don't know how it is on Windows.)



        Most shared libraries are loaded into RAM before control reaches main, and the library containing printf definitely will be. The functions in dlfcn.h can be used to load more shared libraries during execution of the program, that's the most important exception.



        Shared libraries have never been loaded as part of the "heap", if by that you mean the region of memory used to satisfy malloc requests. They are loaded using the system primitive mmap, and could be placed anywhere at all in memory. As user3386109 pointed out in a comment on the question, on modern systems, their locations are intentionally randomized as a countermeasure for various exploits.






        share|improve this answer













        (This answer concerns Unix only. I don't know how it is on Windows.)



        Most shared libraries are loaded into RAM before control reaches main, and the library containing printf definitely will be. The functions in dlfcn.h can be used to load more shared libraries during execution of the program, that's the most important exception.



        Shared libraries have never been loaded as part of the "heap", if by that you mean the region of memory used to satisfy malloc requests. They are loaded using the system primitive mmap, and could be placed anywhere at all in memory. As user3386109 pointed out in a comment on the question, on modern systems, their locations are intentionally randomized as a countermeasure for various exploits.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 28 at 2:13









        zwolzwol

        104k27 gold badges184 silver badges287 bronze badges




        104k27 gold badges184 silver badges287 bronze badges





















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55389035%2fwhen-are-shared-library-functions-loaded-into-the-heap%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

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해