请问HN:关于在机器代码上进行统计的帮助
我想对gcc生成的机器代码进行一些统计,比如使用指令的直方图、函数中易失性/保留寄存器的平均使用情况等。目前只需要x86_64 SysV-ABI的统计就足够了。
然而,我并不知道有任何现成的工具可以让我轻松实现这一点。我目前看到的选项是,要么让gcc输出汇编代码,然后为GNU汇编器格式编写一个解析器(可能通过重用compiler-explorer项目的asm-parser),要么编写一个工具,直接使用elfutils读取(反汇编)目标文件。
任何提示、以往的工作、进一步的想法、有用资源的链接或其他任何形式的帮助都将不胜感激。
查看原文
I'd like to do some statistics over the machine code gcc generates, such as a histogram of used instructions, average volatile/preserved registers usage of functions etc. For now just x86_64 SysV-ABI would be enough.<p>However I'm not aware of any pre-existing tool that lets me easily do this. The options I currently see are either make gcc output assembly and write a parser for the GNU Assembler format (possibly by reusing the asm-parser of the compiler-explorer project), or write a tool that reads (disassembles) object files directly using elfutils.<p>Any hints, prior work, further ideas, links to useful resources, or any other kind of help would be much appreciated.