previous | start | next

Share Libraries

Shared libraries (.so files in Linux and .dll files in Windows) are loaded dynamically at the beginning or perhaps later in execution. So they are not included directly in the executable file.

Advantages

Take up less disk space.

Take up less memory space during execution.

Less memory space is used if only one copy of the shared library code is loaded into memory when multiple processes are using the library code. The code (but not data) can be shared, right?.

But what about relocation information. Won't it be different for different processes?

  1. Does the shared library code have to be loaded into the same address in each process's address space? (Have the linker/loader fix all missing addresses assuming the library will always be loaded at the same fixed address in each processes address space.)
  2. Make the relocation unnecessary so that it can be loaded anywhere in memory without requiring any modification.

    This is a bit tricky. Code written this way is called position-independent-code (PIC).

The technique for producing PIC is to use indirection. The PIC code refers indirectly to addresses of routines, etc. to use in the shared library through a table. Each process can now have different table values with the correct addresses of where the 1 copy of the shared library is mapped into that process's address space.



previous | start | next