Skip to content

Commit

Permalink
Workaround: Avoid failing to calloc while half-way through AsanInitIn…
Browse files Browse the repository at this point in the history
…ternal.

- Get atexit table initialized before we intall interception.
- Do InitializeSuppressions a little earlier


(With LLVM-19.1.6-win32.exe)
ASAN_OPTIONS=verbosity=2 wine "C:\\Program Files\\LLVM\\bin\\llvm-symbolizer.exe"

AddressSanitizer: CHECK failed: asan_suppressions.cpp:46 "((suppression_ctx)) != (0)" (0x0, 0x0) (tid=324)
AddressSanitizer: CHECK failed: asan_suppressions.cpp:46 "((suppression_ctx)) != (0)" (0x0, 0x0) (tid=324)

(rr) bt
#0  __sanitizer::CheckFailed (file=0x7a892243 <.refptr.___asan_shadow_memory_dynamic_address+491> "/home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/asan/asan_suppressions.cpp", line=46, cond=0x7a8922e4 <.refptr.___asan_shadow_memory_dynamic_address+652> "((suppression_ctx)) != (0)", v1=0, v2=0) at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_termination.cpp:83
llvm#1  0x7a8772bc in __asan::IsInterceptorSuppressed (interceptor_name=0x7a890364 <.refptr.___asan_option_detect_stack_use_after_return+9824> "memset") at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/asan/asan_suppressions.cpp:46
llvm#2  0x7a86c071 in __asan_wrap_memset (dst=0x302ba000, v=254, size=8192) at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc:87
llvm#3  0x7a86e563 in __asan::FastPoisonShadow (aligned_beg=<optimized out>, aligned_size=<optimized out>, value=<optimized out>) at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/asan/asan_poisoning.h:55
llvm#4  __asan::PoisonShadow (addr=22872064, size=65536, value=254 '\376') at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/asan/asan_poisoning.cpp:43
llvm#5  0x7a875c43 in __asan::OnLowLevelAllocate (ptr=22872064, size=65536) at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/asan/asan_rtl.cpp:106
llvm#6  0x7a832835 in __sanitizer::LowLevelAllocator::Allocate (this=0x7b14d138, size=16400) at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cpp:159
llvm#7  0x7a84d3ba in operator new (size=16396, alloc=...) at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_common.h:1112
llvm#8  __sanitizer::ChooseSymbolizerTools (list=<optimized out>, allocator=<optimized out>) at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_win.cpp:299
llvm#9  __sanitizer::Symbolizer::PlatformInit () at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_win.cpp:312
llvm#10 0x7a849834 in __sanitizer::Symbolizer::GetOrInit () at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cpp:24
llvm#11 0x7a848378 in __sanitizer::(anonymous namespace)::StackTraceTextPrinter::ProcessAddressFrames (this=this@entry=0x121ead4, pc=2055691253) at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cpp:37
llvm#12 0x7a8482c1 in __sanitizer::StackTrace::PrintTo (this=this@entry=0x121eb30, output=0x121eb14) at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cpp:110
llvm#13 0x7a8485e1 in __sanitizer::StackTrace::Print (this=0x121eb30) at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cpp:133
llvm#14 0x7a875c21 in __asan::CheckUnwind () at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/asan/asan_rtl.cpp:70
llvm#15 0x7a843f03 in __sanitizer::CheckFailed (file=0x7a892243 <.refptr.___asan_shadow_memory_dynamic_address+491> "/home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/asan/asan_suppressions.cpp", line=46, cond=0x7a8922e4 <.refptr.___asan_shadow_memory_dynamic_address+652> "((suppression_ctx)) != (0)", v1=0, v2=0) at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_termination.cpp:86
llvm#16 0x7a8772bc in __asan::IsInterceptorSuppressed (interceptor_name=0x7a890364 <.refptr.___asan_option_detect_stack_use_after_return+9824> "memset") at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/asan/asan_suppressions.cpp:46
llvm#17 0x7a86c071 in __asan_wrap_memset (dst=0x30300000, v=250, size=131072) at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc:87
llvm#18 0x7a86e563 in __asan::FastPoisonShadow (aligned_beg=<optimized out>, aligned_size=<optimized out>, value=<optimized out>) at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/asan/asan_poisoning.h:55
llvm#19 __asan::PoisonShadow (addr=25165824, size=1048576, value=250 '\372') at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/asan/asan_poisoning.cpp:43
llvm#20 0x7a856c54 in __asan::AsanMapUnmapCallback::OnMap (p=25165824, size=1048576, this=<optimized out>) at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/asan/asan_allocator.cpp:283
llvm#21 __sanitizer::SizeClassAllocator32<__asan::AP32<__sanitizer::LocalAddressSpaceView> >::AllocateRegion (stat=0x7b1777e4, this=<optimized out>, class_id=<optimized out>) at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/asan/../sanitizer_common/sanitizer_allocator_primary32.h:304
llvm#22 __sanitizer::SizeClassAllocator32<__asan::AP32<__sanitizer::LocalAddressSpaceView> >::PopulateFreeList (this=0x7b14ec40, stat=0x7b1777e4, c=0x7b170be4, sci=0x7b14ff40, class_id=12) at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/asan/../sanitizer_common/sanitizer_allocator_primary32.h:343
llvm#23 0x7a856b97 in __sanitizer::SizeClassAllocator32<__asan::AP32<__sanitizer::LocalAddressSpaceView> >::AllocateBatch (this=<optimized out>, stat=0x7b1777e4, c=0x7b170be4, class_id=12) at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/asan/../sanitizer_common/sanitizer_allocator_primary32.h:174
llvm#24 0x7a856a2b in __sanitizer::SizeClassAllocator32LocalCache<__sanitizer::SizeClassAllocator32<__asan::AP32<__sanitizer::LocalAddressSpaceView> > >::Refill (this=this@entry=0x7b170be4, c=0x7b1723e4, allocator=0x7b14ec40, class_id=12) at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/asan/../sanitizer_common/sanitizer_allocator_local_cache.h:244
llvm#25 0x7a8575f5 in __sanitizer::SizeClassAllocator32LocalCache<__sanitizer::SizeClassAllocator32<__asan::AP32<__sanitizer::LocalAddressSpaceView> > >::Allocate (this=0x7b170be4, allocator=0x7b14ec40, class_id=131072) at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/asan/../sanitizer_common/sanitizer_allocator_local_cache.h:164
llvm#26 __sanitizer::CombinedAllocator<__sanitizer::SizeClassAllocator32<__asan::AP32<__sanitizer::LocalAddressSpaceView> >, __sanitizer::LargeMmapAllocatorPtrArrayStatic>::Allocate (this=this@entry=0x7b14ec40, cache=0x7b170be4, size=<optimized out>, alignment=8) at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/asan/../sanitizer_common/sanitizer_allocator_combined.h:69
llvm#27 0x7a85545b in __asan::Allocator::Allocate (this=<optimized out>, size=<optimized out>, alignment=8, stack=0x121f5c0, alloc_type=__asan::FROM_MALLOC, can_fill=<optimized out>) at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/asan/asan_allocator.cpp:586
llvm#28 0x7a853aee in __asan::Allocator::Calloc (nmemb=32, size=4, stack=0x121f5c0, this=<optimized out>) at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/asan/asan_allocator.cpp:787
llvm#29 __asan::asan_calloc (nmemb=32, size=4, stack=0x121f5c0) at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/asan/asan_allocator.cpp:1012
llvm#30 0x7a86cd43 in calloc (nmemb=32, size=4) at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/asan/asan_malloc_win.cpp:92
llvm#31 0x7b493543 in register_onexit_function (table=table@entry=0x7a89b160 <atexit_table>, func=func@entry=0x7a844430 <__sanitizer_cov_dump()>) at /home/bernhard/data/entwicklung/2024/wine/wine/dlls/msvcrt/exit.c:80
llvm#32 0x7b493a54 in _register_onexit_function (table=0x7a89b160 <atexit_table>, func=0x7a844430 <__sanitizer_cov_dump()>) at /home/bernhard/data/entwicklung/2024/wine/wine/dlls/msvcrt/exit.c:443
llvm#33 0x7a83139e in atexit (func=<optimized out>) at ../crt/crtdll.c:209
llvm#34 0x7a841f6d in __sanitizer::Atexit (function=0x7a844430 <__sanitizer_cov_dump()>) at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_win.cpp:752
llvm#35 0x7a84440f in __sanitizer::InitializeCoverage (enabled=64, dir=0x7a87f9f6 <.refptr.__ZN11__sanitizer24stoptheworld_tracer_ppidE+42> ".") at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep_new.cpp:214
llvm#36 0x7a844430 in __sanitizer::InitializeCoverage(bool, char const*) () at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep_new.cpp:216
llvm#37 0x0121fa7c in ?? ()
llvm#38 0x7a8757ab in __asan::AsanInitInternal () at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/asan/asan_rtl.cpp:474
llvm#39 0x7a875fa0 in __asan::AsanInitFromRtl () at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/asan/asan_rtl.cpp:522
llvm#40 __asan::AsanInitializer::AsanInitializer (this=<optimized out>) at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/asan/asan_rtl.cpp:542
llvm#41 __cxx_global_var_init () at /home/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/lib/asan/asan_rtl.cpp:546
llvm#42 0x7a875fa0 in _GLOBAL__sub_I_asan_rtl.cpp () from /media/bernhard/data/entwicklung/2025/llvm-mingw/2025-01-04/llvm-mingw/llvm-project/compiler-rt/build-i686-sanitizers/lib/windows/libclang_rt.asan_dynamic-i386.dll
llvm#43 0x0121fd24 in ?? ()
llvm#44 0x7a87cb9b in __do_global_ctors () at ../crt/gccmain.c:44
llvm#45 __main () at ../crt/gccmain.c:58
llvm#46 0x7a831222 in __DllMainCRTStartup (hDllHandle=0x7a830000, dwReason=1, lpreserved=<optimized out>) at ../crt/crtdll.c:185
llvm#47 0x7a8311af in _DllMainCRTStartup@12 (hDllHandle=<optimized out>, dwReason=<optimized out>, lpreserved=<optimized out>) at ../crt/crtdll.c:156
llvm#48 0x7bdf63d6 in call_dll_entry_point () from /mnt/sdb1/wineprefix_asan_2025-01-01_win32/drive_c/windows/system32/ntdll.dll
llvm#49 0x7bdf96e0 in MODULE_InitDLL (wm=<optimized out>, wm@entry=0x243bd0, reason=reason@entry=1, lpReserved=0x121fd24) at /home/bernhard/data/entwicklung/2024/wine/wine/dlls/ntdll/loader.c:1668
llvm#50 0x7bdf7b42 in process_attach (node=<optimized out>, lpReserved=lpReserved@entry=0x121fd24) at /home/bernhard/data/entwicklung/2024/wine/wine/dlls/ntdll/loader.c:1762
llvm#51 0x7bdfa4d8 in loader_init (context=0x121fd24, entry=0x121fdd4) at /home/bernhard/data/entwicklung/2024/wine/wine/dlls/ntdll/loader.c:4456
llvm#52 0x7be18b2c in _LdrInitializeThunk@16 (context=0x121fd24, unk2=0, unk3=0, unk4=0) at /home/bernhard/data/entwicklung/2024/wine/wine/dlls/ntdll/signal_i386.c:559
llvm#53 0xdeadbabe in ?? ()
  • Loading branch information
