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.
source share