blob: 755f00a8f97fe09a12e7c3e34fb4a4daeb3225a0 [file] [log] [blame]
Kostya Serebryanyda63c1d2016-02-26 21:33:56 +00001//===- FuzzerTracePC.cpp - PC tracing--------------------------------------===//
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// Trace PCs.
Kostya Serebryanya00b2432016-09-14 02:13:06 +000010// This module implements __sanitizer_cov_trace_pc_guard[_init],
11// the callback required for -fsanitize-coverage=trace-pc-guard instrumentation.
Kostya Serebryanyda63c1d2016-02-26 21:33:56 +000012//
Kostya Serebryanyda63c1d2016-02-26 21:33:56 +000013//===----------------------------------------------------------------------===//
14
Kostya Serebryany1c73f1b2016-10-05 22:56:21 +000015#include "FuzzerCorpus.h"
Kostya Serebryany86586182016-09-21 21:17:23 +000016#include "FuzzerDefs.h"
Kostya Serebryanya5f94fb2016-10-14 20:20:33 +000017#include "FuzzerDictionary.h"
Kostya Serebryany95b1a432016-10-19 00:12:03 +000018#include "FuzzerExtFunctions.h"
Zachary Turner24a148b2016-11-30 19:06:14 +000019#include "FuzzerIO.h"
Kostya Serebryany6f5a8042016-09-21 01:50:50 +000020#include "FuzzerTracePC.h"
Marcos Pividori62c8fc52017-01-22 01:58:26 +000021#include "FuzzerUtil.h"
Kostya Serebryany86586182016-09-21 21:17:23 +000022#include "FuzzerValueBitMap.h"
Zachary Turner24a148b2016-11-30 19:06:14 +000023#include <map>
24#include <set>
25#include <sstream>
Kostya Serebryanyda63c1d2016-02-26 21:33:56 +000026
27namespace fuzzer {
Mike Aizatsky1aa501e2016-05-10 23:43:15 +000028
Kostya Serebryanya00b2432016-09-14 02:13:06 +000029TracePC TPC;
Mike Aizatsky1aa501e2016-05-10 23:43:15 +000030
Kostya Serebryanyd0ecb4c2017-01-26 01:04:54 +000031ATTRIBUTE_NO_SANITIZE_ALL
Kostya Serebryanya9b0dd02016-09-29 17:43:24 +000032void TracePC::HandleTrace(uint32_t *Guard, uintptr_t PC) {
33 uint32_t Idx = *Guard;
Kostya Serebryanyd0ecb4c2017-01-26 01:04:54 +000034 PCs[Idx] = PC;
Kostya Serebryany7856fb32017-01-26 01:34:58 +000035 Counters[Idx]++;
Kostya Serebryanyda63c1d2016-02-26 21:33:56 +000036}
Kostya Serebryanya5277d52016-09-15 01:30:18 +000037
Kostya Serebryany275e2602016-10-25 23:52:25 +000038size_t TracePC::GetTotalPCCoverage() {
39 size_t Res = 0;
Kostya Serebryany7856fb32017-01-26 01:34:58 +000040 for (size_t i = 1, N = GetNumPCs(); i < N; i++)
Kostya Serebryany275e2602016-10-25 23:52:25 +000041 if (PCs[i])
42 Res++;
43 return Res;
44}
45
Kostya Serebryanya9b0dd02016-09-29 17:43:24 +000046void TracePC::HandleInit(uint32_t *Start, uint32_t *Stop) {
Kostya Serebryany3e36ec12016-09-17 05:04:47 +000047 if (Start == Stop || *Start) return;
48 assert(NumModules < sizeof(Modules) / sizeof(Modules[0]));
Kostya Serebryanyd0ecb4c2017-01-26 01:04:54 +000049 for (uint32_t *P = Start; P < Stop; P++) {
50 NumGuards++;
51 if (NumGuards == kNumPCs) {
52 RawPrint(
53 "WARNING: The binary has too many instrumented PCs.\n"
54 " You may want to reduce the size of the binary\n"
55 " for more efficient fuzzing and precise coverage data\n");
56 }
57 *P = NumGuards % kNumPCs;
58 }
Kostya Serebryany3e36ec12016-09-17 05:04:47 +000059 Modules[NumModules].Start = Start;
60 Modules[NumModules].Stop = Stop;
61 NumModules++;
62}
63
64void TracePC::PrintModuleInfo() {
65 Printf("INFO: Loaded %zd modules (%zd guards): ", NumModules, NumGuards);
66 for (size_t i = 0; i < NumModules; i++)
67 Printf("[%p, %p), ", Modules[i].Start, Modules[i].Stop);
68 Printf("\n");
Kostya Serebryanyda63c1d2016-02-26 21:33:56 +000069}
Kostya Serebryanya5277d52016-09-15 01:30:18 +000070
Kostya Serebryany09845172016-09-15 22:16:15 +000071void TracePC::HandleCallerCallee(uintptr_t Caller, uintptr_t Callee) {
72 const uintptr_t kBits = 12;
73 const uintptr_t kMask = (1 << kBits) - 1;
Kostya Serebryany1c73f1b2016-10-05 22:56:21 +000074 uintptr_t Idx = (Caller & kMask) | ((Callee & kMask) << kBits);
75 HandleValueProfile(Idx);
Kostya Serebryany09845172016-09-15 22:16:15 +000076}
77
Kostya Serebryany11a22bc2016-12-30 01:13:07 +000078void TracePC::InitializePrintNewPCs() {
Kostya Serebryany4986e812017-01-03 18:51:28 +000079 if (!DoPrintNewPCs) return;
Kostya Serebryany11a22bc2016-12-30 01:13:07 +000080 assert(!PrintedPCs);
81 PrintedPCs = new std::set<uintptr_t>;
82 for (size_t i = 1; i < GetNumPCs(); i++)
83 if (PCs[i])
84 PrintedPCs->insert(PCs[i]);
85}
86
Kostya Serebryanya5b2e542016-10-26 00:20:51 +000087void TracePC::PrintNewPCs() {
Kostya Serebryany4986e812017-01-03 18:51:28 +000088 if (!DoPrintNewPCs) return;
Kostya Serebryany11a22bc2016-12-30 01:13:07 +000089 assert(PrintedPCs);
90 for (size_t i = 1; i < GetNumPCs(); i++)
91 if (PCs[i] && PrintedPCs->insert(PCs[i]).second)
92 PrintPC("\tNEW_PC: %p %F %L\n", "\tNEW_PC: %p\n", PCs[i]);
Kostya Serebryanya5b2e542016-10-26 00:20:51 +000093}
94
Kostya Serebryanyb706b482016-09-18 21:47:08 +000095void TracePC::PrintCoverage() {
Kostya Serebryany1394ce22016-12-10 01:19:35 +000096 if (!EF->__sanitizer_symbolize_pc ||
97 !EF->__sanitizer_get_module_and_offset_for_pc) {
98 Printf("INFO: __sanitizer_symbolize_pc or "
99 "__sanitizer_get_module_and_offset_for_pc is not available,"
Kostya Serebryany95b1a432016-10-19 00:12:03 +0000100 " not printing coverage\n");
101 return;
102 }
103 std::map<std::string, std::vector<uintptr_t>> CoveredPCsPerModule;
104 std::map<std::string, uintptr_t> ModuleOffsets;
Kostya Serebryany1cba0a92016-11-30 21:53:32 +0000105 std::set<std::string> CoveredDirs, CoveredFiles, CoveredFunctions,
106 CoveredLines;
Kostya Serebryanyb706b482016-09-18 21:47:08 +0000107 Printf("COVERAGE:\n");
Kostya Serebryany06b87572016-10-26 00:42:52 +0000108 for (size_t i = 1; i < GetNumPCs(); i++) {
Kostya Serebryany95b1a432016-10-19 00:12:03 +0000109 if (!PCs[i]) continue;
110 std::string FileStr = DescribePC("%s", PCs[i]);
111 if (!IsInterestingCoverageFile(FileStr)) continue;
112 std::string FixedPCStr = DescribePC("%p", PCs[i]);
113 std::string FunctionStr = DescribePC("%F", PCs[i]);
114 std::string LineStr = DescribePC("%l", PCs[i]);
Kostya Serebryany1394ce22016-12-10 01:19:35 +0000115 char ModulePathRaw[4096] = ""; // What's PATH_MAX in portable C++?
116 void *OffsetRaw = nullptr;
117 if (!EF->__sanitizer_get_module_and_offset_for_pc(
118 reinterpret_cast<void *>(PCs[i]), ModulePathRaw,
119 sizeof(ModulePathRaw), &OffsetRaw))
120 continue;
121 std::string Module = ModulePathRaw;
Kostya Serebryany95b1a432016-10-19 00:12:03 +0000122 uintptr_t FixedPC = std::stol(FixedPCStr, 0, 16);
Kostya Serebryany1394ce22016-12-10 01:19:35 +0000123 uintptr_t PcOffset = reinterpret_cast<uintptr_t>(OffsetRaw);
Kostya Serebryany95b1a432016-10-19 00:12:03 +0000124 ModuleOffsets[Module] = FixedPC - PcOffset;
125 CoveredPCsPerModule[Module].push_back(PcOffset);
126 CoveredFunctions.insert(FunctionStr);
127 CoveredFiles.insert(FileStr);
Kostya Serebryany1cba0a92016-11-30 21:53:32 +0000128 CoveredDirs.insert(DirName(FileStr));
Kostya Serebryany95b1a432016-10-19 00:12:03 +0000129 if (!CoveredLines.insert(FileStr + ":" + LineStr).second)
130 continue;
131 Printf("COVERED: %s %s:%s\n", FunctionStr.c_str(),
132 FileStr.c_str(), LineStr.c_str());
133 }
134
Kostya Serebryany1cba0a92016-11-30 21:53:32 +0000135 std::string CoveredDirsStr;
136 for (auto &Dir : CoveredDirs) {
137 if (!CoveredDirsStr.empty())
138 CoveredDirsStr += ",";
139 CoveredDirsStr += Dir;
140 }
141 Printf("COVERED_DIRS: %s\n", CoveredDirsStr.c_str());
142
Kostya Serebryany95b1a432016-10-19 00:12:03 +0000143 for (auto &M : CoveredPCsPerModule) {
144 std::set<std::string> UncoveredFiles, UncoveredFunctions;
145 std::map<std::string, std::set<int> > UncoveredLines; // Func+File => lines
146 auto &ModuleName = M.first;
147 auto &CoveredOffsets = M.second;
148 uintptr_t ModuleOffset = ModuleOffsets[ModuleName];
149 std::sort(CoveredOffsets.begin(), CoveredOffsets.end());
150 Printf("MODULE_WITH_COVERAGE: %s\n", ModuleName.c_str());
151 // sancov does not yet fully support DSOs.
152 // std::string Cmd = "sancov -print-coverage-pcs " + ModuleName;
Marcos Pividori62c8fc52017-01-22 01:58:26 +0000153 std::string Cmd = DisassembleCmd(ModuleName) + " | " +
154 SearchRegexCmd("call.*__sanitizer_cov_trace_pc_guard");
Kostya Serebryany95b1a432016-10-19 00:12:03 +0000155 std::string SanCovOutput;
156 if (!ExecuteCommandAndReadOutput(Cmd, &SanCovOutput)) {
157 Printf("INFO: Command failed: %s\n", Cmd.c_str());
158 continue;
159 }
160 std::istringstream ISS(SanCovOutput);
161 std::string S;
162 while (std::getline(ISS, S, '\n')) {
Marcos Pividori62c8fc52017-01-22 01:58:26 +0000163 size_t PcOffsetEnd = S.find(':');
164 if (PcOffsetEnd == std::string::npos)
165 continue;
166 S.resize(PcOffsetEnd);
Kostya Serebryany95b1a432016-10-19 00:12:03 +0000167 uintptr_t PcOffset = std::stol(S, 0, 16);
168 if (!std::binary_search(CoveredOffsets.begin(), CoveredOffsets.end(),
169 PcOffset)) {
170 uintptr_t PC = ModuleOffset + PcOffset;
171 auto FileStr = DescribePC("%s", PC);
172 if (!IsInterestingCoverageFile(FileStr)) continue;
173 if (CoveredFiles.count(FileStr) == 0) {
174 UncoveredFiles.insert(FileStr);
175 continue;
176 }
177 auto FunctionStr = DescribePC("%F", PC);
178 if (CoveredFunctions.count(FunctionStr) == 0) {
179 UncoveredFunctions.insert(FunctionStr);
180 continue;
181 }
182 std::string LineStr = DescribePC("%l", PC);
183 uintptr_t Line = std::stoi(LineStr);
184 std::string FileLineStr = FileStr + ":" + LineStr;
185 if (CoveredLines.count(FileLineStr) == 0)
186 UncoveredLines[FunctionStr + " " + FileStr].insert(Line);
187 }
188 }
189 for (auto &FileLine: UncoveredLines)
190 for (int Line : FileLine.second)
191 Printf("UNCOVERED_LINE: %s:%d\n", FileLine.first.c_str(), Line);
192 for (auto &Func : UncoveredFunctions)
193 Printf("UNCOVERED_FUNC: %s\n", Func.c_str());
194 for (auto &File : UncoveredFiles)
195 Printf("UNCOVERED_FILE: %s\n", File.c_str());
Kostya Serebryanyb706b482016-09-18 21:47:08 +0000196 }
197}
198
Kostya Serebryany7c021af2017-01-26 00:22:08 +0000199inline ALWAYS_INLINE uintptr_t GetPreviousInstructionPc(uintptr_t PC) {
200 // TODO: this implementation is x86 only.
201 // see sanitizer_common GetPreviousInstructionPc for full implementation.
202 return PC - 1;
203}
204
Mike Aizatsky9b415be2016-12-19 22:18:08 +0000205void TracePC::DumpCoverage() {
Kostya Serebryany7c021af2017-01-26 00:22:08 +0000206 if (EF->__sanitizer_dump_coverage) {
207 std::vector<uintptr_t> PCsCopy(GetNumPCs());
208 for (size_t i = 0; i < GetNumPCs(); i++)
209 PCsCopy[i] = PCs[i] ? GetPreviousInstructionPc(PCs[i]) : 0;
210 EF->__sanitizer_dump_coverage(PCsCopy.data(), PCsCopy.size());
211 }
Mike Aizatsky9b415be2016-12-19 22:18:08 +0000212}
213
Kostya Serebryany379359c2016-10-05 01:09:40 +0000214// Value profile.
215// We keep track of various values that affect control flow.
216// These values are inserted into a bit-set-based hash map.
217// Every new bit in the map is treated as a new coverage.
218//
219// For memcmp/strcmp/etc the interesting value is the length of the common
220// prefix of the parameters.
221// For cmp instructions the interesting value is a XOR of the parameters.
222// The interesting value is mixed up with the PC and is then added to the map.
223
Kostya Serebryany3a4e2dd2016-12-16 22:45:25 +0000224ATTRIBUTE_NO_SANITIZE_MEMORY
Kostya Serebryany379359c2016-10-05 01:09:40 +0000225void TracePC::AddValueForMemcmp(void *caller_pc, const void *s1, const void *s2,
Kostya Serebryany1d8c2ce2017-01-17 23:09:05 +0000226 size_t n, bool StopAtZero) {
Kostya Serebryany379359c2016-10-05 01:09:40 +0000227 if (!n) return;
Kostya Serebryany1d8c2ce2017-01-17 23:09:05 +0000228 size_t Len = std::min(n, Word::GetMaxSize());
Kostya Serebryany379359c2016-10-05 01:09:40 +0000229 const uint8_t *A1 = reinterpret_cast<const uint8_t *>(s1);
230 const uint8_t *A2 = reinterpret_cast<const uint8_t *>(s2);
Kostya Serebryany1d8c2ce2017-01-17 23:09:05 +0000231 uint8_t B1[Word::kMaxSize];
232 uint8_t B2[Word::kMaxSize];
233 // Copy the data into locals in this non-msan-instrumented function
234 // to avoid msan complaining further.
Kostya Serebryany6bdd8fc2017-01-23 22:11:04 +0000235 size_t Hash = 0; // Compute some simple hash of both strings.
Kostya Serebryany1d8c2ce2017-01-17 23:09:05 +0000236 for (size_t i = 0; i < Len; i++) {
237 B1[i] = A1[i];
238 B2[i] = A2[i];
Kostya Serebryany6bdd8fc2017-01-23 22:11:04 +0000239 size_t T = B1[i];
240 Hash ^= (T << 8) | B2[i];
Kostya Serebryany1d8c2ce2017-01-17 23:09:05 +0000241 }
Kostya Serebryany379359c2016-10-05 01:09:40 +0000242 size_t I = 0;
243 for (; I < Len; I++)
Kostya Serebryany1d8c2ce2017-01-17 23:09:05 +0000244 if (B1[I] != B2[I] || (StopAtZero && B1[I] == 0))
Kostya Serebryany379359c2016-10-05 01:09:40 +0000245 break;
246 size_t PC = reinterpret_cast<size_t>(caller_pc);
Kostya Serebryany1d8c2ce2017-01-17 23:09:05 +0000247 size_t Idx = (PC & 4095) | (I << 12);
248 TPC.HandleValueProfile(Idx);
Kostya Serebryany6bdd8fc2017-01-23 22:11:04 +0000249 TORCW.Insert(Idx ^ Hash, Word(B1, Len), Word(B2, Len));
Kostya Serebryany379359c2016-10-05 01:09:40 +0000250}
251
Kostya Serebryany17d176e12016-10-13 16:19:09 +0000252template <class T>
Mike Aizatsky0e37f8e2017-01-17 23:11:32 +0000253ATTRIBUTE_TARGET_POPCNT ALWAYS_INLINE
254void TracePC::HandleCmp(uintptr_t PC, T Arg1, T Arg2) {
Kostya Serebryanya5f94fb2016-10-14 20:20:33 +0000255 uint64_t ArgXor = Arg1 ^ Arg2;
256 uint64_t ArgDistance = __builtin_popcountl(ArgXor) + 1; // [1,65]
Mike Aizatsky0e37f8e2017-01-17 23:11:32 +0000257 uintptr_t Idx = ((PC & 4095) + 1) * ArgDistance;
Kostya Serebryany94c427c2016-10-27 00:36:38 +0000258 if (sizeof(T) == 4)
259 TORC4.Insert(ArgXor, Arg1, Arg2);
260 else if (sizeof(T) == 8)
261 TORC8.Insert(ArgXor, Arg1, Arg2);
Kostya Serebryany17d176e12016-10-13 16:19:09 +0000262 HandleValueProfile(Idx);
Kostya Serebryany379359c2016-10-05 01:09:40 +0000263}
264
Kostya Serebryanyda63c1d2016-02-26 21:33:56 +0000265} // namespace fuzzer
266
Dan Liew59144072016-06-06 20:27:09 +0000267extern "C" {
Marcos Pividori6137f982017-01-22 01:27:38 +0000268ATTRIBUTE_INTERFACE
Kostya Serebryanyd0ecb4c2017-01-26 01:04:54 +0000269ATTRIBUTE_NO_SANITIZE_ALL
Kostya Serebryanya9b0dd02016-09-29 17:43:24 +0000270void __sanitizer_cov_trace_pc_guard(uint32_t *Guard) {
Kostya Serebryany7c021af2017-01-26 00:22:08 +0000271 uintptr_t PC = reinterpret_cast<uintptr_t>(__builtin_return_address(0));
Kostya Serebryanya5277d52016-09-15 01:30:18 +0000272 fuzzer::TPC.HandleTrace(Guard, PC);
Kostya Serebryanyda63c1d2016-02-26 21:33:56 +0000273}
Dan Liew59144072016-06-06 20:27:09 +0000274
Marcos Pividori6137f982017-01-22 01:27:38 +0000275ATTRIBUTE_INTERFACE
Kostya Serebryanya9b0dd02016-09-29 17:43:24 +0000276void __sanitizer_cov_trace_pc_guard_init(uint32_t *Start, uint32_t *Stop) {
Kostya Serebryanya5277d52016-09-15 01:30:18 +0000277 fuzzer::TPC.HandleInit(Start, Stop);
Dan Liew59144072016-06-06 20:27:09 +0000278}
Kostya Serebryany09845172016-09-15 22:16:15 +0000279
Marcos Pividori6137f982017-01-22 01:27:38 +0000280ATTRIBUTE_INTERFACE
Kostya Serebryany09845172016-09-15 22:16:15 +0000281void __sanitizer_cov_trace_pc_indir(uintptr_t Callee) {
Kostya Serebryany7c021af2017-01-26 00:22:08 +0000282 uintptr_t PC = reinterpret_cast<uintptr_t>(__builtin_return_address(0));
Kostya Serebryany09845172016-09-15 22:16:15 +0000283 fuzzer::TPC.HandleCallerCallee(PC, Callee);
284}
Kostya Serebryany379359c2016-10-05 01:09:40 +0000285
Marcos Pividori6137f982017-01-22 01:27:38 +0000286ATTRIBUTE_INTERFACE
Kostya Serebryany17d176e12016-10-13 16:19:09 +0000287void __sanitizer_cov_trace_cmp8(uint64_t Arg1, uint64_t Arg2) {
Kostya Serebryany7c021af2017-01-26 00:22:08 +0000288 uintptr_t PC = reinterpret_cast<uintptr_t>(__builtin_return_address(0));
Mike Aizatsky0e37f8e2017-01-17 23:11:32 +0000289 fuzzer::TPC.HandleCmp(PC, Arg1, Arg2);
Kostya Serebryany379359c2016-10-05 01:09:40 +0000290}
Marcos Pividori6137f982017-01-22 01:27:38 +0000291
292ATTRIBUTE_INTERFACE
Kostya Serebryany17d176e12016-10-13 16:19:09 +0000293void __sanitizer_cov_trace_cmp4(uint32_t Arg1, uint32_t Arg2) {
Kostya Serebryany7c021af2017-01-26 00:22:08 +0000294 uintptr_t PC = reinterpret_cast<uintptr_t>(__builtin_return_address(0));
Mike Aizatsky0e37f8e2017-01-17 23:11:32 +0000295 fuzzer::TPC.HandleCmp(PC, Arg1, Arg2);
Kostya Serebryany379359c2016-10-05 01:09:40 +0000296}
Marcos Pividori6137f982017-01-22 01:27:38 +0000297
298ATTRIBUTE_INTERFACE
Kostya Serebryany17d176e12016-10-13 16:19:09 +0000299void __sanitizer_cov_trace_cmp2(uint16_t Arg1, uint16_t Arg2) {
Kostya Serebryany7c021af2017-01-26 00:22:08 +0000300 uintptr_t PC = reinterpret_cast<uintptr_t>(__builtin_return_address(0));
Mike Aizatsky0e37f8e2017-01-17 23:11:32 +0000301 fuzzer::TPC.HandleCmp(PC, Arg1, Arg2);
Kostya Serebryany379359c2016-10-05 01:09:40 +0000302}
Marcos Pividori6137f982017-01-22 01:27:38 +0000303
304ATTRIBUTE_INTERFACE
Kostya Serebryany17d176e12016-10-13 16:19:09 +0000305void __sanitizer_cov_trace_cmp1(uint8_t Arg1, uint8_t Arg2) {
Kostya Serebryany7c021af2017-01-26 00:22:08 +0000306 uintptr_t PC = reinterpret_cast<uintptr_t>(__builtin_return_address(0));
Mike Aizatsky0e37f8e2017-01-17 23:11:32 +0000307 fuzzer::TPC.HandleCmp(PC, Arg1, Arg2);
Kostya Serebryany379359c2016-10-05 01:09:40 +0000308}
309
Marcos Pividori6137f982017-01-22 01:27:38 +0000310ATTRIBUTE_INTERFACE
Kostya Serebryany379359c2016-10-05 01:09:40 +0000311void __sanitizer_cov_trace_switch(uint64_t Val, uint64_t *Cases) {
Kostya Serebryanyd19919a2016-10-11 01:14:41 +0000312 uint64_t N = Cases[0];
Kostya Serebryanyd7238042016-12-29 02:50:35 +0000313 uint64_t ValSizeInBits = Cases[1];
Kostya Serebryanyd19919a2016-10-11 01:14:41 +0000314 uint64_t *Vals = Cases + 2;
Kostya Serebryanyd7238042016-12-29 02:50:35 +0000315 // Skip the most common and the most boring case.
316 if (Vals[N - 1] < 256 && Val < 256)
317 return;
Kostya Serebryany7c021af2017-01-26 00:22:08 +0000318 uintptr_t PC = reinterpret_cast<uintptr_t>(__builtin_return_address(0));
Kostya Serebryanyd7238042016-12-29 02:50:35 +0000319 size_t i;
320 uint64_t Token = 0;
321 for (i = 0; i < N; i++) {
322 Token = Val ^ Vals[i];
323 if (Val < Vals[i])
324 break;
325 }
326
327 if (ValSizeInBits == 16)
328 fuzzer::TPC.HandleCmp(PC + i, static_cast<uint16_t>(Token), (uint16_t)(0));
329 else if (ValSizeInBits == 32)
330 fuzzer::TPC.HandleCmp(PC + i, static_cast<uint32_t>(Token), (uint32_t)(0));
Kostya Serebryany00e638e2016-12-17 02:03:34 +0000331 else
Kostya Serebryanyd7238042016-12-29 02:50:35 +0000332 fuzzer::TPC.HandleCmp(PC + i, Token, (uint64_t)(0));
Kostya Serebryany379359c2016-10-05 01:09:40 +0000333}
334
Marcos Pividori6137f982017-01-22 01:27:38 +0000335ATTRIBUTE_INTERFACE
Kostya Serebryany379359c2016-10-05 01:09:40 +0000336void __sanitizer_cov_trace_div4(uint32_t Val) {
Kostya Serebryany7c021af2017-01-26 00:22:08 +0000337 uintptr_t PC = reinterpret_cast<uintptr_t>(__builtin_return_address(0));
Mike Aizatsky0e37f8e2017-01-17 23:11:32 +0000338 fuzzer::TPC.HandleCmp(PC, Val, (uint32_t)0);
Kostya Serebryany379359c2016-10-05 01:09:40 +0000339}
Marcos Pividori6137f982017-01-22 01:27:38 +0000340
341ATTRIBUTE_INTERFACE
Kostya Serebryany379359c2016-10-05 01:09:40 +0000342void __sanitizer_cov_trace_div8(uint64_t Val) {
Kostya Serebryany7c021af2017-01-26 00:22:08 +0000343 uintptr_t PC = reinterpret_cast<uintptr_t>(__builtin_return_address(0));
Mike Aizatsky0e37f8e2017-01-17 23:11:32 +0000344 fuzzer::TPC.HandleCmp(PC, Val, (uint64_t)0);
Kostya Serebryany379359c2016-10-05 01:09:40 +0000345}
Marcos Pividori6137f982017-01-22 01:27:38 +0000346
347ATTRIBUTE_INTERFACE
Kostya Serebryany379359c2016-10-05 01:09:40 +0000348void __sanitizer_cov_trace_gep(uintptr_t Idx) {
Kostya Serebryany7c021af2017-01-26 00:22:08 +0000349 uintptr_t PC = reinterpret_cast<uintptr_t>(__builtin_return_address(0));
Mike Aizatsky0e37f8e2017-01-17 23:11:32 +0000350 fuzzer::TPC.HandleCmp(PC, Idx, (uintptr_t)0);
Kostya Serebryany379359c2016-10-05 01:09:40 +0000351}
Kostya Serebryany379359c2016-10-05 01:09:40 +0000352} // extern "C"