bernhardu committed Jan 22, 2025
1 parent 55cee2a commit 45b84b8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions compiler-rt/lib/asan/asan_rtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,20 @@ void PrintAddressSpaceLayout() {
kHighShadowBeg > kMidMemEnd);
}

SANITIZER_INTERFACE_ATTRIBUTE void __sanitizer_dummy_atexit() {
}

static bool AsanInitInternal() {
if (LIKELY(AsanInited()))
return true;
SanitizerToolName = "AddressSanitizer";

CacheBinaryName();

// Get the atexit table initialized before the interception gets installed.
// Workaround failure in calloc in InitializeCoverage before InitializeSuppressions.
Atexit(__sanitizer_dummy_atexit);

// Initialize flags. This must be done early, because most of the
// initialization steps look at flags().
InitializeFlags();
Expand Down Expand Up @@ -478,6 +485,8 @@ static bool AsanInitInternal() {
if (flags()->start_deactivated)
AsanDeactivate();

InitializeSuppressions();

// Create main thread.
AsanThread *main_thread = CreateMainThread();
CHECK_EQ(0, main_thread->tid());
Expand All @@ -495,8 +504,6 @@ static bool AsanInitInternal() {
__ubsan::InitAsPlugin();
#endif

InitializeSuppressions();

if (CAN_SANITIZE_LEAKS) {
// LateInitialize() calls dlsym, which can allocate an error string buffer
// in the TLS. Let's ignore the allocation to avoid reporting a leak.
Expand Down

0 comments on commit 45b84b8

Please sign in to comment.