0

Hi I am trying to get a control flow graph with basic block's detailed address in it, i.e. if the CFG tells me about a basic block, it should also tells me the start/end assembly address of that basic block.

I have tried gcc -fdump-tree-cfg-address <myfile.c>

However, the gcc ignored the address. So I am wondering is there any method I can achieve the goal? Not limit to gcc, any solution would be helpful. Thanks!

Chen
  • 27
  • 2
  • 1
    Addresses don't exist until link time; at compile time they're just labels, aka symbolic addresses. GCC internal never know what the numeric address is going to be for any block or function. – Peter Cordes Sep 23 '21 at 17:32
  • @PeterCordes Thank you for clarification. Let me try to reframe the question. Let's say, right now I have a binary, and after objdump, I can have the instruction addresses. Now is there a tool that can turn the assembly into a things similar to a CFG with address on it? – Chen Sep 23 '21 at 17:39
  • 2
    Agner Fog's `objconv` disassembler can disassemble into asm that has branch targets shown, so with that plus looking for branch instructions you can find the basic blocks. (Except for possible computed / indirect jumps). I don't know of anything that can combine higher-level GIMPLE or RTL (or clang LLVM-IR) compiler internal representation with disassembly that has numeric addresses. There is enough metadata in debug info to let `objdump -S` interleave asm and C source, but the internal representations only go into machine-readable files for `-flto` link-time optimization, so probably not. – Peter Cordes Sep 23 '21 at 17:46
  • @PeterCordes That's really helpful! Thank you very much for your input! – Chen Sep 23 '21 at 21:19

0 Answers0