clang dwarf


I am building the llvm IR to generate the control flow graph. I am using autotools(configure, make) to compile my whole program. I use the -save-temps option to save the llvm IR. Now I would like to generate a control flow graph on binary level. I may need the dwarf information to know the mapping between source code and binary code. Besides, I may also need to know the relationship between llvm IR and the source code. Thus, I can translate the control flow graph that I extracted with a pass on LLVM IR to a binary level control flow graph.

Does anyone has some suggestions or comments? Many Thanks


If you compile your program with -gline-tables-only the IR will contain metadata for source locations, and the instructions will have references to the metadata. The IR representation isn’t actually DWARF, but it should have the information you want.

Of course -g will also have the source-location information, but also a lot of other debugging information that you probably do not want, and so for your purposes that would bloat the IR for no benefit.