WIP: Add ability to generate drcov trace using QEMU backend (#1956)

* Document new drcov QEMU plugin

* Add link to lightkeeper for QEMU drcov file loading

---------

Co-authored-by: Jean-Romain Garnier <jean-romain.garnier@airbus.com>
This commit is contained in:
Jean-Romain Garnier
2024-01-12 15:42:41 +01:00
committed by GitHub
parent a4017406dc
commit 355dcf6320
2 changed files with 33 additions and 4 deletions

View File

@ -193,12 +193,39 @@ Comparative measurements of execution speed or instrumentation coverage will be
fairly meaningless if the optimization levels or instrumentation scopes don't
match.
## 12) Other features
## 12) Coverage information
Coverage information about a run of a target binary can be obtained using a
dedicated QEMU user mode plugin enabled at runtime: the `drcov.c` plugin
collects coverage information from the target binary and writes it in the Drcov
format. This file can then be loaded using tools such as
[lighthouse](https://github.com/gaasedelen/lighthouse),
[lightkeeper](https://github.com/WorksButNotTested/lightkeeper) or
[Cartographer](https://github.com/nccgroup/Cartographer).
To compile the QEMU TCG plugins, run the following command from the `qemuafl`
directory:
```
make plugins
```
Plugins can be loaded using either the `QEMU_PLUGIN` environment variable or
using the `-plugin` option. For example:
```
afl-qemu-trace -plugin qemuafl/build/contrib/plugins/libdrcov.so,arg=filename=/tmp/target.drcov.trace <target> <args>
```
This would execute the target binary with the provided arguments and, once done,
would write coverage information at `/tmp/target.drcov.trace`.
## 13) Other features
With `AFL_QEMU_FORCE_DFL`, you force QEMU to ignore the registered signal
handlers of the target.
## 13) Gotchas, feedback, bugs
## 14) Gotchas, feedback, bugs
If you need to fix up checksums or do other cleanups on mutated test cases, see
`afl_custom_post_process` in custom_mutators/examples/example.c for a viable
@ -217,7 +244,7 @@ program may be utilizing. In particular, it does not appear to have full support
for AVX2/FMA3. Using binaries for older CPUs or recompiling them with
`-march=core2`, can help.
## 14) Alternatives: static rewriting
## 15) Alternatives: static rewriting
Statically rewriting binaries just once, instead of attempting to translate them
at run time, can be a faster alternative. That said, static rewriting is fraught

View File

@ -132,7 +132,10 @@ echo "Building for CPU target $CPU_TARGET"
# --enable-pie seems to give a couple of exec's a second performance
# improvement, much to my surprise. Not sure how universal this is..
# --enable-plugins allows loading TCG plugins at runtime, for example to obtain
# coverage information, and does not seem to negatively impact performance
QEMU_CONF_FLAGS=" \
--enable-plugins \
--audio-drv-list= \
--disable-blobs \
--disable-bochs \
@ -162,7 +165,6 @@ QEMU_CONF_FLAGS=" \
--disable-numa \
--disable-opengl \
--disable-parallels \
--disable-plugins \
--disable-qcow1 \
--disable-qed \
--disable-rbd \