Dynamically linked shared libraries are an important aspect of GNU/Linux. They allow executables to dynamically access external functionality at run time and thereby reduce their overall memory footprint. This article investigates the process of creating and using dynamic libraries, provides details on the various tools for exploring them, and explores how these libraries work under the hood.
Anatomy of Linux Dynamic Libraries
2008-08-26 Linux 4 Comments
I really appreciate articles such as this, since I don’t have the shelf-space (or the funds!) to build a comprehensive library on how to program in Linux
I’ve had a detailed look at 2 binary formats over the years, both ELF and Microsoft’s PE.
PE doesn’t generate position-independent code, so it’s slightly faster than ELF since eg. the EBX register is available to x86 applications to use. However each DLL has to be loaded at a particular location in memory, and that location cannot change after the DLL is loaded, so if that memory region is unavailable in a new process, the DLL has to be “rebased”, ie. a new private copy of it loaded somewhere else in memory, which uses extra memory in that process.
ELF does generate position-independent code so it never has the rebasing problem, at the cost of a slight slow down in performance, but in ELF symbol lookup is process scoped, not library scoped like everywhere else. So if 2 libraries define the same symbol, the first library loaded wins. This is a big problem in real world applications, as Autopackage discovered.