[LibFuzzer] Fix `-jobs=<N>` where <N> > 1 and the number of workers is > 1 on macOS.
authorDan Liew <dan@su-root.co.uk>
Fri, 12 Aug 2016 18:29:36 +0000 (18:29 +0000)
committerDan Liew <dan@su-root.co.uk>
Fri, 12 Aug 2016 18:29:36 +0000 (18:29 +0000)
commited3c9cae4972099135982093d40301f7d96fa3b4
tree0a9af3f830bb1230450d59a0341a04c819d9d3b5
parentb7abde0343e1042fec643faca571882e3fc133b7
[LibFuzzer] Fix `-jobs=<N>` where <N> > 1 and the number of workers is > 1 on macOS.

The original `ExecuteCommand()` called `system()` from the C library.
The C library implementation of this on macOS contains a mutex which
serializes calls to `system()`. This prevented the `-jobs=` flag
from running copies of the fuzzing binary in parallel which is
the opposite of what is intended.

To fix this on macOS an alternative implementation of `ExecuteCommand()`
is provided that can be used concurrently. This is provided in
`FuzzerUtilDarwin.cpp` which is guarded to only compile code on Apple
platforms. The existing implementation has been moved to a new file
`FuzzerUtilLinux.cpp` which is guarded to only compile code on Linux.

This commit includes a simple test to check that LibFuzzer is being
executed in parallel when requested.

Differential Revision: https://reviews.llvm.org/D22742

llvm-svn: 278544
llvm/lib/Fuzzer/CMakeLists.txt
llvm/lib/Fuzzer/FuzzerUtil.cpp
llvm/lib/Fuzzer/FuzzerUtilDarwin.cpp [new file with mode: 0644]
llvm/lib/Fuzzer/FuzzerUtilLinux.cpp [new file with mode: 0644]
llvm/lib/Fuzzer/test/fuzzer-jobs.test [new file with mode: 0644]