602 Commits

Author SHA1 Message Date
Justin Bogner
af8c7cedc1 [libFuzzer] Update traces hooks test after r293741
This test now passes on darwin.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@295902 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-22 23:12:36 +00:00
Justin Bogner
28c53fa4a0 [libFuzzer] Mark a test that infinite loops as unsupported
We need to investigate this, but for now it just causes too much
headache when trying to run these tests.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@295900 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-22 23:05:17 +00:00
Kostya Serebryany
8a5fe4855b [libFuzzer] increase the size of FixedWord from 27 to 64, see PR31950
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@295117 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-14 23:02:37 +00:00
Kostya Serebryany
36924d4080 Use "%zd" format specifier for printing number of testcases executed.
Summary:
This helps to avoid signed integer overflow after running a fast fuzz target for several hours, e.g.:

<...>
Done -1097903291 runs in 54001 second(s)



Reviewers: kcc

Reviewed By: kcc

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@295112 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-14 22:14:36 +00:00
Marcos Pividori
fc4c8411e4 [libFuzzer] Use stoull instead of stol to ensure 64 bits.
Differential revision: https://reviews.llvm.org/D29831

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294769 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-10 18:44:14 +00:00
Eric Fiselier
a61fc423f3 [CMake] Fix pthread handling for out-of-tree builds
LLVM defines `PTHREAD_LIB` which is used by AddLLVM.cmake and various projects
to correctly link the threading library when needed. Unfortunately
`PTHREAD_LIB` is defined by LLVM's `config-ix.cmake` file which isn't installed
and therefore can't be used when configuring out-of-tree builds. This causes
such builds to fail since `pthread` isn't being correctly linked.

This patch attempts to fix that problem by renaming and exporting
`LLVM_PTHREAD_LIB` as part of`LLVMConfig.cmake`. I renamed `PTHREAD_LIB`
because It seemed likely to cause collisions with downstream users of
`LLVMConfig.cmake`.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294690 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-10 01:59:20 +00:00
Marcos Pividori
671eb85b72 [libFuzzer] Export external functions on tests.
We need to export external functions so they are found when calling
GetProcAddress() on Windows. But we can't use `__declspec(dllexport)` because
we want the targets to be completely independent from the fuzz engines and don't
depend on other header files. Also, we don't want to include platform specific
code managed with conditional macros.
So, the solution is to add the exported symbols with linker flags in cmake.

Differential revision: https://reviews.llvm.org/D29752

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294688 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-10 01:40:28 +00:00
Marcos Pividori
d9191ae5c6 [libFuzzer] Use dynamic loading for External Functions on Windows.
Replace weak aliases with dynamic loading.
Weak aliases were generating some problems when linking for MT on Windows. For
MT, compiler-rt's libraries are statically linked to the main executable the
same than libFuzzer, so if we use weak aliases, we are providing two different
default implementations for the same weak function and the linker fails.

In this diff I re implement ExternalFunctions() using dynamic loading, so it
works in both cases (MD and MT). Also, dynamic loading is simpler, since we are
not defining any auxiliary external function, and we don't need to deal with
weak aliases.
This is equivalent to the implementation using dlsym(RTLD_DEFAULT, FnName) for
Posix.

