Learn about Dynamic Links (5)-Dynamic symbol tables and dynamic symbols
The dynamic symbol table (. dynsym) is used to save the Import and Export symbols related to the dynamic link, excluding the symbols in the module. The. symtab saves all the symbols, including those in. dynsym.
The symbols in the dynamic symbol table are saved in the dynamic symbol string table. dynstr.
Use readelf to view the. dynsym table, for example, readelf -- dyn-syms libstdc ++. so.
As you can see, the. dynsym table contains 39 items. _ Cxa_atexit is an import symbol, while _ cxa_guard_acquire is an export symbol. Search for the source code of the android libstdc ++ library and find the definition of the export function:
The book says that many dynamic link modules are available at the same time. dynsym and. two symtab tables, but I checked several system shared libraries in android: libc. so ,. liblog. so, libm. so, libstdc ++. so, only. dynsym. In fact, according to my understanding, there is only. dynsym in the so library, which is used for symbol search and address relocation during dynamic link .. The internal symbol in symtab is useless at this time, so there is no need to exist. symtab.
Search for symbols in the symbol table before moving symbols to android linker. To speed up searching, the hash table corresponding to the symbol table is saved in. hash.
The 1st line code of the soinfo_elf_lookup function gets the address of the symbol table in the so library in the memory. In the soinfo_link_image function, the address of the symbol table has been read from. dynamic and saved in si-> symtab before the relocation operation. Both the string table and the symbol hash table are read and saved to the soinfo structure.
The address saved by si-> symtab is the virtual address after. dynsym in the so library is loaded to the memory. For details about the dynamic section. dynamic and the android linker source code parsing, you will continue to take notes later.
Learning Materials: programmer self-cultivation-links, loading and libraries