Operating System Concepts, by Silberschatz A., Galvin P. B., Gagne G. - Operating System Concepts, 9th Edition - 2012 says
8.1.4 Dynamic Loading
In our discussion so far, it has been necessary for the entire program and all data of a process to be in physical memory for the process to execute. The size of a process has thus been limited to the size of physical memory. To obtain better memory-space utilization, we can use dynamic loading. With dynamic loading, a routine is not loaded until it is called. All routines are kept on disk in a relocatable load format. The main program is loaded into memory and is executed. When a routine needs to call another routine, the calling routine ﬁrst checks to see whether the other routine has been loaded. If it has not, the relocatable linking loader is called to load the desired routine into memory and to update the program’s address tables to reﬂect this change. Then control is passed to the newly loaded routine.
The advantage of dynamic loading is that a routine is loaded only when it is needed. This method is particularly useful when large amounts of code are needed to handle infrequently occurring cases, such as error routines. In this case, although the total program size may be large, the portion that is used (and hence loaded) may be much smaller.
Dynamic loading does not require special support from the operating system. It is the responsibility of the users to design their programs to take advantage of such a method. Operating systems may help the programmer, however, by providing library routines to implement dynamic loading.
8.1.5 Dynamic Linking and Shared Libraries
What kinds of files have "a relocatable load format" in Linux,
- an ELF executable file,
- a .so shared library file,
- a kernel module,
- a .o object files?
Can they all be dynamically loaded?
Does "a relocatable load format" in the quote mean .o object file, a kernel module, but not .so shared library file, according to:
http://refspecs.linuxbase.org/elf/gabi4+/ch4.intro.html says there are three kinds of ELF files: executable files, shared object files, and relocatable files.
What ELF types do kernel itself and kernel modules have? shows that a kernel module is also relocatable ELF.
The book doesn't mention anything yet about shared library until Section 8.1.5, so Section 8.1.4 seems to me that dynamic loading is not necessarily loading a shared library into a user program, but may load something else. Is that true?
The last paragraph of section 8.1.4 seems to say that programmers need to perform dynamic loading explicitly. Does it refer to
What kinds of ELF files can
dlopen() accepts as its first argument, a .so shared library, a .o object file, a kernel module, an executable ELF file?