Linking is the process of taking several units of compiled code that would otherwise not be executable alone, and combining them into one unit that can be run.
Also, Linking is the process of taking some smaller executable and joining them together as a single larger executable.
Types of Linking:
1) Static linking
2) Dynamic linking.
Static describes something done before program execution. Static linking occurs at compilation time, hence it occurs prior to loading a program. With static linking the external symbols that are used by your program (e.g. function names) are resolved at compile time.Dynamic describes something done during program execution.
Dynamic linking occurs at run time, so it occurs after or at the time of the loading of a program. With dynamic linking the symbols are resolved either at loading time, or at run time when the symbol is accessed (lazy binding).
A Linker must be able to
* produces an executable file from several object files.
* relocates separately compiled code segments.
* resolves external references.
Loading is part of linking – it’s how to load object files in memory and analyze them as units of data that can eventually be combined into an executable.
Loading is loading the executable into memory prior to execution.
A loader must be able to
* set up text and initialized data in memory
* initialize register copies in the process control block
* initialize the PC copy in the process control block
Dynamic linking and loading has three important benefits:
- Software always uses latest versions of shared libraries.
- Executable files are smaller. They do not include the shared libraries.
- The total memory footprint for multiple processes is reduced. With virtual memory, different programs using the same library function only need a single copy in physical memory. If designed carefully the shared library subprograms can have different logical addresses in different programs.