diff options
author | Kostya Serebryany <kcc@google.com> | 2017-08-22 01:28:32 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2017-08-22 01:28:32 +0000 |
commit | f65cf64fa2d3f7804020b83719ad47969006ff2b (patch) | |
tree | b84bb30f6b6ada59e5799b59451dc49a8a7564c7 /compiler-rt/lib/fuzzer/FuzzerTracePC.cpp | |
parent | e4c532299237876eb8859ac786e326c79a12f83f (diff) | |
download | bcm5719-llvm-f65cf64fa2d3f7804020b83719ad47969006ff2b.tar.gz bcm5719-llvm-f65cf64fa2d3f7804020b83719ad47969006ff2b.zip |
[libFuzzer] apply changes lost during the migration to compiler-rt
llvm-svn: 311420
Diffstat (limited to 'compiler-rt/lib/fuzzer/FuzzerTracePC.cpp')
-rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerTracePC.cpp | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/compiler-rt/lib/fuzzer/FuzzerTracePC.cpp b/compiler-rt/lib/fuzzer/FuzzerTracePC.cpp index d038374dc43..ebd33d3ec88 100644 --- a/compiler-rt/lib/fuzzer/FuzzerTracePC.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerTracePC.cpp @@ -31,6 +31,9 @@ uint8_t __sancov_trace_pc_guard_8bit_counters[fuzzer::TracePC::kNumPCs]; ATTRIBUTE_INTERFACE uintptr_t __sancov_trace_pc_pcs[fuzzer::TracePC::kNumPCs]; +// Used by -fsanitize-coverage=stack-depth to track stack depth +ATTRIBUTE_INTERFACE thread_local uintptr_t __sancov_lowest_stack; + namespace fuzzer { TracePC TPC; @@ -126,6 +129,8 @@ void TracePC::PrintModuleInfo() { _Exit(1); } } + if (size_t NumClangCounters = ClangCountersEnd() - ClangCountersBegin()) + Printf("INFO: %zd Clang Coverage Counters\n", NumClangCounters); } ATTRIBUTE_NO_SANITIZE_ALL @@ -137,13 +142,12 @@ void TracePC::HandleCallerCallee(uintptr_t Caller, uintptr_t Callee) { } void TracePC::UpdateObservedPCs() { + auto Observe = [&](uintptr_t PC) { + bool Inserted = ObservedPCs.insert(PC).second; + if (Inserted && DoPrintNewPCs) + PrintPC("\tNEW_PC: %p %F %L\n", "\tNEW_PC: %p\n", PC + 1); + }; if (NumPCsInPCTables) { - auto Observe = [&](uintptr_t PC) { - bool Inserted = ObservedPCs.insert(PC).second; - if (Inserted && DoPrintNewPCs) - PrintPC("\tNEW_PC: %p %F %L\n", "\tNEW_PC: %p\n", PC + 1); - }; - if (NumInline8bitCounters == NumPCsInPCTables) { for (size_t i = 0; i < NumModulesWithInline8bitCounters; i++) { uint8_t *Beg = ModuleCounters[i].Start; @@ -167,6 +171,13 @@ void TracePC::UpdateObservedPCs() { } } } + if (size_t NumClangCounters = + ClangCountersEnd() - ClangCountersBegin()) { + auto P = ClangCountersBegin(); + for (size_t Idx = 0; Idx < NumClangCounters; Idx++) + if (P[Idx]) + Observe((uintptr_t)Idx); + } } inline ALWAYS_INLINE uintptr_t GetPreviousInstructionPc(uintptr_t PC) { @@ -332,6 +343,14 @@ void TracePC::ClearInlineCounters() { } } +void TracePC::RecordInitialStack() { + InitialStack = __sancov_lowest_stack; +} + +uintptr_t TracePC::GetMaxStackOffset() const { + return InitialStack - __sancov_lowest_stack; // Stack grows down +} + } // namespace fuzzer extern "C" { @@ -342,8 +361,6 @@ void __sanitizer_cov_trace_pc_guard(uint32_t *Guard) { uint32_t Idx = *Guard; __sancov_trace_pc_pcs[Idx] = PC; __sancov_trace_pc_guard_8bit_counters[Idx]++; - // Uncomment the following line to get stack-depth profiling. - // fuzzer::TPC.RecordCurrentStack(); } // Best-effort support for -fsanitize-coverage=trace-pc, which is available |