我可以从ELF文件中符号表中的符号信息中获取对象名称吗? [英] Can I get object name from a symbol information in the symbol table in an ELF file?

查看:693
本文介绍了我可以从ELF文件中符号表中的符号信息中获取对象名称吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已成功解析从多个源文件编译的elf文件(可执行文件)。我能够获得绑定(局部,全局,弱),类型(对象,文件,节,函数),符号的大小和符号的地址以及符号名称(从字符串表)。

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.

我的问题是,我们可以得到对象文件名( * *。obj),它包含符号表信息中的符号?我在解析时缺少一些信息?

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 ?

推荐答案

您不能直接获取对象文件名,但是,根据用于创建可执行文件的构建过程,您可以从STT_FILE符号推断对象文件名(例如,可执行文件包含名为foo.c的STT_FILE符号 - >您可能推断对象文件是foo。 o)。

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).

看起来,特定源文件中的符号跟在具有STB_LOCAL绑定的STT_FILE符号之后。

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

从System V ABI标准:

From the System V ABI standard:


STT_FILE - 通常,符号的名称给出与对象关联的源文件的名称文件。文件符号具有STB_LOCAL绑定,其段索引为SHN_ABS,并且在文件的其他STB_LOCAL符号之前(如果存在)。

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.

这篇关于我可以从ELF文件中符号表中的符号信息中获取对象名称吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