Skip to content

Commit e67f2c4

Browse files
committed
add clang support
1 parent ec8b03d commit e67f2c4

File tree

6 files changed

+36
-13
lines changed

6 files changed

+36
-13
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# afl-cov - AFL Fuzzing Code Coverage
22

3-
Version: 0.6.5
3+
Version: 0.6.6
44

55
- [Preface](#preface)
66
- [Introduction](#introduction)
@@ -23,6 +23,8 @@ It has four changes:
2323
* afl-cov now can send to targets that read on stdin (just omit @@)
2424
* afl-cov.sh makes using afl-cov easier (just needs two parameters)
2525
* afl-cov-build.sh makes builing a target for coverage easier
26+
* afl-cov/afl-cov.sh/afl-cov-build.sh now support clang coverage, just add
27+
-c to afl-cov.sh/afl-cov-build.sh (and --clang to afl-cov)
2628
* afl-stat.sh shows the statistics of a run (in progress or completed)
2729

2830
Enjoy!

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.6.3
1+
0.6.6

afl-clang-cov.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
llvm-cov gcov $*

afl-cov

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# File: afl-cov
44
#
5-
# Version: 0.6.5
5+
# Version: 0.6.6
66
#
77
# Purpose: Perform lcov coverage diff's against each AFL queue file to see
88
# new functions and line coverage evolve from an AFL fuzzing cycle.
@@ -45,7 +45,7 @@ try:
4545
except ImportError:
4646
import subprocess
4747

48-
__version__ = '0.6.5'
48+
__version__ = '0.6.6'
4949

5050
NO_OUTPUT = 0
5151
WANT_OUTPUT = 1
@@ -579,6 +579,8 @@ def lcov_gen_coverage(cov_paths, cargs):
579579
lcov_opts += ' --rc lcov_branch_coverage=1'
580580
if cargs.follow:
581581
lcov_opts += ' --follow'
582+
if cargs.clang:
583+
lcov_opts += ' --gcov-tool afl-clang-cov.sh'
582584

583585
run_cmd(cargs.lcov_path \
584586
+ lcov_opts
@@ -807,6 +809,8 @@ def init_tracking(cov_paths, cargs):
807809
lcov_opts = ''
808810
if cargs.enable_branch_coverage:
809811
lcov_opts += ' --rc lcov_branch_coverage=1 '
812+
if cargs.clang:
813+
lcov_opts += ' --gcov-tool afl-clang-cov.sh'
810814

811815
### reset code coverage counters - this is done only once as
812816
### afl-cov is spinning up even if AFL is running in parallel mode
@@ -1149,6 +1153,9 @@ def parse_cmdline():
11491153
p.add_argument("--live", action='store_true',
11501154
help="Process a live AFL directory, and afl-cov will exit when it appears afl-fuzz has been stopped",
11511155
default=False)
1156+
p.add_argument("--clang", action='store_true',
1157+
help="If clang was used for coverage compilation instead of gcc"",
1158+
default=False)
11521159
p.add_argument("--cover-corpus", action='store_true',
11531160
help="Measure coverage after running all available tests instead of individually per queue file",
11541161
default=False)

afl-cov-build.sh

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
test -z "$1" -o "$1" = "-h" && {
4-
echo "Syntax: $0 <command> [options]"
4+
echo "Syntax: $0 [-c] <command> [options]"
55
echo Sets build options for coverage instrumentation with gcov/lcov.
66
echo Set CC/CXX environment variables if you do not want gcc/g++.
7+
echo Specify the -c parameter if you want to use clang/clang++ instead.
78
echo Example: "$0 ./configure --disable-shared"
89
exit 1
910
}
1011

11-
test -z "$CC" && export CC=gcc
12-
test -z "$CXX" && export CXX=g++
12+
CLANG=
13+
test "$1" = "-c" && { CLANG=yes ; shift ; }
14+
15+
test -z "$CC" -a -z "$CLANG" && export CC=gcc
16+
test -z "$CXX" -a -z "$CLANG" && export CXX=g++
17+
test -z "$CC" -a -n "$CLANG" && export CC=clang
18+
test -z "$CXX" -a -n "$CLANG" && export CXX=clang++
19+
1320
export CFLAGS="-fprofile-arcs -ftest-coverage"
1421
export CXXFLAGS="$CFLAGS"
1522
export CPPFLAGS="$CFLAGS"
16-
export LDFLAGS="-lgcov --coverage"
23+
test -z "$CLANG" && export LDFLAGS="-lgcov --coverage"
24+
test -n "$CLANG" && export LDFLAGS="--coverage"
1725

1826
$*

afl-cov.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,29 @@
33
# easy wrapper script for afl-cov
44
#
55
test "$1" = "-h" -o -z "$1" && {
6-
echo "Syntax: $0 [-v] out-dir \"exec cmd --foo @@\""
6+
echo "Syntax: $0 [-v] [-c] out-dir \"exec cmd --foo @@\""
77
echo
88
echo Generates the coverage information for an AFL run.
99
echo Must be run from the top directory of the coverage build.
10-
echo The -v option enables verbose output
10+
echo The -v option enables verbose output.
11+
echo The option -c specifies that clang was used for the coverage build
1112
echo
1213
echo Example: $0 ../target/out \"tools/target @@\"
1314
exit 1
1415
}
1516

17+
test "$1" = "-v" && { OPT1="-v" ; shift ; }
18+
test "$1" = "-c" && { OPT2="--clang" ; shift ; }
19+
test "$1" = "-v" && { OPT1="-v" ; shift ; }
20+
1621
test -d "$1" || { echo Error: not a directory: $1 ; exit 1 ; }
1722
test -e "$1"/queue || { echo Error: not an afl-fuzz -o out directory ; exit 1 ; }
1823

1924
HOMEPATH=`dirname $0`
2025
DST=`realpath "$1"`
2126
export PATH=$HOMEPATH:$PATH
2227

23-
test "$1" = "-v" && { OPT="-v" ; shift ; }
24-
afl-cov $OPT -d "$DST" --cover-corpus --coverage-cmd "$2" --code-dir . --overwrite
28+
afl-cov $OPT1 $OPT2 -d "$DST" --cover-corpus --coverage-cmd "$2" --code-dir . --overwrite
2529

2630
test -e "$1"/fuzzer_stats && {
2731
DIFF=$(expr `grep last_update "$DST"/fuzzer_stats|awk '{print$3}'` - `grep start_time "$DST"/fuzzer_stats|awk '{print$3}'`)

0 commit comments

Comments
 (0)