Differential revision: https://reviews.llvm.org/D29751

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294687 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-10 01:35:46 +00:00
Marcos Pividori
2ee8a5f7b7 [libFuzzer] Use long long to ensure 64 bits.
We should always use unsigned long long to ensure 64 bits. On Windows, unsigned
long is 4 bytes. This was the reason why value-profile-cmp4.test was failing on
Windows.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294390 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-08 00:03:31 +00:00
Marcos Pividori
7a5e009266 [libFuzzer] Use custom target instead of list of binaries for tests.
Update cmake to use a custom target TestBinaries instead of a list of targets.
This simplifies cmake, and fix some errors. This way, we don't have to propagate
the values into parents directories. We only need to use add_dependencies.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294389 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-08 00:03:26 +00:00
Marcos Pividori
f80dc2a04d [libFuzzer] Properly use Handle instead of FD on Windows.
For Windows, sanitizers work with Handles, not with posix file descriptors,
because they use the windows-specific API. So we need to convert the fds to
handles before passing them to the sanitizer library.
After this change, close_fd_mask is fixed for Windows (this fix some tests too).

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294388 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-08 00:03:18 +00:00
Marcos Pividori
255eed0380 [libFuzzer] Change Uninstrumented test name.
On Windows, executables with the word "uninst" included in their names are
associated with administrator privileges.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294387 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-08 00:03:13 +00:00
Marcos Pividori
ec59eb9d58 [libFuzzer] fuzzer-jobs requires posix.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294386 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-08 00:03:07 +00:00
Marcos Pividori
1ff471105f [libFuzzer] Update fuzzer.test to properly set environment variables.
Use env to set environment variables, so it works on Windows and Linux.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294385 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-08 00:03:03 +00:00
Marcos Pividori
155c4aab57 [libFuzzer] Don't add newline character when using echo in tests.
Add the option "-n", so we don't add a new line character at the end of the file
when using echo. (on Windows this means 2 characters).

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294384 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-08 00:02:59 +00:00
Marcos Pividori
fbc422e6ba [libFuzzer] Disable ulimit test on windows.
Differential Revision: https://reviews.llvm.org/D29535

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294383 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-08 00:02:54 +00:00
Marcos Pividori
44933aa735 [libFuzzer] Remove ? wildcard on tests.
We can not use the wildcard ? on Windows.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294382 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-08 00:02:50 +00:00
Marcos Pividori
6cf9872a5e [libFuzzer] Update fuzzer-segv to set environment variables.
Use env to set environment variables, so it works on Linux and Windows.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294381 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-08 00:02:45 +00:00
Marcos Pividori
75241a8855 [libFuzzer] Properly configure tests for Windows.
This configuration is necessary, and is included in all tests suites.
We need to execute: `config.test_format = lit.formats.ShTest(False)`
Otherwise, lit will try to use bash, which generates many problems.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294380 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-08 00:02:41 +00:00
Marcos Pividori
ddc6c083cf [libFuzzer] Simplify dump_coverage test.
Environment variables are handled differently on Windows. In this case it is not
necessary to use environment variables. So, I simplify the test to work on
Windows.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294379 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-08 00:02:36 +00:00
Marcos Pividori
a8f8ed08cc [libFuzzer] Update Load test to work on 32 bits.
We should ensure the size of the variable `a` is 8 bytes. Otherwise, this
generates a stack buffer overflow inside the memcpy call in 32 bits machines.
(We write more bytes than the size of a, when it is 4 bytes)

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294378 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-08 00:02:32 +00:00
Marcos Pividori
f78e1b3b9d [libFuzzer] Update test to consider different exceptions.
Differential Revision: https://reviews.llvm.org/D29531

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294377 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-08 00:02:25 +00:00
Marcos Pividori
8c0ca40461 [libFuzzer] Temporarily fix Shmem for Windows.
In this diff, I add stubs for shared memory on Windows. Now we can compile and
use libFuzzer without support for shared memory.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294376 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-08 00:02:12 +00:00
Kostya Serebryany
ffcfd0c3bc [libFuzzer] replace std::random_shuffle with std::shuffle as std::random_shuffle is being deprecated in C++17. Also simplify fuzzer::Random. NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294366 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-07 22:37:34 +00:00
Kostya Serebryany
522017cf0d [libFuzzer] make code less clever to avoid fallthrough in switch (and in turn avoid compiler warnings). NFC. Suggested by Christian Holler.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294239 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-06 21:21:37 +00:00
Kostya Serebryany
66d69563f7 [libFuzzer] properly hide the memcmp interceptor from msan
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294061 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-03 22:51:38 +00:00
Mike Aizatsky
0022fc7373 [libfuzzer] chromium-related compilation fixes
Reviewers: kcc

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294035 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-03 20:26:44 +00:00
Kostya Serebryany
5459106ddf [libFuzzer] reorganize the tracing code to make it easier to experiment with inlined coverage instrumentation. NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293928 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-02 19:56:01 +00:00
Marcos Pividori
ebf6feac60 [libFuzzer] Properly handle exceptions with UnhandledExceptionFilter.
Use SetUnhandledExceptionFilter instead of AddVectoredExceptionHandler.

According to the documentation on Structured Exception Handling, this is the
order for the Exception Dispatching:
+ If the process is being debugged, the system notifies the debugger.
+ The Vectored Exception Handler is called.
+ The system attempts to locate a frame-based exception handler by searching the
 stack frames of the thread in which the exception occurred.
+ If no frame-based handler can be found, the UnhandledExceptionFilter filter is
 called.
+ Default handling based on the exception type.

