0
23kviews
What is the difference between Dynamic Loading and Dynamic Linking explain with an example

Mumbai University > Computer > Sem 6 > System programming and compiler construction

Marks: 10

Years:May 2016

1 Answer
0
283views

Dynamic Loading

Dynamic loading refers to mapping (or less often copying) an executable or library into a process's memory after is has started.

Dynamic linking refers to resolving symbols - associating their names with addresses or offsets - after compile time.

The reason it's hard to make a distinction is that the two are often done together without recognizing the subtle distinctions around the parts I put in bold.

Perhaps the clearest way to explain is to go through what the different combinations would mean in practice.

• Dynamic loading, static linking.

The executable has an address/offset table generated at compile time, but the actual code/data aren't loaded into memory at process start. This is not the way things tend to work in most systems nowadays, but it would describe some old-fashioned overlay systems. I'd also be utterly unsurprised if some current embedded systems work this way too. In either case, the goal is to give the programmer control over memory use while also avoiding the overhead of linking at runtime.

• Static loading, dynamic linking.

This is how dynamic libraries specified at compile time usually work. The executable contains a reference to the dynamic/shared library, but the symbol table is missing or incomplete. Both loading and linking occur at process start, which is considered "dynamic" for linking but not for loading.

• Dynamic loading, dynamic linking.

This is what happens when you call dlopen or its equivalent on other systems. The object file is loaded dynamically under program control (i.e. after start), and symbols both in the calling program and in the library are resolved based on the process's possibly-unique memory layout at that time.

• Static loading, static linking.

Everything is resolved at compile time. At process start everything is loaded into memory immediately and no extra resolution (linking) is necessary. In the abstract it's not necessary for the loading to occur from a single file, but I don't think the actual formats or implementations (at least those I'm familiar with) can do multi-file loading without dynamic linking.

Dynamic Linking Loader:

• Dynamic Linking Loader is a general re-locatable loader.

• Allowing the programmer multiple procedure segments and multiple data segments and giving programmer complete freedom in referencing data or instruction contained in other segments.

• The assembler must give the loader the following information with each procedure or data segment.

• Dynamic linking defers much of the linking process until a program starts running. It provides a variety of benefits that are hard to get otherwise:

• Dynamically linked shared libraries are easier to create than static linked shared libraries.

• Dynamically linked shared libraries are easier to update than static linked shared libraries.

• The semantics of dynamically linked shared libraries can be much closer to those of unshared libraries.

• Dynamic linking permits a program to load and unload routines at runtime, a facility that can otherwise be very difficult to provide.

enter image description here

Please log in to add an answer.