Learn about Dynamic Links (1)-Overview and overview of Dynamic Links
I. disadvantages of static links
1. Memory and disk space waste
Assume that both module A and Module B depend on C and use static links. The C library is linked to database A and database B. In this way, whether Stored on disk or in memory, each module C has two copies.
2. Program maintenance troubles
Assume that the program depends on many libraries. If any of them modifies a bug or updates the program, you need to re-link and re-release the program.
2. Dynamic Link)
Delay the link process until it is run.
Assume that both module A and Module B depend on Module C and use dynamic links. At runtime, Module C only has one copy in the memory, which is shared by module A and Module B, there is only one independent C Shared library on the disk.
Dynamic Links are used to solve the two shortcomings of static links mentioned above.
The process of dynamic link is roughly to recursively load the dependent Library to the memory, then parse the symbol and relocate the address, and finally execute the entry point program.
3. Dynamic links are not perfect
1. Version Control of the Shared Library
The basic idea of dynamic link is to split the program into independent modules. A common problem is that after a module on which the program depends is updated, some original programs cannot run because the interfaces of the New and Old modules are incompatible.
2. Performance Loss
Dynamic Links are used to re-link the program each time it runs, which may cause some performance loss. Lazy Binding can minimize this performance loss.
4. How to quickly understand the entire process of Dynamic Links
The fastest way to learn is to read the code, such as reading the Linker code of the Android system. The entire Linker does not have a large amount of code, but the premise is to have a certain understanding of the ELF format.
Learning Materials: programmer self-cultivation-links, loading and libraries