[llvm] r309615 - [libFuzzer] implement __sanitizer_cov_pcs_init and add pc-table to build flags for one test (for now)
Kostya Serebryany via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 31 13:20:59 PDT 2017
Author: kcc
Date: Mon Jul 31 13:20:59 2017
New Revision: 309615
URL: http://llvm.org/viewvc/llvm-project?rev=309615&view=rev
Log:
[libFuzzer] implement __sanitizer_cov_pcs_init and add pc-table to build flags for one test (for now)
Modified:
llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp
llvm/trunk/lib/Fuzzer/FuzzerTracePC.h
llvm/trunk/lib/Fuzzer/test/inline-8bit-counters/CMakeLists.txt
Modified: llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp?rev=309615&r1=309614&r2=309615&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp Mon Jul 31 13:20:59 2017
@@ -66,6 +66,15 @@ void TracePC::HandleInline8bitCountersIn
NumInline8bitCounters += Stop - Start;
}
+void TracePC::HandlePCsInit(const uint8_t *Start, const uint8_t *Stop) {
+ const uintptr_t *B = reinterpret_cast<const uintptr_t *>(Start);
+ const uintptr_t *E = reinterpret_cast<const uintptr_t *>(Stop);
+ if (NumPCTables && ModulePCTable[NumPCTables - 1].Start == B) return;
+ assert(NumPCTables < sizeof(ModulePCTable) / sizeof(ModulePCTable[0]));
+ ModulePCTable[NumPCTables++] = {B, E};
+ NumPCsInPCTables = E - B;
+}
+
void TracePC::HandleInit(uint32_t *Start, uint32_t *Stop) {
if (Start == Stop || *Start) return;
assert(NumModules < sizeof(Modules) / sizeof(Modules[0]));
@@ -85,17 +94,28 @@ void TracePC::HandleInit(uint32_t *Start
}
void TracePC::PrintModuleInfo() {
- Printf("INFO: Loaded %zd modules (%zd guards): ", NumModules, NumGuards);
- for (size_t i = 0; i < NumModules; i++)
- Printf("[%p, %p), ", Modules[i].Start, Modules[i].Stop);
- Printf("\n");
+ if (NumGuards) {
+ Printf("INFO: Loaded %zd modules (%zd guards): ", NumModules, NumGuards);
+ for (size_t i = 0; i < NumModules; i++)
+ Printf("[%p, %p), ", Modules[i].Start, Modules[i].Stop);
+ Printf("\n");
+ }
if (NumModulesWithInline8bitCounters) {
- Printf("INFO: Loaded %zd modules with %zd inline 8-bit counters\n",
+ Printf("INFO: Loaded %zd modules with %zd inline 8-bit counters: ",
NumModulesWithInline8bitCounters, NumInline8bitCounters);
for (size_t i = 0; i < NumModulesWithInline8bitCounters; i++)
Printf("[%p, %p), ", ModuleCounters[i].Start, ModuleCounters[i].Stop);
Printf("\n");
}
+ if (NumPCTables) {
+ Printf("INFO: Loaded %zd PC tables, %zd PCs: ", NumPCTables,
+ NumPCsInPCTables);
+ for (size_t i = 0; i < NumPCTables; i++) {
+ Printf("[%p,%p), ", ModulePCTable[i].Start, ModulePCTable[i].Stop,
+ ModulePCTable[i].Stop - ModulePCTable[i].Start);
+ }
+ Printf("\n");
+ }
}
ATTRIBUTE_NO_SANITIZE_ALL
@@ -354,6 +374,7 @@ void __sanitizer_cov_8bit_counters_init(
ATTRIBUTE_INTERFACE
void __sanitizer_cov_pcs_init(const uint8_t *pcs_beg, const uint8_t *pcs_end) {
+ fuzzer::TPC.HandlePCsInit(pcs_beg, pcs_end);
}
ATTRIBUTE_INTERFACE
Modified: llvm/trunk/lib/Fuzzer/FuzzerTracePC.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerTracePC.h?rev=309615&r1=309614&r2=309615&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerTracePC.h (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerTracePC.h Mon Jul 31 13:20:59 2017
@@ -75,6 +75,7 @@ class TracePC {
void HandleInit(uint32_t *Start, uint32_t *Stop);
void HandleInline8bitCountersInit(uint8_t *Start, uint8_t *Stop);
+ void HandlePCsInit(const uint8_t *Start, const uint8_t *Stop);
void HandleCallerCallee(uintptr_t Caller, uintptr_t Callee);
template <class T> void HandleCmp(uintptr_t PC, T Arg1, T Arg2);
size_t GetTotalPCCoverage();
@@ -149,6 +150,10 @@ private:
size_t NumModulesWithInline8bitCounters; // linker-initialized.
size_t NumInline8bitCounters;
+ struct { const uintptr_t *Start, *Stop; } ModulePCTable[4096];
+ size_t NumPCTables;
+ size_t NumPCsInPCTables;
+
uint8_t *Counters() const;
uintptr_t *PCs() const;
Modified: llvm/trunk/lib/Fuzzer/test/inline-8bit-counters/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/inline-8bit-counters/CMakeLists.txt?rev=309615&r1=309614&r2=309615&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/inline-8bit-counters/CMakeLists.txt (original)
+++ llvm/trunk/lib/Fuzzer/test/inline-8bit-counters/CMakeLists.txt Mon Jul 31 13:20:59 2017
@@ -1,7 +1,7 @@
# These tests are instrumented with -fsanitize-coverage=inline-8bit-counters
set(CMAKE_CXX_FLAGS
- "${LIBFUZZER_FLAGS_BASE} -fno-sanitize-coverage=trace-pc-guard -fsanitize-coverage=inline-8bit-counters")
+ "${LIBFUZZER_FLAGS_BASE} -fno-sanitize-coverage=trace-pc-guard -fsanitize-coverage=inline-8bit-counters,pc-table")
set(Inline8bitCounterTests
SimpleTest
More information about the llvm-commits
mailing list