[compiler-rt] r311794 - [sanitizer-coverage] extend fsanitize-coverage=pc-table with flags for every PC
Kostya Serebryany via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 25 12:29:48 PDT 2017
Author: kcc
Date: Fri Aug 25 12:29:47 2017
New Revision: 311794
URL: http://llvm.org/viewvc/llvm-project?rev=311794&view=rev
Log:
[sanitizer-coverage] extend fsanitize-coverage=pc-table with flags for every PC
Modified:
compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.cpp
compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.h
compiler-rt/trunk/test/fuzzer/InitializeTest.cpp
compiler-rt/trunk/test/sanitizer_common/TestCases/sanitizer_coverage_inline8bit_counter.cc
Modified: compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.cpp?rev=311794&r1=311793&r2=311794&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.cpp (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.cpp Fri Aug 25 12:29:47 2017
@@ -70,9 +70,9 @@ 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);
+void TracePC::HandlePCsInit(const uintptr_t *Start, const uintptr_t *Stop) {
+ const PCTableEntry *B = reinterpret_cast<const PCTableEntry *>(Start);
+ const PCTableEntry *E = reinterpret_cast<const PCTableEntry *>(Stop);
if (NumPCTables && ModulePCTable[NumPCTables - 1].Start == B) return;
assert(NumPCTables < sizeof(ModulePCTable) / sizeof(ModulePCTable[0]));
ModulePCTable[NumPCTables++] = {B, E};
@@ -157,7 +157,7 @@ void TracePC::UpdateObservedPCs() {
(size_t)(ModulePCTable[i].Stop - ModulePCTable[i].Start));
for (size_t j = 0; j < Size; j++)
if (Beg[j])
- Observe(ModulePCTable[i].Start[j]);
+ Observe(ModulePCTable[i].Start[j].PC);
}
} else if (NumGuards == NumPCsInPCTables) {
size_t GuardIdx = 1;
@@ -168,7 +168,7 @@ void TracePC::UpdateObservedPCs() {
(size_t)(ModulePCTable[i].Stop - ModulePCTable[i].Start));
for (size_t j = 0; j < Size; j++, GuardIdx++)
if (Counters()[GuardIdx])
- Observe(ModulePCTable[i].Start[j]);
+ Observe(ModulePCTable[i].Start[j].PC);
}
}
}
@@ -240,9 +240,9 @@ void TracePC::PrintCoverage() {
for (size_t i = 0; i < NumPCTables; i++) {
auto &M = ModulePCTable[i];
assert(M.Start < M.Stop);
- auto ModuleName = GetModuleName(*M.Start);
+ auto ModuleName = GetModuleName(M.Start->PC);
for (auto Ptr = M.Start; Ptr < M.Stop; Ptr++) {
- auto PC = *Ptr;
+ auto PC = Ptr->PC;
auto VisualizePC = GetNextInstructionPc(PC);
bool IsObserved = ObservedPCs.count(PC);
std::string FileStr = DescribePC("%s", VisualizePC);
@@ -388,7 +388,8 @@ void __sanitizer_cov_8bit_counters_init(
}
ATTRIBUTE_INTERFACE
-void __sanitizer_cov_pcs_init(const uint8_t *pcs_beg, const uint8_t *pcs_end) {
+void __sanitizer_cov_pcs_init(const uintptr_t *pcs_beg,
+ const uintptr_t *pcs_end) {
fuzzer::TPC.HandlePCsInit(pcs_beg, pcs_end);
}
Modified: compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.h?rev=311794&r1=311793&r2=311794&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.h (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerTracePC.h Fri Aug 25 12:29:47 2017
@@ -75,7 +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 HandlePCsInit(const uintptr_t *Start, const uintptr_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();
@@ -146,7 +146,11 @@ private:
size_t NumModulesWithInline8bitCounters; // linker-initialized.
size_t NumInline8bitCounters;
- struct { const uintptr_t *Start, *Stop; } ModulePCTable[4096];
+ struct PCTableEntry {
+ uintptr_t PC, PCFlags;
+ };
+
+ struct { const PCTableEntry *Start, *Stop; } ModulePCTable[4096];
size_t NumPCTables;
size_t NumPCsInPCTables;
Modified: compiler-rt/trunk/test/fuzzer/InitializeTest.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/fuzzer/InitializeTest.cpp?rev=311794&r1=311793&r2=311794&view=diff
==============================================================================
--- compiler-rt/trunk/test/fuzzer/InitializeTest.cpp (original)
+++ compiler-rt/trunk/test/fuzzer/InitializeTest.cpp Fri Aug 25 12:29:47 2017
@@ -19,6 +19,7 @@ extern "C" int LLVMFuzzerInitialize(int
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
+ assert(argv0);
if (Size == strlen(argv0) &&
!memmem(Data, Size, argv0, Size)) {
fprintf(stderr, "BINGO %s\n", argv0);
Modified: compiler-rt/trunk/test/sanitizer_common/TestCases/sanitizer_coverage_inline8bit_counter.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/sanitizer_coverage_inline8bit_counter.cc?rev=311794&r1=311793&r2=311794&view=diff
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/sanitizer_coverage_inline8bit_counter.cc (original)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/sanitizer_coverage_inline8bit_counter.cc Fri Aug 25 12:29:47 2017
@@ -3,7 +3,9 @@
// REQUIRES: has_sancovcc,stable-runtime
// UNSUPPORTED: i386-darwin
//
-// RUN: %clangxx -O0 %s -fsanitize-coverage=inline-8bit-counters,pc-table 2>&1
+// RUN: %clangxx -O0 %s -fsanitize-coverage=inline-8bit-counters,pc-table -o %t
+// RUN: %run %t 2>&1 | FileCheck %s
+// XFAIL: tsan
#include <stdio.h>
#include <stdint.h>
@@ -19,13 +21,15 @@ void __sanitizer_cov_8bit_counters_init(
}
uintptr_t FirstPC;
+uintptr_t FirstPCFlag;
-extern "C" void __sanitizer_cov_pcs_init(const uint8_t *pcs_beg,
- const uint8_t *pcs_end) {
+extern "C" void __sanitizer_cov_pcs_init(const uintptr_t *pcs_beg,
+ const uintptr_t *pcs_end) {
const uintptr_t *B = (const uintptr_t *)pcs_beg;
const uintptr_t *E = (const uintptr_t *)pcs_end;
- assert(B < E);
- FirstPC = *B;
+ assert(B + 1 < E);
+ FirstPC = B[0];
+ FirstPCFlag = B[1];
}
@@ -33,4 +37,7 @@ int main() {
assert(first_counter);
assert(*first_counter == 1);
assert(FirstPC == (uintptr_t)&main);
+ assert(FirstPCFlag == 1);
+ fprintf(stderr, "PASS\n");
+ // CHECK: PASS
}
More information about the llvm-commits
mailing list