So, similar to what we do for asan, we should use SetUnhandledExceptionFilter
instead of AddVectoredExceptionHandler, so user's code that is being fuzzed can
execute frame-based exception handlers before we catch them . We want to catch
unhandled exceptions, not all the exceptions.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293920 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-02 19:07:53 +00:00
Marcos Pividori
f7fdc84b39 [libFuzzer] Disable afl tests on non-posix systems.
AflDriver is not supported on non posix systems.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293830 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 22:40:50 +00:00
Marcos Pividori
b2df6a0c9b [libFuzzer] Disable equivalence tests on non posix systems.
We can not run this test until we implement shared memory on Windows.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293829 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 22:40:45 +00:00
Marcos Pividori
98399aa4b2 [libFuzzer] Isolate merge tests that require posix.
Differential Revision: https://reviews.llvm.org/D29420

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293828 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 22:40:40 +00:00
Marcos Pividori
b928b9b13e [libFuzzer] Add features windows and posix for lit tests.
Add 2 features: posix and windows.
Sometimes we want some specific tests only for posix and we use:
 REQUIRES: posix
Sometimes we want some specific tests only for windows and we use:
 REQUIRES: windows

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293827 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 22:40:34 +00:00
Marcos Pividori
adb057cab2 [libFuzzer] Accept different extensions.
Differential Revision: https://reviews.llvm.org/D29417

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293826 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 22:40:29 +00:00
Marcos Pividori
1d98b650ef [libFuzzer] Fix test because cmd prompt does not expand wildcard.
Commands should expand the wildcards on Windows, the cmd prompt doesn't.
Because of that sancov was not finding the needed file.
To deal with this, we use ls and xargs from gnu win utils.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293825 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 22:39:55 +00:00
Marcos Pividori
12cb357da1 [libFuzzer] Do not use llvm-objdump for disassembling a DSO.
When disassembling a DSO, for calls to functions from the PLT, llvm-objdump only
prints the offset from the PLT, like: <.plt+0x30>.

While objdump and dumpbin print the function name, like:
<__sanitizer_cov_trace_pc_guard@plt>

When analyzing the coverage in libFuzzer we dissasemble and look for the calls
to __sanitizer_cov_trace_pc_guard.

So, this fails when using llvm-objdump on a DSO.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293791 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 17:59:23 +00:00
Marcos Pividori
90e4124e52 [libFuzzer] Properly check if we can use dumpbin.
The flag "/sumary" is necessary, otherwise it returns a non-zero value.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293790 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 17:59:19 +00:00
Kostya Serebryany
63c362484c [libFuzzer] increase the default size for shmem
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293722 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-01 00:07:47 +00:00
Marcos Pividori
2c531bbcf6 [libFuzzer] Implement TmpDir() for Windows.
Differential Revision: https://reviews.llvm.org/D28977

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293516 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-30 18:14:53 +00:00
Kostya Serebryany
dec0b05633 [libfuzzer] include errno.h. On Ubuntu 14.04 we got away w/o it, but other systems seem to require it
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293389 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-28 18:56:05 +00:00
Kostya Serebryany
001f56735f [libFuzzer] make shmem more robust in the presence of signals
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293339 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-27 22:41:30 +00:00
Kostya Serebryany
49c910dae1 [libFuzzer] simplify the value profiling callback further: don't use (idx MOD prime) on the hot path where it is useless anyway
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293239 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-27 00:39:12 +00:00
Kostya Serebryany
eff755f3da [libFuzzer] make sure (again) that __builtin_popcountl is compiled into popcnt
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293237 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-27 00:20:55 +00:00
Kostya Serebryany
bcc64b878f [libFuzzer] simplify the value profile code and disable asan/msan on it
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293236 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-27 00:09:59 +00:00
Kostya Serebryany
6c2c7c89da [libFuzzer] remove a bit of stale code
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293129 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-26 01:45:54 +00:00
Kostya Serebryany
c43e0682f2 [libFuzzer] further simplify __sanitizer_cov_trace_pc_guard
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293128 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-26 01:34:58 +00:00
Kostya Serebryany
df040aa50b [libFuzzer] simplify the code for __sanitizer_cov_trace_pc_guard and make sure it is not asan/msan-instrumented
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293125 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-26 01:04:54 +00:00
Kostya Serebryany
13aa2bfeaf [libFuzzer] don't call GetPreviousInstructionPc on the hot path -- only when dumping the PCs
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293117 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-26 00:22:08 +00:00
Kostya Serebryany
72e0240a06 [libFuzzer] mutate empty input using the regular mutators (instead of a custom dummy one). This way when we mutate an empty input there is a chance we will get a dictionary word
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292843 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-23 22:52:13 +00:00
Kostya Serebryany
fc4ec25a17 [libFuzzer] make sure we use the feedback from std::string operator ==
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292835 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-23 22:11:04 +00:00