Basic problem: the main reason why dynamic links are slower than static links is that global and static access and data access are complex under dynamic links.GotLocate and then conduct indirect addressing. There are also various dynamic relocation methods.
1>The basic idea of delayed binding: a function is bound only when it is used for the first time (symbol search, relocation, etc.). If it is not used, it is not bound. DetailsElfUsePLT. Actually used functions_ Dl_runtime_resolve ()
2> Now you can find . Got Insert a process. Through PLT Item structure. Each external function is PLT Each has a corresponding item. Function @ PLT Indicates Function In PLT Address in
3> The basic loading process of executable files: first, the operating system reads the header of the executable file, checks the validity of the file, and second, reads each "Segment" And map them to the corresponding location of the virtual space. ( If it is a static link OS The control is handed over to the entry of the executable file. Third, start the dynamic linker ( Dynamic linker) LD. So. 4. Hand over the control to the dynamic linker entry address. The dynamic linker starts initialization and then dynamically links executable files, after the work is completed, the dynamic linker gives control to the entry address of the executable file.
4>The position of the dynamic linker isElfExecutable File decision
5>. interp (INTERPRETER) stores the string, that is, the path of the dynamic linker required for the executable file.LinuxAlmost all/Lib/ld-linux.so.2(This is a soft link.
6> the dynamic linker is available in Linux below is glibc also belongs to the system library level. In the system, glibc other versions are updated, ld-linux.so.2 This soft link points to a new soft link, so it does not need to be modified in the executable file.
7>, dynamicThe structure is classic. Is a struct that describes the required dynamic link information
8> LDD elfprogramView masterProgramShared libraries that the module depends on
9>Import and export functions
10>. dynsymOnly symbols related to dynamic links are saved.. SymtabAll symbols are saved.
11> static . strtab symbol string table. . dynstr dynamic symbol string table (Auxiliary table ). To speed up the search process, the signed hash table . hash (a hash function that allows you to view data structures)
12> PICAddress-independent-FPICGenerated between modulesCode
13>. Rel. Text And . Rel. Data . . Rel. Dyn It is actually a correction of the data reference. The corrected position is located . Got And Data Segment. While . Rel. PLT It is actually a correction to function reference. The position it corrected is located . Got. PLT Segment
14>. got used to save the global variable reference address . got. PLT used to save the function reference address . PLT each external function is stored in . PLT uses a corresponding item to implement latency jump. When the first jump is made, the function address is filled in . got. PLT medium