How to list on-the-fly all the functions/symbols available in C code on a Linux architecture?

后端 未结 5 1519
悲&欢浪女
悲&欢浪女 2020-12-08 14:54

Assume main.c uses symbols from shared libs and local functions declared in main.c.

Is there a nice and elegant way to print a list of all

5条回答
  •  暖寄归人
    2020-12-08 15:29

    On dynamic-linked ELF-based systems, you may have a function dl_iterate_phdr available. If so, it can be used to gather information on each loaded shared library file, and the information you get is sufficient to examine the symbol tables. The process is basically:

    1. Get the address of the program headers from the dl_phdr_info structure passed back to you.
    2. Use the PT_DYNAMIC program header to find the _DYNAMIC table for the module.
    3. Use the DT_SYMTAB, DT_STRTAB, and DT_HASH entries of _DYNAMIC to find the list of symbols. DT_HASH is only needed to get the length of the symbol table, since it doesn't seem to be stored anywhere else.

    The types you need should all be in and .

提交回复
热议问题