Need a explantion for understanding

Hi

I could not understanding few points while I was reading this from "Linker and Loader By John R Levine". Below I have put this paragraph and marked the lines for which I need some more explanation.

In the first marked position

If the operating system manages(which I think is not the case now) all the addresses of the shared library at a global address space, then in that case how thing works?

In the second marked position

This is way things are now running.
I have a little knowledge about Mapped files, virtual memory and paging.
That is when the programs is loaded by the loader, then it's divided into logical separate pages(generally 4 or 8 KB), maintained by the page table.
This is case while loading simple program.

What is the case when the DLL gets loaded in relevant to Position independent code?

What relocation means?


Position-independent code

When a program is in use in several different address spaces, the operating system can usually load the program at the same place in each of the address spaces in which it appears. This makes the linker’s job much easier, since it can bind all of the addresses in the program to fixed locations, and no relocation need be done at the time the program is loaded.

Shared libraries complicate this situation considerably.In some simple shared library designs, each library is assigned a globally unique memory address either at system boot time or at the time the libraries are created.This puts the each library at a fixed address, but at the cost of creating a serious ottleneck to shared library administration, since the global list of library memory addresses has to be intained by the system manager.Furthermore, if a new version of a library appears that is larger than the revious version and doesn’t fit into the address space assigned, the entire set of shared libraries and, potentially, all of the programs that reference them, may need to be relinked.

The alternative is to permit different programs to map a library to different places in the address space. This eases library administration, but the compiler, and linker, and program loader need to cooperate so that the library will work regardless of where in the address space the library appears.

One simple approach is to include standard relocation information with the library, and when the library is mapped into each address space, the loader can fix up any relocatable addresses in the program to reflect the loaded addresses. Unfortunately, the process of fixing up involves writing into the library’s code and data, which means that the pages will no longer be shared, if they’re mapped COW, or the program will crash if the pages are mapped RO.

To avoid this problem, shared libraries use Position Independent Code (PIC), code which will work regardless of where in memory it is loaded. All the code in shared libraries is usually PIC, so the code can be mapped read-only. Data pages still usually contain pointers which need relocation, but since data pages are mapped COW anyway, there’s little sharing lost.


Thanks
Last edited on
Topic archived. No new replies allowed.