diff options
author | Vyacheslav Cherkashin <v.cherkashin@samsung.com> | 2018-10-31 17:52:22 +0300 |
---|---|---|
committer | Slava Barinov <v.barinov@samsung.com> | 2024-05-13 14:38:30 +0300 |
commit | dd328e67aeb59520a3f69b943a055422e85c4910 (patch) | |
tree | 62d8b621ae55bdd9c243357d1161e88437524453 | |
parent | dd1b2c66cd4f9e795ba58a3e875b58110407d490 (diff) | |
download | gcc-dd328e67aeb59520a3f69b943a055422e85c4910.tar.gz gcc-dd328e67aeb59520a3f69b943a055422e85c4910.tar.bz2 gcc-dd328e67aeb59520a3f69b943a055422e85c4910.zip |
[LSan] Add dynamic loading support for LSan library
The LSan library has very big static TLS section
Problem:
- LSan library could not be loaded dynamically because it had a very
big static TLS section.
AllocatorCache: ~15KB for 32bit
~53KB for 64bit
Solution:
- Store in the TLS section only a pointer to the AllocatorCache and
dynamically allocate memory for it.
Change-Id: I6e90e6682e277c90825938f5732867b6564d62b4
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
-rw-r--r-- | libsanitizer/lsan/lsan_linux.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/libsanitizer/lsan/lsan_linux.cpp b/libsanitizer/lsan/lsan_linux.cpp index 5074cee1296..933bc35d190 100644 --- a/libsanitizer/lsan/lsan_linux.cpp +++ b/libsanitizer/lsan/lsan_linux.cpp @@ -14,6 +14,7 @@ #if SANITIZER_LINUX || SANITIZER_NETBSD || SANITIZER_FUCHSIA +# include "sanitizer_common/sanitizer_allocator_internal.h" # include "lsan_allocator.h" # include "lsan_thread.h" @@ -23,8 +24,15 @@ static THREADLOCAL ThreadContextLsanBase *current_thread = nullptr; ThreadContextLsanBase *GetCurrentThread() { return current_thread; } void SetCurrentThread(ThreadContextLsanBase *tctx) { current_thread = tctx; } -static THREADLOCAL AllocatorCache allocator_cache; -AllocatorCache *GetAllocatorCache() { return &allocator_cache; } +static THREADLOCAL AllocatorCache *allocator_cache; +AllocatorCache *GetAllocatorCache() { + if (UNLIKELY(allocator_cache == nullptr)) { + // We will not release the memory because the library is not unloaded. + allocator_cache = (AllocatorCache *)InternalAlloc(sizeof(*allocator_cache)); + *allocator_cache = AllocatorCache(); + } + return allocator_cache; +} void ReplaceSystemMalloc() {} |