Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!shadooby!samsung!munnari.oz.au!mimir!hugin!augean!idall From: idall@augean.OZ (Ian Dall) Newsgroups: comp.unix.wizards Subject: Shared Libraries Message-ID: <656@augean.OZ> Date: 15 Nov 89 04:47:44 GMT Reply-To: idall@augean.OZ (Ian Dall) Organization: Engineering Faculty, University of Adelaide, Australia Lines: 42 Share libraries seem to me a really neat idea. The implimentation, however, also seems non trivial. I was wondering how they could be implimented and had a look at the SunOs 4 man page for ld(1). They mention that the shared libraries are linked at run time by crt0.o "invoking" ld.so. I am wondering how this really works. Is ld.so itself a shared object? If so how does crt0.o get to "invoke" it before ld.so has been executed? i.e. How do we bootstrap the process? Secondly, does the runtime linking only involve relocation or is the actual code copied from the .so file to the processes address space as well? The latter scheme would have the disadvantage that the process text space would not really be shared (there would be multiple copies of the library code in core or swap space) and start up might be slow. It would seem to be better if the library was mapped into the process virtual address space and demand paged out of the .so file. This might be difficult to arrange without using up a lot of virtual address space. Mapping the whole library (whether or not it is all used) clearly uses up a lot of virtual address space and mapping each function referenced would waste fragments of a page (average 1 per function) since the functions do not start and finish on a page boundary, although is would be possible to align the start of the functions in the .so file to page boundaries reducing the average size of the unused page fragments to 0.5 pages per funtion. The only other scheme I can think of off the top of my head, would involve the functions being replaced by stubs which requested the kernel to remap a region of the virtual address space. This implies a system call per funtion call which might not be too bad for a lot of libc funtions which do system calls anyway, but would be a significant overhead for (say) maths libraries. Anyway, can anyone elaborate on a) how SunOs does shared libraries, b) how SysV does shared libraries and c) any better schemes. -- Ian Dall life (n). A sexually transmitted disease which afflicts some people more severely than others. idall@augean.oz