bmalloc should automatically disable itself when ThreadSanitizer is used
authorddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 May 2016 23:47:10 +0000 (23:47 +0000)
committerddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 May 2016 23:47:10 +0000 (23:47 +0000)
<https://webkit.org/b/157527>

Reviewed by Michael Catanzaro.

* bmalloc/Environment.cpp:
(bmalloc::isASanEnabled): Rename to isSanitizerEnabled.
(bmalloc::isSanitizerEnabled): Rename from isASanEnabled. Add
support for detecting ThreadSanitizer.
(bmalloc::Environment::computeIsBmallocEnabled): Switch from
isASanEnabled to isSanitizerEnabled.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200654 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/bmalloc/ChangeLog
Source/bmalloc/bmalloc/Environment.cpp

index bbc9100..fa0ad57 100644 (file)
@@ -1,3 +1,17 @@
+2016-05-10  David Kilzer  <ddkilzer@apple.com>
+
+        bmalloc should automatically disable itself when ThreadSanitizer is used
+        <https://webkit.org/b/157527>
+
+        Reviewed by Michael Catanzaro.
+
+        * bmalloc/Environment.cpp:
+        (bmalloc::isASanEnabled): Rename to isSanitizerEnabled.
+        (bmalloc::isSanitizerEnabled): Rename from isASanEnabled. Add
+        support for detecting ThreadSanitizer.
+        (bmalloc::Environment::computeIsBmallocEnabled): Switch from
+        isASanEnabled to isSanitizerEnabled.
+
 2016-05-03  Geoffrey Garen  <ggaren@apple.com>
 
         Assertion failure in bmalloc::vmRevokePermissions(void*, unsigned long).
index 2f08ec7..0d95071 100644 (file)
@@ -75,23 +75,31 @@ static bool isLibgmallocEnabled()
     return true;
 }
 
-static bool isASanEnabled()
+static bool isSanitizerEnabled()
 {
 #if BOS(DARWIN)
+    static const char sanitizerPrefix[] = "/libclang_rt.";
+    static const char asanName[] = "asan_";
+    static const char tsanName[] = "tsan_";
     uint32_t imageCount = _dyld_image_count();
     for (uint32_t i = 0; i < imageCount; ++i) {
         const char* imageName = _dyld_get_image_name(i);
         if (!imageName)
             continue;
-        if (strstr(imageName, "/libclang_rt.asan_"))
-            return true;
+        if (const char* s = strstr(imageName, sanitizerPrefix)) {
+            const char* sanitizerName = s + sizeof(sanitizerPrefix) - 1;
+            if (!strncmp(sanitizerName, asanName, sizeof(asanName) - 1))
+                return true;
+            if (!strncmp(sanitizerName, tsanName, sizeof(tsanName) - 1))
+                return true;
+        }
     }
     return false;
 #elif BOS(UNIX)
     void* handle = dlopen(nullptr, RTLD_NOW);
     if (!handle)
         return false;
-    bool result = !!dlsym(handle, "__asan_poison_memory_region");
+    bool result = !!dlsym(handle, "__asan_init") || !!dlsym(handle, "__tsan_init");
     dlclose(handle);
     return result;
 #else
@@ -110,7 +118,7 @@ bool Environment::computeIsBmallocEnabled()
         return false;
     if (isLibgmallocEnabled())
         return false;
-    if (isASanEnabled())
+    if (isSanitizerEnabled())
         return false;
     return true;
 }