简体   繁体   English

给定一个功能标识符,是否有一个命令行程序或一个库函数来提供存储在elf文件中的地址

[英]given a function identifier, is there a command line program or a library function providing the address as stored in the elf file

I am looking for a command or library function that returns the address of a function, the opposite of addr2line. 我正在寻找一个返回函数地址的命令或库函数,与addr2line相反。

Currently, I use the following command: 当前,我使用以下命令:

readelf -s ./a.out|grep "\<main\>"|uniq
>    451: 000000000001967f   148 FUNC    GLOBAL DEFAULT   14 main

您也可以为此使用gdb, info address打印给定符号的地址,因此应如下所示: gdb ./a.out -ex 'info address main'

You could use libelf . 您可以使用libelf

Alternatively, this question and answer shows how to do what nm does. 或者,此问题和答案显示了如何执行nm操作。

You could easily modify the code there to go in reverse: iterate over all symbols until you find the right symbol name, then return the address of that symbol. 您可以轻松地在那里修改代码以反向执行:遍历所有符号,直到找到正确的符号名称,然后返回该符号的地址。

If you need to perform lookups over multiple symbol names, you could of course iterate over all symbols once, and build a name -> address map, so subsequent lookups are fast. 如果您需要对多个符号名称执行查找,那么您当然可以遍历所有符号一次,并构建一个name -> address映射,因此后续查找速度很快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM