in Operating System
145 views
0 votes
0 votes
Compare Following Points between Static and Dynamic Linking :-

1. Program Startup.

2. Overall Page Fault Rate.
in Operating System
by
145 views

1 Answer

0 votes
0 votes

PROGRAM STARTUP: 

Static linking:

In Non-Shared (static) libraries, since library code is connected at compile time, the final executable has no dependencies on the library at the run time i.e. no additional run-time loading costs, it means that you don’t need to carry along copy of the library that is being used and you have everything under your control and there is no dependency.

(source: https://www.geeksforgeeks.org/gate-gate-cs-2003-question-77/)

Dynamic linking: 

  • One way of implementing dynamic linking: using a jump table.
    • If any of the files being linked are shared libraries, the linker doesn't include the shared library code in the final program. Instead, it includes two things that implement dynamic linking:
      • Jump table: an array in which each entry is a single machine instruction containing an unconditional branch (jump).
        • For each function in a shared library used by the program, there is one entry in the jump table that will jump to the beginning of that function.
      • Dynamic loader: library package invoked at startup to fill in the jump table. → (additional cost)
    • For relocation records referring to functions in the shared library, the linker substitutes the address of the jump table entry: when the function is invoked, the caller will "call" the jump table entry, which redirects the call to the real function.
    • Initially, all jump table entries jump to zero (unresolved).
    • When the program starts up, the dynamic load library is invoked:
      • It invokes the OS mmap functions to load each shared library into memory.→ (additional cost)
      • It fills in the jump table with the correct address for each function in a shared library. → (additional cost)

(source: https://web.stanford.edu/~ouster/cgi-bin/cs140-spring14/lecture.php?topic=linkers)

Overall Page Fault Rate: 

Static:

Static linking combines all the related object files and makes a single executable file. Assume there are many programs that need a common library function “printf()”.  In static linking, every program will contain the object code of the stdio file. This will make all every code in the memory bulky. which may lead to a lack of space for other processes in the memory and they will have to face page faults.

Dynamic: 

In Dynamic linking, all the shared files are loaded separately, only once (not exclusively for each and every program that needs them like in static linking) in the memory and the programs which need one or two functions from those shared libraries can invoke them at the runtime. So more processes can be loaded and the size of these processes is not very huge. So lesser overall page fault rate as a new process can load more pages and hence won’t require frequent page faults. 

Related questions