void __lsan_enable();
// The heap object into which p points will be treated as a non-leak.
void __lsan_ignore_object(const void *p);
+ // The user may optionally provide this function to disallow leak checking
+ // for the program it is linked into. Note: this function may be called late,
+ // after all the global destructors.
+ int __lsan_is_turned_off();
#ifdef __cplusplus
} // extern "C"
--- /dev/null
+// Test for disabling LSan at link-time.
+// RUN: %clangxx_lsan %s -o %t
+// RUN: %t
+// RUN: %t foo 2>&1 | FileCheck %s
+
+#include <sanitizer/lsan_interface.h>
+
+int argc_copy;
+
+extern "C" {
+int __lsan_is_turned_off() {
+ return (argc_copy == 1);
+}
+}
+
+int main(int argc, char *argv[]) {
+ volatile int *x = new int;
+ *x = 42;
+ argc_copy = argc;
+ return 0;
+}
+
+// CHECK: SUMMARY: LeakSanitizer: 4 byte(s) leaked in 1 allocation(s)
static bool already_done;
CHECK(!already_done);
already_done = true;
+ if (&__lsan_is_turned_off && __lsan_is_turned_off())
+ return;
DoLeakCheckParam param;
param.success = false;
__lsan::disable_counter--;
#endif
}
+
+#if !SANITIZER_SUPPORTS_WEAK_HOOKS
+SANITIZER_WEAK_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE
+int __lsan_is_turned_off() {
+ return 0;
+}
+#endif
} // extern "C"
} // namespace __lsan
+extern "C" {
+int __lsan_is_turned_off() SANITIZER_WEAK_ATTRIBUTE
+ SANITIZER_INTERFACE_ATTRIBUTE;
+} // extern "C"
+
#endif // LSAN_COMMON_H