Can I get object name from a symbol information in the symbol table in an ELF file?

和自甴很熟 提交于 2019-12-07 21:26:25

问题


I have successfully parsed an elf file (executable file) compiled from multiple source files. I am able to get the binding(local,global,weak), type(object,file,section,function), size of the symbol and the address of the symbol along with the symbol name ( from string table).

The section to which the symbol is linked is also known to me.

My question is that can we get the exact object file name(**.obj) which contains the symbol from the symbol table information? Am I missing some information while parsing ?


回答1:


You cannot get the object file name directly, this is lost during linking. However, depending on the build process used to create the executable, you can infer the object file name from the STT_FILE symbols (e.g., an executable contains a STT_FILE symbol with name foo.c -> you could maybe infer the object file was foo.o).

It appears that symbols in a specific source file follow the STT_FILE symbol with a binding of STB_LOCAL.

From the System V ABI standard:

STT_FILE -- Conventionally, the symbol’s name gives the name of the source file associated with the object file. A file symbol has STB_LOCAL binding, its section index is SHN_ABS, and it precedes the other STB_LOCAL symbols for the file, if it is present.



来源:https://stackoverflow.com/questions/6981787/can-i-get-object-name-from-a-symbol-information-in-the-symbol-table-in-an-elf-fi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!