Can I get object name from a symbol information in the symbol table in an ELF file?
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 infor开发者_运维技巧mation? Am I missing some information while parsing ?
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.
精彩评论