简体   繁体   中英

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.

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 .

Alternatively, this question and answer shows how to do what nm does.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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