[compiler-rt] eae047a - sanitizer_common: tighten on_print hook test

Dmitry Vyukov via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 27 06:12:15 PDT 2021


Author: Dmitry Vyukov
Date: 2021-10-27T15:11:43+02:00
New Revision: eae047afe0d35efc85e23b1688fc859c53843893

URL: https://github.com/llvm/llvm-project/commit/eae047afe0d35efc85e23b1688fc859c53843893
DIFF: https://github.com/llvm/llvm-project/commit/eae047afe0d35efc85e23b1688fc859c53843893.diff

LOG: sanitizer_common: tighten on_print hook test

The new tsan runtime does not support arbitrary forms
of recursing into the runtime from hooks.
Disable instrumentation of the hook and use write instead
of fwrite (calls malloc internally).
The new version still recurses (write is intercepted),
but does not fail now (the issue at hand was malloc).

Depends on D112601.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D112602

Added: 
    

Modified: 
    compiler-rt/test/sanitizer_common/TestCases/onprint.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/test/sanitizer_common/TestCases/onprint.cpp b/compiler-rt/test/sanitizer_common/TestCases/onprint.cpp
index c5afb824714b8..8779efbb237d6 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/onprint.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/onprint.cpp
@@ -8,21 +8,25 @@
 // UNSUPPORTED: android
 
 #include <cassert>
-#include <cstdio>
 #include <cstdlib>
+#include <fcntl.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
 
-FILE *f;
+int f;
 volatile void *buf;
 volatile char sink;
 
-extern "C" void __sanitizer_on_print(const char *str) {
-  fprintf(f, "%s", str);
-  fflush(f);
+__attribute__((disable_sanitizer_instrumentation)) extern "C" void
+__sanitizer_on_print(const char *str) {
+  write(f, str, strlen(str));
 }
 
 int main(int argc, char *argv[]) {
   assert(argc >= 2);
-  f = fopen(argv[1], "w");
+  f = open(argv[1], O_WRONLY);
 
   // Use-after-free to trigger ASan/TSan reports.
   void *ptr = malloc(1);


        


More information about the llvm-commits mailing list