Kostya Serebryany | da63c1d | 2016-02-26 21:33:56 +0000 | [diff] [blame] | 1 | //===- 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 Serebryany | a00b243 | 2016-09-14 02:13:06 +0000 | [diff] [blame] | 10 | // This module implements __sanitizer_cov_trace_pc_guard[_init], |
| 11 | // the callback required for -fsanitize-coverage=trace-pc-guard instrumentation. |
Kostya Serebryany | da63c1d | 2016-02-26 21:33:56 +0000 | [diff] [blame] | 12 | // |
Kostya Serebryany | da63c1d | 2016-02-26 21:33:56 +0000 | [diff] [blame] | 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Kostya Serebryany | 1c73f1b | 2016-10-05 22:56:21 +0000 | [diff] [blame] | 15 | #include "FuzzerCorpus.h" |
Kostya Serebryany | 8658618 | 2016-09-21 21:17:23 +0000 | [diff] [blame] | 16 | #include "FuzzerDefs.h" |
Kostya Serebryany | a5f94fb | 2016-10-14 20:20:33 +0000 | [diff] [blame] | 17 | #include "FuzzerDictionary.h" |
Kostya Serebryany | 95b1a43 | 2016-10-19 00:12:03 +0000 | [diff] [blame] | 18 | #include "FuzzerExtFunctions.h" |
Zachary Turner | 24a148b | 2016-11-30 19:06:14 +0000 | [diff] [blame^] | 19 | #include "FuzzerIO.h" |
Kostya Serebryany | 6f5a804 | 2016-09-21 01:50:50 +0000 | [diff] [blame] | 20 | #include "FuzzerTracePC.h" |
Kostya Serebryany | 8658618 | 2016-09-21 21:17:23 +0000 | [diff] [blame] | 21 | #include "FuzzerValueBitMap.h" |
Zachary Turner | 24a148b | 2016-11-30 19:06:14 +0000 | [diff] [blame^] | 22 | #include <map> |
| 23 | #include <set> |
| 24 | #include <sstream> |
Kostya Serebryany | da63c1d | 2016-02-26 21:33:56 +0000 | [diff] [blame] | 25 | |
| 26 | namespace fuzzer { |
Mike Aizatsky | 1aa501e | 2016-05-10 23:43:15 +0000 | [diff] [blame] | 27 | |
Kostya Serebryany | a00b243 | 2016-09-14 02:13:06 +0000 | [diff] [blame] | 28 | TracePC TPC; |
Mike Aizatsky | 1aa501e | 2016-05-10 23:43:15 +0000 | [diff] [blame] | 29 | |
Kostya Serebryany | a9b0dd0 | 2016-09-29 17:43:24 +0000 | [diff] [blame] | 30 | void TracePC::HandleTrace(uint32_t *Guard, uintptr_t PC) { |
| 31 | uint32_t Idx = *Guard; |
Kostya Serebryany | 8e781a8 | 2016-09-18 04:52:23 +0000 | [diff] [blame] | 32 | if (!Idx) return; |
Kostya Serebryany | 2fabeca | 2016-10-26 18:52:04 +0000 | [diff] [blame] | 33 | PCs[Idx % kNumPCs] = PC; |
| 34 | Counters[Idx % kNumCounters]++; |
Kostya Serebryany | da63c1d | 2016-02-26 21:33:56 +0000 | [diff] [blame] | 35 | } |
Kostya Serebryany | a5277d5 | 2016-09-15 01:30:18 +0000 | [diff] [blame] | 36 | |
Kostya Serebryany | 275e260 | 2016-10-25 23:52:25 +0000 | [diff] [blame] | 37 | size_t TracePC::GetTotalPCCoverage() { |
| 38 | size_t Res = 0; |
Kostya Serebryany | 06b8757 | 2016-10-26 00:42:52 +0000 | [diff] [blame] | 39 | for (size_t i = 1; i < GetNumPCs(); i++) |
Kostya Serebryany | 275e260 | 2016-10-25 23:52:25 +0000 | [diff] [blame] | 40 | if (PCs[i]) |
| 41 | Res++; |
| 42 | return Res; |
| 43 | } |
| 44 | |
Kostya Serebryany | a9b0dd0 | 2016-09-29 17:43:24 +0000 | [diff] [blame] | 45 | void TracePC::HandleInit(uint32_t *Start, uint32_t *Stop) { |
Kostya Serebryany | 3e36ec1 | 2016-09-17 05:04:47 +0000 | [diff] [blame] | 46 | if (Start == Stop || *Start) return; |
| 47 | assert(NumModules < sizeof(Modules) / sizeof(Modules[0])); |
Kostya Serebryany | a9b0dd0 | 2016-09-29 17:43:24 +0000 | [diff] [blame] | 48 | for (uint32_t *P = Start; P < Stop; P++) |
Kostya Serebryany | 8e781a8 | 2016-09-18 04:52:23 +0000 | [diff] [blame] | 49 | *P = ++NumGuards; |
Kostya Serebryany | 3e36ec1 | 2016-09-17 05:04:47 +0000 | [diff] [blame] | 50 | Modules[NumModules].Start = Start; |
| 51 | Modules[NumModules].Stop = Stop; |
| 52 | NumModules++; |
| 53 | } |
| 54 | |
| 55 | void TracePC::PrintModuleInfo() { |
| 56 | Printf("INFO: Loaded %zd modules (%zd guards): ", NumModules, NumGuards); |
| 57 | for (size_t i = 0; i < NumModules; i++) |
| 58 | Printf("[%p, %p), ", Modules[i].Start, Modules[i].Stop); |
| 59 | Printf("\n"); |
Kostya Serebryany | da63c1d | 2016-02-26 21:33:56 +0000 | [diff] [blame] | 60 | } |
Kostya Serebryany | a5277d5 | 2016-09-15 01:30:18 +0000 | [diff] [blame] | 61 | |
Kostya Serebryany | 1c73f1b | 2016-10-05 22:56:21 +0000 | [diff] [blame] | 62 | size_t TracePC::FinalizeTrace(InputCorpus *C, size_t InputSize, bool Shrink) { |
| 63 | if (!UsingTracePcGuard()) return 0; |
| 64 | size_t Res = 0; |
| 65 | const size_t Step = 8; |
| 66 | assert(reinterpret_cast<uintptr_t>(Counters) % Step == 0); |
| 67 | size_t N = Min(kNumCounters, NumGuards + 1); |
| 68 | N = (N + Step - 1) & ~(Step - 1); // Round up. |
| 69 | for (size_t Idx = 0; Idx < N; Idx += Step) { |
| 70 | uint64_t Bundle = *reinterpret_cast<uint64_t*>(&Counters[Idx]); |
| 71 | if (!Bundle) continue; |
| 72 | for (size_t i = Idx; i < Idx + Step; i++) { |
| 73 | uint8_t Counter = (Bundle >> (i * 8)) & 0xff; |
| 74 | if (!Counter) continue; |
| 75 | Counters[i] = 0; |
| 76 | unsigned Bit = 0; |
| 77 | /**/ if (Counter >= 128) Bit = 7; |
| 78 | else if (Counter >= 32) Bit = 6; |
| 79 | else if (Counter >= 16) Bit = 5; |
| 80 | else if (Counter >= 8) Bit = 4; |
| 81 | else if (Counter >= 4) Bit = 3; |
| 82 | else if (Counter >= 3) Bit = 2; |
| 83 | else if (Counter >= 2) Bit = 1; |
| 84 | size_t Feature = (i * 8 + Bit); |
| 85 | if (C->AddFeature(Feature, InputSize, Shrink)) |
| 86 | Res++; |
Kostya Serebryany | a5277d5 | 2016-09-15 01:30:18 +0000 | [diff] [blame] | 87 | } |
| 88 | } |
Kostya Serebryany | 1c73f1b | 2016-10-05 22:56:21 +0000 | [diff] [blame] | 89 | if (UseValueProfile) |
| 90 | ValueProfileMap.ForEach([&](size_t Idx) { |
| 91 | if (C->AddFeature(NumGuards + Idx, InputSize, Shrink)) |
| 92 | Res++; |
| 93 | }); |
Kostya Serebryany | d216922 | 2016-10-01 01:04:29 +0000 | [diff] [blame] | 94 | return Res; |
Kostya Serebryany | a5277d5 | 2016-09-15 01:30:18 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Kostya Serebryany | 0984517 | 2016-09-15 22:16:15 +0000 | [diff] [blame] | 97 | void TracePC::HandleCallerCallee(uintptr_t Caller, uintptr_t Callee) { |
| 98 | const uintptr_t kBits = 12; |
| 99 | const uintptr_t kMask = (1 << kBits) - 1; |
Kostya Serebryany | 1c73f1b | 2016-10-05 22:56:21 +0000 | [diff] [blame] | 100 | uintptr_t Idx = (Caller & kMask) | ((Callee & kMask) << kBits); |
| 101 | HandleValueProfile(Idx); |
Kostya Serebryany | 0984517 | 2016-09-15 22:16:15 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Kostya Serebryany | 95b1a43 | 2016-10-19 00:12:03 +0000 | [diff] [blame] | 104 | static bool IsInterestingCoverageFile(std::string &File) { |
| 105 | if (File.find("compiler-rt/lib/") != std::string::npos) |
| 106 | return false; // sanitizer internal. |
| 107 | if (File.find("/usr/lib/") != std::string::npos) |
| 108 | return false; |
| 109 | if (File.find("/usr/include/") != std::string::npos) |
| 110 | return false; |
| 111 | if (File == "<null>") |
| 112 | return false; |
| 113 | return true; |
| 114 | } |
| 115 | |
Kostya Serebryany | a5b2e54 | 2016-10-26 00:20:51 +0000 | [diff] [blame] | 116 | void TracePC::PrintNewPCs() { |
| 117 | if (DoPrintNewPCs) { |
| 118 | if (!PrintedPCs) |
| 119 | PrintedPCs = new std::set<uintptr_t>; |
Kostya Serebryany | 06b8757 | 2016-10-26 00:42:52 +0000 | [diff] [blame] | 120 | for (size_t i = 1; i < GetNumPCs(); i++) |
Kostya Serebryany | a5b2e54 | 2016-10-26 00:20:51 +0000 | [diff] [blame] | 121 | if (PCs[i] && PrintedPCs->insert(PCs[i]).second) |
| 122 | PrintPC("\tNEW_PC: %p %F %L\n", "\tNEW_PC: %p\n", PCs[i]); |
| 123 | } |
| 124 | } |
| 125 | |
Kostya Serebryany | b706b48 | 2016-09-18 21:47:08 +0000 | [diff] [blame] | 126 | void TracePC::PrintCoverage() { |
Kostya Serebryany | 95b1a43 | 2016-10-19 00:12:03 +0000 | [diff] [blame] | 127 | if (!EF->__sanitizer_symbolize_pc) { |
| 128 | Printf("INFO: __sanitizer_symbolize_pc is not available," |
| 129 | " not printing coverage\n"); |
| 130 | return; |
| 131 | } |
| 132 | std::map<std::string, std::vector<uintptr_t>> CoveredPCsPerModule; |
| 133 | std::map<std::string, uintptr_t> ModuleOffsets; |
| 134 | std::set<std::string> CoveredFiles, CoveredFunctions, CoveredLines; |
Kostya Serebryany | b706b48 | 2016-09-18 21:47:08 +0000 | [diff] [blame] | 135 | Printf("COVERAGE:\n"); |
Kostya Serebryany | 06b8757 | 2016-10-26 00:42:52 +0000 | [diff] [blame] | 136 | for (size_t i = 1; i < GetNumPCs(); i++) { |
Kostya Serebryany | 95b1a43 | 2016-10-19 00:12:03 +0000 | [diff] [blame] | 137 | if (!PCs[i]) continue; |
| 138 | std::string FileStr = DescribePC("%s", PCs[i]); |
| 139 | if (!IsInterestingCoverageFile(FileStr)) continue; |
| 140 | std::string FixedPCStr = DescribePC("%p", PCs[i]); |
| 141 | std::string FunctionStr = DescribePC("%F", PCs[i]); |
| 142 | std::string LineStr = DescribePC("%l", PCs[i]); |
| 143 | // TODO(kcc): get the module using some other way since this |
| 144 | // does not work with ASAN_OPTIONS=strip_path_prefix=something. |
| 145 | std::string Module = DescribePC("%m", PCs[i]); |
| 146 | std::string OffsetStr = DescribePC("%o", PCs[i]); |
| 147 | uintptr_t FixedPC = std::stol(FixedPCStr, 0, 16); |
| 148 | uintptr_t PcOffset = std::stol(OffsetStr, 0, 16); |
| 149 | ModuleOffsets[Module] = FixedPC - PcOffset; |
| 150 | CoveredPCsPerModule[Module].push_back(PcOffset); |
| 151 | CoveredFunctions.insert(FunctionStr); |
| 152 | CoveredFiles.insert(FileStr); |
| 153 | if (!CoveredLines.insert(FileStr + ":" + LineStr).second) |
| 154 | continue; |
| 155 | Printf("COVERED: %s %s:%s\n", FunctionStr.c_str(), |
| 156 | FileStr.c_str(), LineStr.c_str()); |
| 157 | } |
| 158 | |
| 159 | for (auto &M : CoveredPCsPerModule) { |
| 160 | std::set<std::string> UncoveredFiles, UncoveredFunctions; |
| 161 | std::map<std::string, std::set<int> > UncoveredLines; // Func+File => lines |
| 162 | auto &ModuleName = M.first; |
| 163 | auto &CoveredOffsets = M.second; |
| 164 | uintptr_t ModuleOffset = ModuleOffsets[ModuleName]; |
| 165 | std::sort(CoveredOffsets.begin(), CoveredOffsets.end()); |
| 166 | Printf("MODULE_WITH_COVERAGE: %s\n", ModuleName.c_str()); |
| 167 | // sancov does not yet fully support DSOs. |
| 168 | // std::string Cmd = "sancov -print-coverage-pcs " + ModuleName; |
| 169 | std::string Cmd = "objdump -d " + ModuleName + |
| 170 | " | grep 'call.*__sanitizer_cov_trace_pc_guard' | awk -F: '{print $1}'"; |
| 171 | std::string SanCovOutput; |
| 172 | if (!ExecuteCommandAndReadOutput(Cmd, &SanCovOutput)) { |
| 173 | Printf("INFO: Command failed: %s\n", Cmd.c_str()); |
| 174 | continue; |
| 175 | } |
| 176 | std::istringstream ISS(SanCovOutput); |
| 177 | std::string S; |
| 178 | while (std::getline(ISS, S, '\n')) { |
| 179 | uintptr_t PcOffset = std::stol(S, 0, 16); |
| 180 | if (!std::binary_search(CoveredOffsets.begin(), CoveredOffsets.end(), |
| 181 | PcOffset)) { |
| 182 | uintptr_t PC = ModuleOffset + PcOffset; |
| 183 | auto FileStr = DescribePC("%s", PC); |
| 184 | if (!IsInterestingCoverageFile(FileStr)) continue; |
| 185 | if (CoveredFiles.count(FileStr) == 0) { |
| 186 | UncoveredFiles.insert(FileStr); |
| 187 | continue; |
| 188 | } |
| 189 | auto FunctionStr = DescribePC("%F", PC); |
| 190 | if (CoveredFunctions.count(FunctionStr) == 0) { |
| 191 | UncoveredFunctions.insert(FunctionStr); |
| 192 | continue; |
| 193 | } |
| 194 | std::string LineStr = DescribePC("%l", PC); |
| 195 | uintptr_t Line = std::stoi(LineStr); |
| 196 | std::string FileLineStr = FileStr + ":" + LineStr; |
| 197 | if (CoveredLines.count(FileLineStr) == 0) |
| 198 | UncoveredLines[FunctionStr + " " + FileStr].insert(Line); |
| 199 | } |
| 200 | } |
| 201 | for (auto &FileLine: UncoveredLines) |
| 202 | for (int Line : FileLine.second) |
| 203 | Printf("UNCOVERED_LINE: %s:%d\n", FileLine.first.c_str(), Line); |
| 204 | for (auto &Func : UncoveredFunctions) |
| 205 | Printf("UNCOVERED_FUNC: %s\n", Func.c_str()); |
| 206 | for (auto &File : UncoveredFiles) |
| 207 | Printf("UNCOVERED_FILE: %s\n", File.c_str()); |
Kostya Serebryany | b706b48 | 2016-09-18 21:47:08 +0000 | [diff] [blame] | 208 | } |
| 209 | } |
| 210 | |
Kostya Serebryany | 379359c | 2016-10-05 01:09:40 +0000 | [diff] [blame] | 211 | // Value profile. |
| 212 | // We keep track of various values that affect control flow. |
| 213 | // These values are inserted into a bit-set-based hash map. |
| 214 | // Every new bit in the map is treated as a new coverage. |
| 215 | // |
| 216 | // For memcmp/strcmp/etc the interesting value is the length of the common |
| 217 | // prefix of the parameters. |
| 218 | // For cmp instructions the interesting value is a XOR of the parameters. |
| 219 | // The interesting value is mixed up with the PC and is then added to the map. |
| 220 | |
Kostya Serebryany | 2356791 | 2016-11-11 23:06:53 +0000 | [diff] [blame] | 221 | #ifdef __clang__ // avoid gcc warning. |
| 222 | __attribute__((no_sanitize("memory"))) |
| 223 | #endif |
Kostya Serebryany | 379359c | 2016-10-05 01:09:40 +0000 | [diff] [blame] | 224 | void TracePC::AddValueForMemcmp(void *caller_pc, const void *s1, const void *s2, |
| 225 | size_t n) { |
| 226 | if (!n) return; |
| 227 | size_t Len = std::min(n, (size_t)32); |
| 228 | const uint8_t *A1 = reinterpret_cast<const uint8_t *>(s1); |
| 229 | const uint8_t *A2 = reinterpret_cast<const uint8_t *>(s2); |
| 230 | size_t I = 0; |
| 231 | for (; I < Len; I++) |
| 232 | if (A1[I] != A2[I]) |
| 233 | break; |
| 234 | size_t PC = reinterpret_cast<size_t>(caller_pc); |
| 235 | size_t Idx = I; |
| 236 | // if (I < Len) |
| 237 | // Idx += __builtin_popcountl((A1[I] ^ A2[I])) - 1; |
| 238 | TPC.HandleValueProfile((PC & 4095) | (Idx << 12)); |
| 239 | } |
| 240 | |
| 241 | void TracePC::AddValueForStrcmp(void *caller_pc, const char *s1, const char *s2, |
| 242 | size_t n) { |
| 243 | if (!n) return; |
| 244 | size_t Len = std::min(n, (size_t)32); |
| 245 | const uint8_t *A1 = reinterpret_cast<const uint8_t *>(s1); |
| 246 | const uint8_t *A2 = reinterpret_cast<const uint8_t *>(s2); |
| 247 | size_t I = 0; |
| 248 | for (; I < Len; I++) |
| 249 | if (A1[I] != A2[I] || A1[I] == 0) |
| 250 | break; |
| 251 | size_t PC = reinterpret_cast<size_t>(caller_pc); |
| 252 | size_t Idx = I; |
| 253 | // if (I < Len && A1[I]) |
| 254 | // Idx += __builtin_popcountl((A1[I] ^ A2[I])) - 1; |
| 255 | TPC.HandleValueProfile((PC & 4095) | (Idx << 12)); |
| 256 | } |
| 257 | |
Kostya Serebryany | 17d176e1 | 2016-10-13 16:19:09 +0000 | [diff] [blame] | 258 | template <class T> |
Kostya Serebryany | 379359c | 2016-10-05 01:09:40 +0000 | [diff] [blame] | 259 | ATTRIBUTE_TARGET_POPCNT |
Kostya Serebryany | 17d176e1 | 2016-10-13 16:19:09 +0000 | [diff] [blame] | 260 | #ifdef __clang__ // g++ can't handle this __attribute__ here :( |
| 261 | __attribute__((always_inline)) |
| 262 | #endif // __clang__ |
| 263 | void TracePC::HandleCmp(void *PC, T Arg1, T Arg2) { |
| 264 | uintptr_t PCuint = reinterpret_cast<uintptr_t>(PC); |
Kostya Serebryany | a5f94fb | 2016-10-14 20:20:33 +0000 | [diff] [blame] | 265 | uint64_t ArgXor = Arg1 ^ Arg2; |
| 266 | uint64_t ArgDistance = __builtin_popcountl(ArgXor) + 1; // [1,65] |
Kostya Serebryany | 17d176e1 | 2016-10-13 16:19:09 +0000 | [diff] [blame] | 267 | uintptr_t Idx = ((PCuint & 4095) + 1) * ArgDistance; |
Kostya Serebryany | 94c427c | 2016-10-27 00:36:38 +0000 | [diff] [blame] | 268 | if (sizeof(T) == 4) |
| 269 | TORC4.Insert(ArgXor, Arg1, Arg2); |
| 270 | else if (sizeof(T) == 8) |
| 271 | TORC8.Insert(ArgXor, Arg1, Arg2); |
Kostya Serebryany | 17d176e1 | 2016-10-13 16:19:09 +0000 | [diff] [blame] | 272 | HandleValueProfile(Idx); |
Kostya Serebryany | 379359c | 2016-10-05 01:09:40 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Kostya Serebryany | da63c1d | 2016-02-26 21:33:56 +0000 | [diff] [blame] | 275 | } // namespace fuzzer |
| 276 | |
Dan Liew | 5914407 | 2016-06-06 20:27:09 +0000 | [diff] [blame] | 277 | extern "C" { |
Kostya Serebryany | 32661f9 | 2016-08-18 20:52:52 +0000 | [diff] [blame] | 278 | __attribute__((visibility("default"))) |
Kostya Serebryany | a9b0dd0 | 2016-09-29 17:43:24 +0000 | [diff] [blame] | 279 | void __sanitizer_cov_trace_pc_guard(uint32_t *Guard) { |
Kostya Serebryany | a00b243 | 2016-09-14 02:13:06 +0000 | [diff] [blame] | 280 | uintptr_t PC = (uintptr_t)__builtin_return_address(0); |
Kostya Serebryany | a5277d5 | 2016-09-15 01:30:18 +0000 | [diff] [blame] | 281 | fuzzer::TPC.HandleTrace(Guard, PC); |
Kostya Serebryany | da63c1d | 2016-02-26 21:33:56 +0000 | [diff] [blame] | 282 | } |
Dan Liew | 5914407 | 2016-06-06 20:27:09 +0000 | [diff] [blame] | 283 | |
Kostya Serebryany | 32661f9 | 2016-08-18 20:52:52 +0000 | [diff] [blame] | 284 | __attribute__((visibility("default"))) |
Kostya Serebryany | a9b0dd0 | 2016-09-29 17:43:24 +0000 | [diff] [blame] | 285 | void __sanitizer_cov_trace_pc_guard_init(uint32_t *Start, uint32_t *Stop) { |
Kostya Serebryany | a5277d5 | 2016-09-15 01:30:18 +0000 | [diff] [blame] | 286 | fuzzer::TPC.HandleInit(Start, Stop); |
Dan Liew | 5914407 | 2016-06-06 20:27:09 +0000 | [diff] [blame] | 287 | } |
Kostya Serebryany | 0984517 | 2016-09-15 22:16:15 +0000 | [diff] [blame] | 288 | |
| 289 | __attribute__((visibility("default"))) |
| 290 | void __sanitizer_cov_trace_pc_indir(uintptr_t Callee) { |
| 291 | uintptr_t PC = (uintptr_t)__builtin_return_address(0); |
| 292 | fuzzer::TPC.HandleCallerCallee(PC, Callee); |
| 293 | } |
Kostya Serebryany | 379359c | 2016-10-05 01:09:40 +0000 | [diff] [blame] | 294 | |
Kostya Serebryany | 379359c | 2016-10-05 01:09:40 +0000 | [diff] [blame] | 295 | __attribute__((visibility("default"))) |
Kostya Serebryany | 17d176e1 | 2016-10-13 16:19:09 +0000 | [diff] [blame] | 296 | void __sanitizer_cov_trace_cmp8(uint64_t Arg1, uint64_t Arg2) { |
| 297 | fuzzer::TPC.HandleCmp(__builtin_return_address(0), Arg1, Arg2); |
Kostya Serebryany | 379359c | 2016-10-05 01:09:40 +0000 | [diff] [blame] | 298 | } |
| 299 | __attribute__((visibility("default"))) |
Kostya Serebryany | 17d176e1 | 2016-10-13 16:19:09 +0000 | [diff] [blame] | 300 | void __sanitizer_cov_trace_cmp4(uint32_t Arg1, uint32_t Arg2) { |
| 301 | fuzzer::TPC.HandleCmp(__builtin_return_address(0), Arg1, Arg2); |
Kostya Serebryany | 379359c | 2016-10-05 01:09:40 +0000 | [diff] [blame] | 302 | } |
| 303 | __attribute__((visibility("default"))) |
Kostya Serebryany | 17d176e1 | 2016-10-13 16:19:09 +0000 | [diff] [blame] | 304 | void __sanitizer_cov_trace_cmp2(uint16_t Arg1, uint16_t Arg2) { |
| 305 | fuzzer::TPC.HandleCmp(__builtin_return_address(0), Arg1, Arg2); |
Kostya Serebryany | 379359c | 2016-10-05 01:09:40 +0000 | [diff] [blame] | 306 | } |
| 307 | __attribute__((visibility("default"))) |
Kostya Serebryany | 17d176e1 | 2016-10-13 16:19:09 +0000 | [diff] [blame] | 308 | void __sanitizer_cov_trace_cmp1(uint8_t Arg1, uint8_t Arg2) { |
| 309 | fuzzer::TPC.HandleCmp(__builtin_return_address(0), Arg1, Arg2); |
Kostya Serebryany | 379359c | 2016-10-05 01:09:40 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | __attribute__((visibility("default"))) |
| 313 | void __sanitizer_cov_trace_switch(uint64_t Val, uint64_t *Cases) { |
Kostya Serebryany | d19919a | 2016-10-11 01:14:41 +0000 | [diff] [blame] | 314 | uint64_t N = Cases[0]; |
| 315 | uint64_t *Vals = Cases + 2; |
| 316 | char *PC = (char*)__builtin_return_address(0); |
| 317 | for (size_t i = 0; i < N; i++) |
| 318 | if (Val != Vals[i]) |
Kostya Serebryany | 17d176e1 | 2016-10-13 16:19:09 +0000 | [diff] [blame] | 319 | fuzzer::TPC.HandleCmp(PC + i, Val, Vals[i]); |
Kostya Serebryany | 379359c | 2016-10-05 01:09:40 +0000 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | __attribute__((visibility("default"))) |
| 323 | void __sanitizer_cov_trace_div4(uint32_t Val) { |
Kostya Serebryany | 17d176e1 | 2016-10-13 16:19:09 +0000 | [diff] [blame] | 324 | fuzzer::TPC.HandleCmp(__builtin_return_address(0), Val, (uint32_t)0); |
Kostya Serebryany | 379359c | 2016-10-05 01:09:40 +0000 | [diff] [blame] | 325 | } |
| 326 | __attribute__((visibility("default"))) |
| 327 | void __sanitizer_cov_trace_div8(uint64_t Val) { |
Kostya Serebryany | 17d176e1 | 2016-10-13 16:19:09 +0000 | [diff] [blame] | 328 | fuzzer::TPC.HandleCmp(__builtin_return_address(0), Val, (uint64_t)0); |
Kostya Serebryany | 379359c | 2016-10-05 01:09:40 +0000 | [diff] [blame] | 329 | } |
| 330 | __attribute__((visibility("default"))) |
| 331 | void __sanitizer_cov_trace_gep(uintptr_t Idx) { |
Kostya Serebryany | 17d176e1 | 2016-10-13 16:19:09 +0000 | [diff] [blame] | 332 | fuzzer::TPC.HandleCmp(__builtin_return_address(0), Idx, (uintptr_t)0); |
Kostya Serebryany | 379359c | 2016-10-05 01:09:40 +0000 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | } // extern "C" |