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,24 @@ 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. Note that this won't cover +# all possible uninitialized stack contents, such as those used for register +# spill slots, unused portions for alignment, or even local variables not +# yet in scope at a certain point in the function. +if(LSAN_AUTO_VAR_INIT_PATTERN) + list(APPEND LSAN_CFLAGS -ftrivial-auto-var-init=pattern) +elseif(LSAN_AUTO_VAR_INIT_ZERO) + # Note this may hide some bugs in the lsan runtime itself that would involve + # reading uninitialized memory. + list(APPEND LSAN_CFLAGS -ftrivial-auto-var-init=zero) +endif() + # Too many existing bugs, needs cleanup. append_list_if(COMPILER_RT_HAS_WNO_FORMAT -Wno-format LSAN_CFLAGS)