diff --git a/compiler-rt/lib/lsan/CMakeLists.txt b/compiler-rt/lib/lsan/CMakeLists.txt --- a/compiler-rt/lib/lsan/CMakeLists.txt +++ b/compiler-rt/lib/lsan/CMakeLists.txt @@ -3,6 +3,21 @@ set(LSAN_CFLAGS ${SANITIZER_COMMON_CFLAGS}) append_rtti_flag(OFF LSAN_CFLAGS) +# When lsan scans the stack for detecting reachable pointers, it's possible for +# a leaked pointer, which was pushed to the stack on an earlier function call, +# to still exist on the stack when doing a leak check if that part of the stack +# was not overwritten. In particular, if there's any uninitialized data in the +# lsan runtime, and the SP we start from is sufficiently deep into the runtime, +# then a leaked pointer could be marked as reachable. Such instances could be +# mitigated by clobbering any uninitialized data. +# +# Keep as =zero to mitigate any performance costs as opposed to =pattern. +# +# Note that, in the general case, this may hide some bugs in lsan runtime +# itself that would involve reading uninitialized memory. +check_cxx_compiler_flag(-ftrivial-auto-var-init=zero COMPILER_RT_HAS_AUTO_VAR_INIT_ZERO) +append_list_if(COMPILER_RT_HAS_AUTO_VAR_INIT_ZERO -ftrivial-auto-var-init=zero LSAN_CFLAGS) + # Too many existing bugs, needs cleanup. append_list_if(COMPILER_RT_HAS_WNO_FORMAT -Wno-format LSAN_CFLAGS)