[PATCH] [compiler-rt] Fix ASan's Noinst unit tests

Kuba Brecka kuba.brecka at gmail.com
Sun Feb 8 13:28:59 PST 2015


I noticed that on OS X, we currently skip all "Noinst" unit tests, see http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA_check/1384/consoleFull and search for "Asan-i386-inline-Noinst-Test" (they're not being run at all).  The reason is that in MaybeReexec() we always try to set DYLD_INSERT_LIBRARIES to the module where we find the `__asan_init` symbol.  However, the non-instrumented unit tests link the runtime statically, so this symbol is in the executable itself.

This was probably caused when we removed the "allow_reexec" flag.  This patch adds a check into MaybeReexec such that if the module that contains the `__asan_init` symbol is not a dylib, we will not try to re-execute at all.  This should only affect the statically-linked unit tests, all other uses on OS X should use the dynamic library.

http://reviews.llvm.org/D7493

Files:
  lib/asan/asan_mac.cc

Index: lib/asan/asan_mac.cc
===================================================================
--- lib/asan/asan_mac.cc
+++ lib/asan/asan_mac.cc
@@ -67,6 +67,7 @@
 void __asan_init();
 
 static const char kDyldInsertLibraries[] = "DYLD_INSERT_LIBRARIES";
+static const char kDylibSuffix[] = ".dylib";
 LowLevelAllocator allocator_for_env;
 
 // Change the value of the env var |name|, leaking the original value.
@@ -114,6 +115,15 @@
   uptr fname_len = internal_strlen(info.dli_fname);
   const char *dylib_name = StripModuleName(info.dli_fname);
   uptr dylib_name_len = internal_strlen(dylib_name);
+
+  // "Noinst" unit tests link the runtime statically. We can't re-exec there,
+  // because we have no dylib to insert. Wrappers don't work there (that's
+  // expected).
+  uptr suffix_len = internal_strlen(kDylibSuffix);
+  if (dylib_name_len < suffix_len ||
+      internal_strcmp(dylib_name + dylib_name_len - suffix_len, kDylibSuffix))
+    return;
+
   if (!dyld_insert_libraries ||
       !REAL(strstr)(dyld_insert_libraries, dylib_name)) {
     // DYLD_INSERT_LIBRARIES is not set or does not contain the runtime

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7493.19554.patch
Type: text/x-patch
Size: 1127 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150208/d032e351/attachment.bin>


More information about the llvm-commits mailing list