[lsan] LSan in LD_PRELOAD library form.

git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@182376 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/lsan/tests/lsan_testlib.cc b/lib/lsan/tests/lsan_testlib.cc
new file mode 100644
index 0000000..142f187
--- /dev/null
+++ b/lib/lsan/tests/lsan_testlib.cc
@@ -0,0 +1,31 @@
+//===-- lsan_testlib.cc ---------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is a part of LeakSanitizer.
+// Standalone LSan tool as a shared library, to be used with LD_PRELOAD.
+//
+//===----------------------------------------------------------------------===//
+/* Usage:
+clang++ ../sanitizer_common/sanitizer_*.cc ../interception/interception_*.cc \
+ lsan*.cc tests/lsan_testlib.cc -I. -I.. -g -ldl -lpthread -fPIC -shared -O2 \
+ -o lsan.so
+LD_PRELOAD=./lsan.so /your/app
+*/
+#include "lsan_common.h"
+#include "lsan.h"
+
+__attribute__((constructor))
+void constructor() {
+  __lsan::Init();
+}
+
+__attribute__((destructor))
+void destructor() {
+  __lsan::DoLeakCheck();
+}