kcc | 1c0379f | 2017-08-22 01:28:32 +0000 | [diff] [blame] | 1 | //===- FuzzerExtraCounters.cpp - Extra coverage counters ------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // Coverage counters from Clang's SourceBasedCodeCoverage. |
| 10 | //===----------------------------------------------------------------------===// |
| 11 | |
| 12 | // Support for SourceBasedCodeCoverage is experimental: |
| 13 | // * Works only for the main binary, not DSOs yet. |
| 14 | // * Works only on Linux. |
| 15 | // * Does not implement print_pcs/print_coverage yet. |
| 16 | // * Is not fully evaluated for performance and sensitivity. |
| 17 | // We expect large performance drop due to 64-bit counters, |
| 18 | // and *maybe* better sensitivity due to more fine-grained counters. |
| 19 | // Preliminary comparison on a single benchmark (RE2) shows |
| 20 | // a bit worse sensitivity though. |
| 21 | |
| 22 | #include "FuzzerDefs.h" |
| 23 | |
| 24 | #if LIBFUZZER_LINUX |
| 25 | __attribute__((weak)) extern uint64_t __start___llvm_prf_cnts; |
| 26 | __attribute__((weak)) extern uint64_t __stop___llvm_prf_cnts; |
| 27 | namespace fuzzer { |
| 28 | uint64_t *ClangCountersBegin() { return &__start___llvm_prf_cnts; } |
| 29 | uint64_t *ClangCountersEnd() { return &__stop___llvm_prf_cnts; } |
| 30 | } // namespace fuzzer |
| 31 | #else |
| 32 | // TODO: Implement on Mac (if the data shows it's worth it). |
| 33 | //__attribute__((visibility("hidden"))) |
| 34 | //extern uint64_t CountersStart __asm("section$start$__DATA$__llvm_prf_cnts"); |
| 35 | //__attribute__((visibility("hidden"))) |
| 36 | //extern uint64_t CountersEnd __asm("section$end$__DATA$__llvm_prf_cnts"); |
| 37 | namespace fuzzer { |
| 38 | uint64_t *ClangCountersBegin() { return nullptr; } |
| 39 | uint64_t *ClangCountersEnd() { return nullptr; } |
| 40 | } // namespace fuzzer |
| 41 | #endif |
| 42 | |
| 43 | namespace fuzzer { |
| 44 | ATTRIBUTE_NO_SANITIZE_ALL |
| 45 | void ClearClangCounters() { // hand-written memset, don't asan-ify. |
| 46 | for (auto P = ClangCountersBegin(); P < ClangCountersEnd(); P++) |
| 47 | *P = 0; |
| 48 | } |
| 49 | } |