Tuesday 23 September 2014

SPO600: Static linking vs. Dynamic linking

Linker as a system program takes relocatable object files and command line arguments in order to generate an executable object file. The linker is responsible for locating individual parts of the object files in the executable image, ensuring that all the required code and data is available to the image and any addresses required are handled correctly.




Static and dynamic linking are two processes of collecting and combining multiple object files in order to create a single executable. 

Static linking is the process of copying all library modules used in the program into the final executable image. This is performed by the linker and it is done as the last step of the compilation process.

During dynamic linking the name of the shared library is placed in the final executable file while the actual linking takes place at run time when both executable file and library are placed in the memory.

Differences between Static linking and Dynamic linking:

Static linking
Dynamic linking
Sharing external program
External called program cannot be shared. It requires duplicate copies of programs in memory.
Dynamic linking lets several programs use a single copy of an executable module.
File size
Statically linked files are significantly larger in size because external programs are built into the executable files.
Dynamic linking significantly reduces the size of executable programs because it uses only one copy of shared library
Easiness to update
In static linking if any of the external programs has changed then they have to be recompiled and re-linked again else the changes won't reflect in existing executable file.
In dynamic linking individual shared modules and bug fixes can be updated and recompiled.
Speed
Programs that use statically-linked libraries are usually faster than those that use shared libraries.
Programs that use shared libraries are usually slower than those that use statically-linked libraries.
Compati-bility
In statically-linked programs, all code is contained in a single executable module. Therefore, they never run into compatibility issues.
Dynamically linked programs are dependent on having a compatible library. If a library is changed, applications might have to be reworked to be made compatible with the new version of the library.

Advantages:

Static linking
Dynamic linking
      Static linking is efficient at run time.
      It has less system calls.
      Static linking can make binaries easier to distribute to diverse user environment.
      It let the code run in very limited environments.
      Dynamic linking is more flexible.
      It is more efficient in resource utilization, taking less memory space, cache space and disk space.
      It is easy to update and fix the bugs.
Static linking
Dynamic linking
Source:




No comments:

Post a Comment