Logout

6.3.3 Outline the functions of linker, loader and library manager.

(No teaching notes for this one.)

Sample Questions:

2. Outline the function of the linker. [2 marks]

JSR Notes:

Be careful of this one.  It’s pretty straight-forward, but students tend to not quite get the differences. 

Let me start with some webopedia definitions, and then I’ll clarify.

Linker: Also called link editor and binder, a linker is a program that combines object modules to form an executable program. Many programming languages allow you to write different pieces of code, called modules, separately. This simplifies the programming task because you can break a large program into small, more manageable pieces. Eventually, though, you need to put all the modules together. This is the job of the linker.
In addition to combining modules, a linker also replaces symbolic addresses with real addresses. Therefore, you may need to link a program even if it contains only one module.
Since Java works with the virtual machine, it’s a little different than other programming languages, but ,with the Java example, think of all of the classes that you make yourself, and then also all of the other classes that you “link” to when you use System.out.println() and Math.random() etc.  In fact there are dozens of classes that use other classes that you don’t even have to think about because they link behind the scene.  But one way or the other – for all intents and purposes – all of these files have to be linked together to have one full functioning program.

With Java, it is the Java Virtual Machine on the computer that executes the program, where the final linking occurs, but linking is linking, wherever it occurs.

One other point is that what is being combined is object code, not higher level Java, rather compiled object code modules.

And the other point not to miss here is that the linker is indeed part of the operating system.

Loader:
An operating system utility that copies programs from a storage device to main memory, where they can be executed. In addition to copying a program into main memory, the loader can also replace virtual addresses with physical addresses.
Most loaders are transparent, i.e., you cannot directly execute them, but the operating system uses them when necessary.

So, this is quite different from linkers.  Before being loaded, a program will have to be linked together and transferred to a storage device.  The loading, then concerns the where rather than the what.  The “from” is from the secondary storage (whether CD or hard drive etc.), and the “to” is to the RAM.  Something has to do this, and it is the part of the operating system called the loader.  That’s it.

 

Library Manager:  There is no webopedia.com definition for “library manager”, but there is for “library”, and you’ll get the idea by reading it:
In programming, a library is a collection of precompiled routinesthat a program can use. The routines, sometimes called modules, are stored in object format. Libraries are particularly useful for storing frequently used routines because you do not need to explicitly link them to every program that uses them. The linker automatically looks in libraries for routines that it does not find elsewhere. In MS-Windows environments, library files have a .DLL extension.

When you think .dll, you get the picture.  Basically .dll files are files which have certain common modules/routines that are so common, many applications use the same ones.  For example, many applications do all sorts of things with fonts, as they do with colors, so there can be .dll libraries that have pre-made libraries which can be shared by a number of different applications.  In that way those applications don’t have to “re-invent the wheel”, and can just dynamically, i.e. “on-the-fly” link to them rather than linking them all in before, resulting in a much larger application.

BUT, this entirely flies in the face of good OOP concepts.  Rather than programs adopting a fortress mentality, where they look after everything themselves, they end up using other files that could potentially screw things up.  The biggest pitfall can be when you’re all sharing the toothpaste, and little Bobby loses the cap down the toilet.  Woops, that was the analogy.  The biggest pitfall can be when one of the .dll files an application relies on is either lost or damaged.  What often happens in fact is that poorly programmed applications access and screw up the .dll file, and other, more reliable applications get screwed as a side effect.

So, the point is that properly maintaining and managing these shared files becomes an important job of the operating system, that is, unless it’s a Mac, which avoids such problems by avoiding shared libraries.