[PATCH] [MC] Disassembled CFG reconstruction

Ahmed Bougacha ahmed.bougacha at gmail.com
Thu May 16 22:08:53 PDT 2013


This early patch uses a few classes that were unfinished/broken to do
CFG reconstruction from a disassembled binary:
- MCModule represents the binary, and has a list of MCAtoms.
- MCAtom represents either contiguous data (MCDataAtom), or disassembled
  instructions (MCTextAtom).
- MCBasicBlock and MCFunction form the reconstructed CFG. An MCBB is backed by
  an MCTextAtom, and has successors.
- MCObjectDisassembler creates a module from an objectfile using a disassembler.
  It initially builds an atom for each section. It also constructs the CFG,
  and this splits the text atoms into basic blocks.

There used to be some code that did this (under llvm-objdump -macho -cfg), this
brings it back to life; now, llvm-objdump -d -cfg generates graphviz files for
each function found in the binary.

Future: MCObjectDisassembler would be the right place to do "intelligent"
disassembly: for example, handling constant islands is just a matter of
splitting the atom, using information available in the ObjectFile.
Also, better initial atom formation than just using the sections is possible
using the symbols (and, on mach-o, the function_starts load command).

Immediately though, the patch is still very rough; notably, the llvm-objdump
(especially MachODump.cpp) part wasn't given much attention; updates coming.

http://llvm-reviews.chandlerc.com/D811

Files:
  include/llvm/MC/MCAtom.h
  include/llvm/MC/MCFunction.h
  include/llvm/MC/MCInstrAnalysis.h
  include/llvm/MC/MCModule.h
  include/llvm/MC/MCObjectDisassembler.h
  include/llvm/Support/StringRefMemoryObject.h
  lib/MC/CMakeLists.txt
  lib/MC/MCAtom.cpp
  lib/MC/MCInstrAnalysis.cpp
  lib/MC/MCModule.cpp
  lib/MC/MCObjectDisassembler.cpp
  lib/Support/CMakeLists.txt
  lib/Support/StringRefMemoryObject.cpp
  lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp
  lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp
  tools/llvm-objdump/CMakeLists.txt
  tools/llvm-objdump/MCFunction.cpp
  tools/llvm-objdump/MCFunction.h
  tools/llvm-objdump/MachODump.cpp
  tools/llvm-objdump/llvm-objdump.cpp
  tools/llvm-objdump/llvm-objdump.h
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D811.1.patch
Type: text/x-patch
Size: 64781 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130516/29ff1af2/attachment.bin>


More information about the llvm-commits mailing list