What segment is the memory for distributed library functions in?

A way to automatically switch variables / local variables to the stack, dynamically allocated objects / data type go to the heap; where is the memory for calling library functions (for example, printf ()). In which segment?

+4
source share
2 answers

Static join

For a statically linked program, the library code is combined with the application, and almost all the differences between the program and the library are lost, i.e. each object ends in the same section, which will look like a similar object in the main program,

Dynamic linking

For dynamically linked programs, if the object is writable and not automatic, memory pages will be allocated in each process that uses the library, and the data section (or sections) will exist only for dynamically loaded libraries.

Auto

Automatic variables are allocated on the stack in the same way for the main program, statically linked library functions, and dynamic libraries. The linking process has no role in this; rather, the generated code simply subtracts the specific amount from the stack pointer for each routine local requirement for automatic space.

Local non-automatic

Local static variables are allocated by the linker as static and global addresses; they simply do not have globally-connected names.

Heap

Finally, the library routines will contact the same malloc() (or any other), and therefore all heap allocations will be made the same from the same address group.

+5
source

Library functions are not actually processed differently than any other modules that you reference: their local variables use the stack, their dynamically allocated parts of the memory go to heap.

+1
source

All Articles