glibc - get handle to shared library having symbol containing specified address

StackOverflow https://stackoverflow.com/questions/16208652

  •  11-04-2022
  •  | 
  •  

Вопрос

Something like dladdr that gives me a dynamic library handle to the shared object or a way to get the handle from the shared object's base address. The file containing the shared object may have been moved or deleted so no, I can't dlopen() the filename given by dladdr.

Это было полезно?

Решение

glibc's dlopen handles are based on link_map. I can iterate all link_map's and see if one has l_addr equal to the one given by dladdr. The address of that link_map is the handle.

dietlibc also uses link_map's as handles.

In the case of uClibc there is another struct - dyn_elf. It contains a pointer to a link_map. The global variable _dl_symbol_tables has a pointer to the head of a linked list of dyn_elf's.

bionic uses its own struct which contains struct link_map as a member (not a pointer).

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top