diff --git a/compiler-rt/include/sanitizer/lsan_interface.h b/compiler-rt/include/sanitizer/lsan_interface.h index 8fb8e756da26..1f2e58909b4d 100644 --- a/compiler-rt/include/sanitizer/lsan_interface.h +++ b/compiler-rt/include/sanitizer/lsan_interface.h @@ -64,6 +64,8 @@ extern "C" { // for the program it is linked into (if the return value is non-zero). This // function must be defined as returning a constant value; any behavior beyond // that is unsupported. + // To avoid dead stripping, you may need to define this function with + // __attribute__((used)) int __lsan_is_turned_off(); // This function may be optionally provided by the user and should return diff --git a/compiler-rt/test/lsan/TestCases/link_turned_off.cc b/compiler-rt/test/lsan/TestCases/link_turned_off.cc index fd11272ceae3..245fd017b6ec 100644 --- a/compiler-rt/test/lsan/TestCases/link_turned_off.cc +++ b/compiler-rt/test/lsan/TestCases/link_turned_off.cc @@ -3,15 +3,13 @@ // RUN: %clangxx_lsan %s -o %t // RUN: %env_lsan_opts=$LSAN_BASE %run %t // RUN: %env_lsan_opts=$LSAN_BASE not %run %t foo 2>&1 | FileCheck %s -// -// UNSUPPORTED: darwin #include int argc_copy; extern "C" { -int __lsan_is_turned_off() { +int __attribute__((used)) __lsan_is_turned_off() { return (argc_copy == 1); } }