Skip to content

Commit fc7faec

Browse files
[fuzzer] Use RawPrint instead of Printf for instrumentation warning
Summary: Use RawPrint instead of Printf for instrumentation warning because Printf doesn't work on Win when instrumentation is being initialized (since OutputFile is not yet initialized). Reviewers: kcc Reviewed By: kcc Differential Revision: https://reviews.llvm.org/D57531 llvm-svn: 352789
1 parent 4f9543b commit fc7faec

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

compiler-rt/lib/fuzzer/FuzzerIOWindows.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ bool IsInterestingCoverageFile(const std::string &FileName) {
334334

335335
void RawPrint(const char *Str) {
336336
// Not tested, may or may not work. Fix if needed.
337-
Printf("%s", Str);
337+
write(2, Str, strlen(Str));
338338
}
339339

340340
} // namespace fuzzer

compiler-rt/lib/fuzzer/FuzzerTracePC.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,13 @@ uintptr_t TracePC::GetMaxStackOffset() const {
403403
}
404404

405405
void WarnAboutDeprecatedInstrumentation(const char *flag) {
406-
Printf("libFuzzer does not support %s any more.\n"
407-
"Please either migrate to a compiler that supports -fsanitize=fuzzer\n"
408-
"or use an older version of libFuzzer\n", flag);
406+
// Use RawPrint because Printf cannot be used on Windows before OutputFile is
407+
// initialized.
408+
RawPrint(flag);
409+
RawPrint(
410+
" is no longer supported by libFuzzer.\n"
411+
"Please either migrate to a compiler that supports -fsanitize=fuzzer\n"
412+
"or use an older version of libFuzzer\n");
409413
exit(1);
410414
}
411415

@@ -415,16 +419,16 @@ extern "C" {
415419
ATTRIBUTE_INTERFACE
416420
ATTRIBUTE_NO_SANITIZE_ALL
417421
void __sanitizer_cov_trace_pc_guard(uint32_t *Guard) {
418-
fuzzer::WarnAboutDeprecatedInstrumentation("-fsanitize-coverage=trace-pc");
422+
fuzzer::WarnAboutDeprecatedInstrumentation(
423+
"-fsanitize-coverage=trace-pc-guard");
419424
}
420425

421426
// Best-effort support for -fsanitize-coverage=trace-pc, which is available
422427
// in both Clang and GCC.
423428
ATTRIBUTE_INTERFACE
424429
ATTRIBUTE_NO_SANITIZE_ALL
425430
void __sanitizer_cov_trace_pc() {
426-
fuzzer::WarnAboutDeprecatedInstrumentation(
427-
"-fsanitize-coverage=trace-pc-guard");
431+
fuzzer::WarnAboutDeprecatedInstrumentation("-fsanitize-coverage=trace-pc");
428432
}
429433

430434
ATTRIBUTE_INTERFACE
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CHECK: libFuzzer does not support -fsanitize-coverage=trace-pc
1+
CHECK: -fsanitize-coverage=trace-pc is no longer supported by libFuzzer
22
RUN: %cpp_compiler %S/SimpleTest.cpp -c -o %t-SimpleTest.o -fsanitize-coverage=trace-pc
33
RUN: %cpp_compiler %t-SimpleTest.o -o %t-SimpleTest
44
RUN: not %run %t-SimpleTest 2>&1 | FileCheck %s

0 commit comments

Comments
 (0)