[compiler-rt] a63932a - [lsan] Allow suppression of "unknown module"

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 15 13:36:34 PDT 2022


Author: Vitaly Buka
Date: 2022-03-15T13:35:21-07:00
New Revision: a63932a8152d23acf2905a1956b95b290d6703ad

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

LOG: [lsan] Allow suppression of "unknown module"

If sanitizer cannot determine name of the module it
will use "<unknown module>". Then it can be suppressed
if needed.

Reviewed By: kda

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

Added: 
    compiler-rt/test/lsan/TestCases/Linux/dso-unknown.cpp

Modified: 
    compiler-rt/lib/lsan/lsan_common.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/lsan/lsan_common.cpp b/compiler-rt/lib/lsan/lsan_common.cpp
index fd7aa38d99db6..8d1bf11fdab62 100644
--- a/compiler-rt/lib/lsan/lsan_common.cpp
+++ b/compiler-rt/lib/lsan/lsan_common.cpp
@@ -135,10 +135,11 @@ Suppression *LeakSuppressionContext::GetSuppressionForAddr(uptr addr) {
   Suppression *s = nullptr;
 
   // Suppress by module name.
-  if (const char *module_name =
-          Symbolizer::GetOrInit()->GetModuleNameForPc(addr))
-    if (context.Match(module_name, kSuppressionLeak, &s))
-      return s;
+  const char *module_name = Symbolizer::GetOrInit()->GetModuleNameForPc(addr);
+  if (!module_name)
+    module_name = "<unknown module>";
+  if (context.Match(module_name, kSuppressionLeak, &s))
+    return s;
 
   // Suppress by file or function name.
   SymbolizedStack *frames = Symbolizer::GetOrInit()->SymbolizePC(addr);

diff  --git a/compiler-rt/test/lsan/TestCases/Linux/dso-unknown.cpp b/compiler-rt/test/lsan/TestCases/Linux/dso-unknown.cpp
new file mode 100644
index 0000000000000..2294ab81fdf96
--- /dev/null
+++ b/compiler-rt/test/lsan/TestCases/Linux/dso-unknown.cpp
@@ -0,0 +1,50 @@
+// Build a library with origin tracking and an executable w/o origin tracking.
+// Test that origin tracking is enabled at runtime.
+// RUN: %clangxx_lsan -O0 %s -DBUILD_SO -fPIC -shared -o %t-so.so
+// RUN: %clangxx_lsan -O0 %s -ldl -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_lsan -O0 %s -ldl -o %t -DSUPPRESS_LEAK && %run %t 2>&1
+
+#ifdef BUILD_SO
+
+#  include <stdlib.h>
+
+extern "C" {
+void *my_alloc(unsigned sz) { return malloc(sz); }
+} // extern "C"
+
+#else // BUILD_SO
+
+#  include <assert.h>
+#  include <dlfcn.h>
+#  include <stdlib.h>
+#  include <string>
+
+#  ifdef SUPPRESS_LEAK
+extern "C" const char *__lsan_default_suppressions() {
+  return "leak:^<unknown module>$";
+}
+#  endif
+
+void *p;
+int main(int argc, char **argv) {
+
+  std::string path = std::string(argv[0]) + "-so.so";
+
+  dlerror();
+
+  void *handle = dlopen(path.c_str(), RTLD_LAZY);
+  assert(handle != 0);
+  typedef void *(*fn)(unsigned sz);
+  fn my_alloc = (fn)dlsym(handle, "my_alloc");
+
+  p = my_alloc(1);
+  p = my_alloc(2);
+  p = my_alloc(3);
+
+  dlclose(handle);
+  return 0;
+}
+
+#endif // BUILD_SO
+
+// CHECK: Direct leak


        


More information about the llvm-commits mailing list