https://github.com/adrianherrera/llvm-cfg-to-json
Exports an LLVM control flow graph (CFG) (including function calls) to JSON
https://github.com/adrianherrera/llvm-cfg-to-json
fuzzing llvm llvm-cfg
Last synced: about 1 year ago
JSON representation
Exports an LLVM control flow graph (CFG) (including function calls) to JSON
- Host: GitHub
- URL: https://github.com/adrianherrera/llvm-cfg-to-json
- Owner: adrianherrera
- License: other
- Created: 2019-10-09T22:54:42.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-11-26T09:42:55.000Z (over 4 years ago)
- Last Synced: 2025-03-28T23:43:34.335Z (about 1 year ago)
- Topics: fuzzing, llvm, llvm-cfg
- Language: C++
- Homepage:
- Size: 145 KB
- Stars: 23
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.jsoncpp
Awesome Lists containing this project
README
# LLVM CFG to JSON
Exports an LLVM control flow graph (CFG) to JSON. This pass is different from
LLVM's standard CFG printer in that it captures both *intra* and *inter*
procedural edges (i.e., function calls).
## Building
```bash
git clone https://github.com/adrianherrera/llvm-cfg-to-json.git
cd llvm-cfg-to-json
mkdir build
cd build
# If you have multiple LLVM versions installed, specify the one you want by
# setting LLVM_DIR; e.g., -DLLVM_DIR=`llvm-config-12 --cmakedir`
#
# This probably also requires setting CC/CXX
CC=clang CXX=clang++ cmake ..
```
## Running
```bash
clang -fplugin=/path/to/build/libLLVMCFGToJSON.so /path/to/src.c
```
If using autotools/make/etc., do
```bash
CFLAGS="-fplugin=/path/to/build/libLLVMCFGToJSON.so" CXXFLAGS="-fplugin=/path/to/build/libLLVMCFGToJSON.so" ./configure
make
```
Or CMake:
```bash
cmake -DCMAKE_C_FLAGS="-fplugin=/path/to/build/libLLVMCFGToJSON.so" -DCMAKE_CXX_FLAGS="-fplugin=/path/to/build/libLLVMCFGToJSON.so" ...
make
```
## `cfg_stats.py`
Using the results produced by the LLVM pass, calculate some interesting graph
statistics (e.g., number of basic blocks, number of edges, and the graph
eccentricity from the CFG's entry point). The script can also (optionally)
produce a DOT graph of the CFG.
### Running
```bash
clang -fplugin=/path/to/build/libLLVMCFGToJSON.so /path/to/src.c
python cfg_stats.py `pwd`/cfg.*.json
```