This is an archive of the discontinued LLVM Phabricator instance.

[lsan] Invoke hooks on realloc
ClosedPublic

Authored by Northbadge on May 22 2023, 5:56 PM.

Details

Summary

Previously lsan would not invoke hooks on reallocations.
An accompanying regression test is included in sanitizer_common.

This change also moves hook calls to a location where subsequent
calls (via an external caller) to __sanitizer_get_allocated_size
via hooks will return a valid size.

This allows a faster version of __sanitizer_get_allocated_size
to be implemented, which can skip checks.

Test to ensure RunFreeHooks' call order will come with
__sanitizer_get_allocated_size_fast

Diff Detail

Event Timeline

Northbadge created this revision.May 22 2023, 5:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 22 2023, 5:56 PM
Herald added a subscriber: Enna1. · View Herald Transcript
Northbadge published this revision for review.May 22 2023, 6:05 PM
Northbadge added a reviewer: vitalybuka.
Herald added a project: Restricted Project. · View Herald TranscriptMay 22 2023, 6:06 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
vitalybuka accepted this revision.May 22 2023, 6:09 PM
This revision is now accepted and ready to land.May 22 2023, 6:09 PM
Northbadge added inline comments.May 22 2023, 6:09 PM
compiler-rt/test/sanitizer_common/TestCases/malloc_hook.cpp
45

this is to avoid asan complaining of non-matching alloc-dealloc calls. e.g. it was doing new-free(from realloc) before.

This revision was automatically updated to reflect the committed changes.
This revision is now accepted and ready to land.May 31 2023, 4:19 PM

It looks like also failing in chromium mac bots. I haven't confirmed, but it's very likely.
Build: https://logs.chromium.org/logs/chromium/buildbucket/cr-buildbucket/8780155112582797025/+/u/package_clang/stdout?format=raw

FAIL: SanitizerCommon-tsan-x86_64-Darwin :: malloc_hook.cpp (67438 of 71222)
 ******************** TEST 'SanitizerCommon-tsan-x86_64-Darwin :: malloc_hook.cpp' FAILED ********************
 Script:
 --
 : 'RUN: at line 1';      /opt/s/w/ir/cache/builder/src/third_party/llvm-build/Release+Asserts/./bin/clang  --driver-mode=g++ -gline-tables-only -fsanitize=thread  -arch x86_64 -stdlib=libc++ -mmacosx-version-min=10.12 -isysroot /opt/s/w/ir/cache/osx_sdk/XCode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk  -I/opt/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/test -O2 /opt/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/test/sanitizer_common/TestCases/malloc_hook.cpp -o /opt/s/w/ir/cache/builder/src/third_party/llvm-build/Release+Asserts/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/tsan-x86_64-Darwin/Output/malloc_hook.cpp.tmp &&  /opt/s/w/ir/cache/builder/src/third_party/llvm-build/Release+Asserts/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/tsan-x86_64-Darwin/Output/malloc_hook.cpp.tmp 2>&1 | FileCheck /opt/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/test/sanitizer_common/TestCases/malloc_hook.cpp
 --
 Exit Code: 2
 
 Command Output (stderr):
 --
 FileCheck error: '<stdin>' is empty.
 FileCheck command line:  FileCheck /opt/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/test/sanitizer_common/TestCases/malloc_hook.cpp
 
 --
Northbadge closed this revision.Jun 1 2023, 11:15 AM

Test failures on darwin should be resolved past https://github.com/llvm/llvm-project/commit/2de54b919ba5fd9ccf37038cddfc36e97eb480af , sorry for the trouble!