This is an archive of the discontinued LLVM Phabricator instance.

[LeakSanitizer] Capture calling thread SP early to avoid false negatives.
ClosedPublic

Authored by wiktorg on Jul 21 2022, 2:55 AM.

Details

Summary

As shown in https://github.com/llvm/llvm-project/issues/42932 dead pointers might be overlapped by a new stack frame inside CheckForLeaks, which does not use bytes with pointers.
This leads to false negatives.

It's not a full solution for the problem as it does not solve "overlapping" new/old frames for frames below the CheckForLeaks and in other threads.
It should improve leaks found in direct callers of __lsan_do_leak_check.

Diff Detail

Event Timeline

wiktorg created this revision.Jul 21 2022, 2:55 AM
wiktorg created this object with visibility "All Users".
Herald added a project: Restricted Project. · View Herald TranscriptJul 21 2022, 2:55 AM
Herald added a subscriber: Enna1. · View Herald Transcript
wiktorg requested review of this revision.Jul 21 2022, 2:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 21 2022, 2:55 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
wiktorg changed the visibility from "All Users" to "Public (No Login Required)".Jul 21 2022, 5:04 AM

LGTM
Would you be able to create a test from reproducer?

compiler-rt/lib/lsan/lsan_common.cpp
744

why do we need noinline? I guess to avoid "i" to move too far
With __builtin_frame_address it should not be needed.

799

__builtin_frame_address

wiktorg updated this revision to Diff 455288.Aug 24 2022, 10:57 AM
wiktorg marked 2 inline comments as done.
vitalybuka accepted this revision.Oct 12 2022, 4:46 PM
This revision is now accepted and ready to land.Oct 12 2022, 4:46 PM
haowei added a subscriber: haowei.Oct 12 2022, 5:19 PM

We are seeing build failures after this change landed:

[1184/1522] Building CXX object compiler-rt/lib/lsan/CMakeFiles/RTLSanCommon.x86_64.dir/lsan_common.cpp.obj
FAILED: compiler-rt/lib/lsan/CMakeFiles/RTLSanCommon.x86_64.dir/lsan_common.cpp.obj 
/b/s/w/ir/cache/goma/client/gomacc /b/s/w/ir/x/w/staging/llvm_build/./bin/clang++ --target=x86_64-unknown-fuchsia --sysroot=/b/s/w/ir/x/w/cipd/sdk/arch/x64/sysroot -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/lsan/.. --target=x86_64-unknown-fuchsia -I/b/s/w/ir/x/w/cipd/sdk/pkg/sync/include -I/b/s/w/ir/x/w/cipd/sdk/pkg/fdio/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -ffunction-sections -fdata-sections -ffile-prefix-map=/b/s/w/ir/x/w/staging/llvm_build/runtimes/runtimes-x86_64-unknown-fuchsia-bins=../staging/llvm_build/runtimes/runtimes-x86_64-unknown-fuchsia-bins -ffile-prefix-map=/b/s/w/ir/x/w/llvm-llvm-project/= -no-canonical-prefixes -Wall -Wno-unused-parameter -O2 -g -DNDEBUG -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -nostdinc++ -fno-rtti -Wno-format -std=c++17 -MD -MT compiler-rt/lib/lsan/CMakeFiles/RTLSanCommon.x86_64.dir/lsan_common.cpp.obj -MF compiler-rt/lib/lsan/CMakeFiles/RTLSanCommon.x86_64.dir/lsan_common.cpp.obj.d -o compiler-rt/lib/lsan/CMakeFiles/RTLSanCommon.x86_64.dir/lsan_common.cpp.obj -c /b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/lsan/lsan_common.cpp
/b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/lsan/lsan_common.cpp:615:3: error: no matching function for call to 'ProcessThreads'
  ProcessThreads(suspended_threads, frontier, caller_tid, caller_sp);
  ^~~~~~~~~~~~~~
/b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/lsan/lsan_common.cpp:361:13: note: candidate function not viable: requires 2 arguments, but 4 were provided
static void ProcessThreads(SuspendedThreadsList const &, Frontier *) {}
            ^
1 error generated.

Looks like you forgot to change the declaration at L361. Could you revert your change if it takes a while to fix please?