asan_rtl.cc revision 94c54f19d4330cbf2b6fd83b65841f706e34365e
1//===-- asan_rtl.cc -------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file is a part of AddressSanitizer, an address sanity checker. 11// 12// Main file of the ASan run-time library. 13//===----------------------------------------------------------------------===// 14#include "asan_allocator.h" 15#include "asan_interceptors.h" 16#include "asan_interface.h" 17#include "asan_internal.h" 18#include "asan_lock.h" 19#include "asan_mapping.h" 20#include "asan_stack.h" 21#include "asan_stats.h" 22#include "asan_thread.h" 23#include "asan_thread_registry.h" 24#include "sanitizer_common/sanitizer_libc.h" 25 26namespace __sanitizer { 27using namespace __asan; 28 29void Die() { 30 static int num_calls = 0; 31 if (AtomicInc(&num_calls) > 1) { 32 // Don't die twice - run a busy loop. 33 while (1) { } 34 } 35 if (FLAG_sleep_before_dying) { 36 Report("Sleeping for %zd second(s)\n", FLAG_sleep_before_dying); 37 SleepForSeconds(FLAG_sleep_before_dying); 38 } 39 if (FLAG_unmap_shadow_on_exit) 40 UnmapOrDie((void*)kLowShadowBeg, kHighShadowEnd - kLowShadowBeg); 41 if (death_callback) 42 death_callback(); 43 if (FLAG_abort_on_error) 44 Abort(); 45 Exit(FLAG_exitcode); 46} 47 48void CheckFailed(const char *file, int line, const char *cond, u64 v1, u64 v2) { 49 AsanReport("AddressSanitizer CHECK failed: %s:%d \"%s\" (%zx, %zx)\n", 50 file, line, cond, (uptr)v1, (uptr)v2); 51 PRINT_CURRENT_STACK(); 52 ShowStatsAndAbort(); 53} 54 55} // namespace __sanitizer 56 57namespace __asan { 58 59// -------------------------- Flags ------------------------- {{{1 60static const uptr kMallocContextSize = 30; 61 62uptr FLAG_malloc_context_size = kMallocContextSize; 63uptr FLAG_max_malloc_fill_size = 0; 64s64 FLAG_v = 0; 65uptr FLAG_redzone = (ASAN_LOW_MEMORY) ? 64 : 128; // power of two, >= 32 66uptr FLAG_quarantine_size = (ASAN_LOW_MEMORY) ? 1UL << 24 : 1UL << 28; 67static s64 FLAG_atexit = 0; 68bool FLAG_poison_shadow = 1; 69s64 FLAG_report_globals = 1; 70bool FLAG_handle_segv = ASAN_NEEDS_SEGV; 71bool FLAG_use_sigaltstack = 0; 72bool FLAG_symbolize = 0; 73s64 FLAG_demangle = 1; 74s64 FLAG_debug = 0; 75bool FLAG_replace_cfallocator = 1; // Used on Mac only. 76bool FLAG_mac_ignore_invalid_free = 0; // Used on Mac only. 77bool FLAG_replace_str = 1; 78bool FLAG_replace_intrin = 1; 79bool FLAG_use_fake_stack = 1; 80s64 FLAG_exitcode = ASAN_DEFAULT_FAILURE_EXITCODE; 81bool FLAG_allow_user_poisoning = 1; 82s64 FLAG_sleep_before_dying = 0; 83bool FLAG_abort_on_error = 0; 84bool FLAG_unmap_shadow_on_exit = 0; 85bool FLAG_disable_core = __WORDSIZE == 64; 86bool FLAG_check_malloc_usable_size = 1; 87 88// -------------------------- Globals --------------------- {{{1 89int asan_inited; 90bool asan_init_is_running; 91void (*death_callback)(void); 92static void (*error_report_callback)(const char*); 93char *error_message_buffer = 0; 94uptr error_message_buffer_pos = 0; 95uptr error_message_buffer_size = 0; 96 97// -------------------------- Misc ---------------- {{{1 98void ShowStatsAndAbort() { 99 __asan_print_accumulated_stats(); 100 Die(); 101} 102 103static void PrintBytes(const char *before, uptr *a) { 104 u8 *bytes = (u8*)a; 105 uptr byte_num = (__WORDSIZE) / 8; 106 AsanPrintf("%s%p:", before, (void*)a); 107 for (uptr i = 0; i < byte_num; i++) { 108 AsanPrintf(" %x%x", bytes[i] >> 4, bytes[i] & 15); 109 } 110 AsanPrintf("\n"); 111} 112 113void AppendToErrorMessageBuffer(const char *buffer) { 114 if (error_message_buffer) { 115 uptr length = internal_strlen(buffer); 116 CHECK_GE(error_message_buffer_size, error_message_buffer_pos); 117 uptr remaining = error_message_buffer_size - error_message_buffer_pos; 118 internal_strncpy(error_message_buffer + error_message_buffer_pos, 119 buffer, remaining); 120 error_message_buffer[error_message_buffer_size - 1] = '\0'; 121 // FIXME: reallocate the buffer instead of truncating the message. 122 error_message_buffer_pos += remaining > length ? length : remaining; 123 } 124} 125 126// ---------------------- mmap -------------------- {{{1 127// Reserve memory range [beg, end]. 128static void ReserveShadowMemoryRange(uptr beg, uptr end) { 129 CHECK((beg % kPageSize) == 0); 130 CHECK(((end + 1) % kPageSize) == 0); 131 uptr size = end - beg + 1; 132 void *res = MmapFixedNoReserve(beg, size); 133 CHECK(res == (void*)beg && "ReserveShadowMemoryRange failed"); 134} 135 136// ---------------------- LowLevelAllocator ------------- {{{1 137void *LowLevelAllocator::Allocate(uptr size) { 138 CHECK((size & (size - 1)) == 0 && "size must be a power of two"); 139 if (allocated_end_ - allocated_current_ < (sptr)size) { 140 uptr size_to_allocate = Max(size, kPageSize); 141 allocated_current_ = 142 (char*)MmapOrDie(size_to_allocate, __FUNCTION__); 143 allocated_end_ = allocated_current_ + size_to_allocate; 144 PoisonShadow((uptr)allocated_current_, size_to_allocate, 145 kAsanInternalHeapMagic); 146 } 147 CHECK(allocated_end_ - allocated_current_ >= (sptr)size); 148 void *res = allocated_current_; 149 allocated_current_ += size; 150 return res; 151} 152 153// ---------------------- DescribeAddress -------------------- {{{1 154static bool DescribeStackAddress(uptr addr, uptr access_size) { 155 AsanThread *t = asanThreadRegistry().FindThreadByStackAddress(addr); 156 if (!t) return false; 157 const sptr kBufSize = 4095; 158 char buf[kBufSize]; 159 uptr offset = 0; 160 const char *frame_descr = t->GetFrameNameByAddr(addr, &offset); 161 // This string is created by the compiler and has the following form: 162 // "FunctioName n alloc_1 alloc_2 ... alloc_n" 163 // where alloc_i looks like "offset size len ObjectName ". 164 CHECK(frame_descr); 165 // Report the function name and the offset. 166 const char *name_end = internal_strchr(frame_descr, ' '); 167 CHECK(name_end); 168 buf[0] = 0; 169 internal_strncat(buf, frame_descr, 170 Min(kBufSize, 171 static_cast<sptr>(name_end - frame_descr))); 172 AsanPrintf("Address %p is located at offset %zu " 173 "in frame <%s> of T%d's stack:\n", 174 (void*)addr, offset, buf, t->tid()); 175 // Report the number of stack objects. 176 char *p; 177 uptr n_objects = internal_simple_strtoll(name_end, &p, 10); 178 CHECK(n_objects > 0); 179 AsanPrintf(" This frame has %zu object(s):\n", n_objects); 180 // Report all objects in this frame. 181 for (uptr i = 0; i < n_objects; i++) { 182 uptr beg, size; 183 sptr len; 184 beg = internal_simple_strtoll(p, &p, 10); 185 size = internal_simple_strtoll(p, &p, 10); 186 len = internal_simple_strtoll(p, &p, 10); 187 if (beg <= 0 || size <= 0 || len < 0 || *p != ' ') { 188 AsanPrintf("AddressSanitizer can't parse the stack frame " 189 "descriptor: |%s|\n", frame_descr); 190 break; 191 } 192 p++; 193 buf[0] = 0; 194 internal_strncat(buf, p, Min(kBufSize, len)); 195 p += len; 196 AsanPrintf(" [%zu, %zu) '%s'\n", beg, beg + size, buf); 197 } 198 AsanPrintf("HINT: this may be a false positive if your program uses " 199 "some custom stack unwind mechanism\n" 200 " (longjmp and C++ exceptions *are* supported)\n"); 201 t->summary()->Announce(); 202 return true; 203} 204 205static NOINLINE void DescribeAddress(uptr addr, uptr access_size) { 206 // Check if this is a global. 207 if (DescribeAddrIfGlobal(addr)) 208 return; 209 210 if (DescribeStackAddress(addr, access_size)) 211 return; 212 213 // finally, check if this is a heap. 214 DescribeHeapAddress(addr, access_size); 215} 216 217// -------------------------- Run-time entry ------------------- {{{1 218// exported functions 219#define ASAN_REPORT_ERROR(type, is_write, size) \ 220extern "C" NOINLINE INTERFACE_ATTRIBUTE \ 221void __asan_report_ ## type ## size(uptr addr); \ 222void __asan_report_ ## type ## size(uptr addr) { \ 223 GET_CALLER_PC_BP_SP; \ 224 __asan_report_error(pc, bp, sp, addr, is_write, size); \ 225} 226 227ASAN_REPORT_ERROR(load, false, 1) 228ASAN_REPORT_ERROR(load, false, 2) 229ASAN_REPORT_ERROR(load, false, 4) 230ASAN_REPORT_ERROR(load, false, 8) 231ASAN_REPORT_ERROR(load, false, 16) 232ASAN_REPORT_ERROR(store, true, 1) 233ASAN_REPORT_ERROR(store, true, 2) 234ASAN_REPORT_ERROR(store, true, 4) 235ASAN_REPORT_ERROR(store, true, 8) 236ASAN_REPORT_ERROR(store, true, 16) 237 238// Force the linker to keep the symbols for various ASan interface functions. 239// We want to keep those in the executable in order to let the instrumented 240// dynamic libraries access the symbol even if it is not used by the executable 241// itself. This should help if the build system is removing dead code at link 242// time. 243static NOINLINE void force_interface_symbols() { 244 volatile int fake_condition = 0; // prevent dead condition elimination. 245 if (fake_condition) { 246 __asan_report_load1(0); 247 __asan_report_load2(0); 248 __asan_report_load4(0); 249 __asan_report_load8(0); 250 __asan_report_load16(0); 251 __asan_report_store1(0); 252 __asan_report_store2(0); 253 __asan_report_store4(0); 254 __asan_report_store8(0); 255 __asan_report_store16(0); 256 __asan_register_global(0, 0, 0); 257 __asan_register_globals(0, 0); 258 __asan_unregister_globals(0, 0); 259 __asan_set_death_callback(0); 260 __asan_set_error_report_callback(0); 261 __asan_handle_no_return(); 262 } 263} 264 265// -------------------------- Init ------------------- {{{1 266static void IntFlagValue(const char *flags, const char *flag, 267 s64 *out_val) { 268 if (!flags) return; 269 const char *str = internal_strstr(flags, flag); 270 if (!str) return; 271 *out_val = internal_atoll(str + internal_strlen(flag)); 272} 273 274static void BoolFlagValue(const char *flags, const char *flag, 275 bool *out_val) { 276 if (!flags) return; 277 const char *str = internal_strstr(flags, flag); 278 if (!str) return; 279 const char *suffix = str + internal_strlen(flag); 280 if (!internal_atoll(str + internal_strlen(flag))) { 281 if (suffix[0] == '0') { 282 *out_val = false; 283 return; 284 } 285 } else { 286 *out_val = true; 287 return; 288 } 289 switch (suffix[0]) { 290 case 'y': 291 case 't': { 292 *out_val = true; 293 break; 294 } 295 case 'n': 296 case 'f': { 297 *out_val = false; 298 break; 299 } 300 default: return; 301 } 302} 303 304static void asan_atexit() { 305 AsanPrintf("AddressSanitizer exit stats:\n"); 306 __asan_print_accumulated_stats(); 307} 308 309} // namespace __asan 310 311// ---------------------- Interface ---------------- {{{1 312using namespace __asan; // NOLINT 313 314int __asan_set_error_exit_code(int exit_code) { 315 int old = FLAG_exitcode; 316 FLAG_exitcode = exit_code; 317 return old; 318} 319 320void NOINLINE __asan_handle_no_return() { 321 int local_stack; 322 AsanThread *curr_thread = asanThreadRegistry().GetCurrent(); 323 CHECK(curr_thread); 324 uptr top = curr_thread->stack_top(); 325 uptr bottom = ((uptr)&local_stack - kPageSize) & ~(kPageSize-1); 326 PoisonShadow(bottom, top - bottom, 0); 327} 328 329void NOINLINE __asan_set_death_callback(void (*callback)(void)) { 330 death_callback = callback; 331} 332 333void NOINLINE __asan_set_error_report_callback(void (*callback)(const char*)) { 334 error_report_callback = callback; 335 if (callback) { 336 error_message_buffer_size = 1 << 16; 337 error_message_buffer = 338 (char*)MmapOrDie(error_message_buffer_size, __FUNCTION__); 339 error_message_buffer_pos = 0; 340 } 341} 342 343void __asan_report_error(uptr pc, uptr bp, uptr sp, 344 uptr addr, bool is_write, uptr access_size) { 345 // Do not print more than one report, otherwise they will mix up. 346 static int num_calls = 0; 347 if (AtomicInc(&num_calls) > 1) return; 348 349 AsanPrintf("====================================================" 350 "=============\n"); 351 const char *bug_descr = "unknown-crash"; 352 if (AddrIsInMem(addr)) { 353 u8 *shadow_addr = (u8*)MemToShadow(addr); 354 // If we are accessing 16 bytes, look at the second shadow byte. 355 if (*shadow_addr == 0 && access_size > SHADOW_GRANULARITY) 356 shadow_addr++; 357 // If we are in the partial right redzone, look at the next shadow byte. 358 if (*shadow_addr > 0 && *shadow_addr < 128) 359 shadow_addr++; 360 switch (*shadow_addr) { 361 case kAsanHeapLeftRedzoneMagic: 362 case kAsanHeapRightRedzoneMagic: 363 bug_descr = "heap-buffer-overflow"; 364 break; 365 case kAsanHeapFreeMagic: 366 bug_descr = "heap-use-after-free"; 367 break; 368 case kAsanStackLeftRedzoneMagic: 369 bug_descr = "stack-buffer-underflow"; 370 break; 371 case kAsanStackMidRedzoneMagic: 372 case kAsanStackRightRedzoneMagic: 373 case kAsanStackPartialRedzoneMagic: 374 bug_descr = "stack-buffer-overflow"; 375 break; 376 case kAsanStackAfterReturnMagic: 377 bug_descr = "stack-use-after-return"; 378 break; 379 case kAsanUserPoisonedMemoryMagic: 380 bug_descr = "use-after-poison"; 381 break; 382 case kAsanGlobalRedzoneMagic: 383 bug_descr = "global-buffer-overflow"; 384 break; 385 } 386 } 387 388 AsanThread *curr_thread = asanThreadRegistry().GetCurrent(); 389 u32 curr_tid = asanThreadRegistry().GetCurrentTidOrInvalid(); 390 391 if (curr_thread) { 392 // We started reporting an error message. Stop using the fake stack 393 // in case we will call an instrumented function from a symbolizer. 394 curr_thread->fake_stack().StopUsingFakeStack(); 395 } 396 397 AsanReport("ERROR: AddressSanitizer %s on address " 398 "%p at pc 0x%zx bp 0x%zx sp 0x%zx\n", 399 bug_descr, (void*)addr, pc, bp, sp); 400 401 AsanPrintf("%s of size %zu at %p thread T%d\n", 402 access_size ? (is_write ? "WRITE" : "READ") : "ACCESS", 403 access_size, (void*)addr, curr_tid); 404 405 if (FLAG_debug) { 406 PrintBytes("PC: ", (uptr*)pc); 407 } 408 409 GET_STACK_TRACE_WITH_PC_AND_BP(kStackTraceMax, pc, bp); 410 stack.PrintStack(); 411 412 CHECK(AddrIsInMem(addr)); 413 414 DescribeAddress(addr, access_size); 415 416 uptr shadow_addr = MemToShadow(addr); 417 AsanReport("ABORTING\n"); 418 __asan_print_accumulated_stats(); 419 AsanPrintf("Shadow byte and word:\n"); 420 AsanPrintf(" %p: %x\n", (void*)shadow_addr, *(unsigned char*)shadow_addr); 421 uptr aligned_shadow = shadow_addr & ~(kWordSize - 1); 422 PrintBytes(" ", (uptr*)(aligned_shadow)); 423 AsanPrintf("More shadow bytes:\n"); 424 PrintBytes(" ", (uptr*)(aligned_shadow-4*kWordSize)); 425 PrintBytes(" ", (uptr*)(aligned_shadow-3*kWordSize)); 426 PrintBytes(" ", (uptr*)(aligned_shadow-2*kWordSize)); 427 PrintBytes(" ", (uptr*)(aligned_shadow-1*kWordSize)); 428 PrintBytes("=>", (uptr*)(aligned_shadow+0*kWordSize)); 429 PrintBytes(" ", (uptr*)(aligned_shadow+1*kWordSize)); 430 PrintBytes(" ", (uptr*)(aligned_shadow+2*kWordSize)); 431 PrintBytes(" ", (uptr*)(aligned_shadow+3*kWordSize)); 432 PrintBytes(" ", (uptr*)(aligned_shadow+4*kWordSize)); 433 if (error_report_callback) { 434 error_report_callback(error_message_buffer); 435 } 436 Die(); 437} 438 439static void ParseAsanOptions(const char *options) { 440 IntFlagValue(options, "malloc_context_size=", 441 (s64*)&FLAG_malloc_context_size); 442 CHECK(FLAG_malloc_context_size <= kMallocContextSize); 443 444 IntFlagValue(options, "max_malloc_fill_size=", 445 (s64*)&FLAG_max_malloc_fill_size); 446 447 IntFlagValue(options, "verbosity=", &FLAG_v); 448 449 IntFlagValue(options, "redzone=", (s64*)&FLAG_redzone); 450 CHECK(FLAG_redzone >= 16); 451 CHECK(IsPowerOfTwo(FLAG_redzone)); 452 IntFlagValue(options, "quarantine_size=", (s64*)&FLAG_quarantine_size); 453 454 IntFlagValue(options, "atexit=", &FLAG_atexit); 455 BoolFlagValue(options, "poison_shadow=", &FLAG_poison_shadow); 456 IntFlagValue(options, "report_globals=", &FLAG_report_globals); 457 BoolFlagValue(options, "handle_segv=", &FLAG_handle_segv); 458 BoolFlagValue(options, "use_sigaltstack=", &FLAG_use_sigaltstack); 459 BoolFlagValue(options, "symbolize=", &FLAG_symbolize); 460 IntFlagValue(options, "demangle=", &FLAG_demangle); 461 IntFlagValue(options, "debug=", &FLAG_debug); 462 BoolFlagValue(options, "replace_cfallocator=", &FLAG_replace_cfallocator); 463 BoolFlagValue(options, "mac_ignore_invalid_free=", 464 &FLAG_mac_ignore_invalid_free); 465 BoolFlagValue(options, "replace_str=", &FLAG_replace_str); 466 BoolFlagValue(options, "replace_intrin=", &FLAG_replace_intrin); 467 BoolFlagValue(options, "use_fake_stack=", &FLAG_use_fake_stack); 468 IntFlagValue(options, "exitcode=", &FLAG_exitcode); 469 BoolFlagValue(options, "allow_user_poisoning=", &FLAG_allow_user_poisoning); 470 IntFlagValue(options, "sleep_before_dying=", &FLAG_sleep_before_dying); 471 BoolFlagValue(options, "abort_on_error=", &FLAG_abort_on_error); 472 BoolFlagValue(options, "unmap_shadow_on_exit=", &FLAG_unmap_shadow_on_exit); 473 // By default, disable core dumper on 64-bit -- 474 // it makes little sense to dump 16T+ core. 475 BoolFlagValue(options, "disable_core=", &FLAG_disable_core); 476 477 // Allow the users to work around the bug in Nvidia drivers prior to 295.*. 478 BoolFlagValue(options, "check_malloc_usable_size=", 479 &FLAG_check_malloc_usable_size); 480} 481 482void __asan_init() { 483 if (asan_inited) return; 484 asan_init_is_running = true; 485 486 // Make sure we are not statically linked. 487 AsanDoesNotSupportStaticLinkage(); 488 489#if !defined(_WIN32) 490 if (__asan_default_options) { 491 ParseAsanOptions(__asan_default_options); 492 if (FLAG_v) { 493 Report("Using the defaults from __asan_default_options: %s\n", 494 __asan_default_options); 495 } 496 } 497#endif 498 // flags 499 const char *options = GetEnv("ASAN_OPTIONS"); 500 ParseAsanOptions(options); 501 502 if (FLAG_v && options) { 503 Report("Parsed ASAN_OPTIONS: %s\n", options); 504 } 505 506 if (FLAG_atexit) { 507 Atexit(asan_atexit); 508 } 509 510 // interceptors 511 InitializeAsanInterceptors(); 512 513 ReplaceSystemMalloc(); 514 ReplaceOperatorsNewAndDelete(); 515 516 if (FLAG_v) { 517 Printf("|| `[%p, %p]` || HighMem ||\n", 518 (void*)kHighMemBeg, (void*)kHighMemEnd); 519 Printf("|| `[%p, %p]` || HighShadow ||\n", 520 (void*)kHighShadowBeg, (void*)kHighShadowEnd); 521 Printf("|| `[%p, %p]` || ShadowGap ||\n", 522 (void*)kShadowGapBeg, (void*)kShadowGapEnd); 523 Printf("|| `[%p, %p]` || LowShadow ||\n", 524 (void*)kLowShadowBeg, (void*)kLowShadowEnd); 525 Printf("|| `[%p, %p]` || LowMem ||\n", 526 (void*)kLowMemBeg, (void*)kLowMemEnd); 527 Printf("MemToShadow(shadow): %p %p %p %p\n", 528 (void*)MEM_TO_SHADOW(kLowShadowBeg), 529 (void*)MEM_TO_SHADOW(kLowShadowEnd), 530 (void*)MEM_TO_SHADOW(kHighShadowBeg), 531 (void*)MEM_TO_SHADOW(kHighShadowEnd)); 532 Printf("red_zone=%zu\n", (uptr)FLAG_redzone); 533 Printf("malloc_context_size=%zu\n", (uptr)FLAG_malloc_context_size); 534 535 Printf("SHADOW_SCALE: %zx\n", (uptr)SHADOW_SCALE); 536 Printf("SHADOW_GRANULARITY: %zx\n", (uptr)SHADOW_GRANULARITY); 537 Printf("SHADOW_OFFSET: %zx\n", (uptr)SHADOW_OFFSET); 538 CHECK(SHADOW_SCALE >= 3 && SHADOW_SCALE <= 7); 539 } 540 541 if (FLAG_disable_core) { 542 DisableCoreDumper(); 543 } 544 545 uptr shadow_start = kLowShadowBeg; 546 if (kLowShadowBeg > 0) shadow_start -= kMmapGranularity; 547 uptr shadow_end = kHighShadowEnd; 548 if (MemoryRangeIsAvailable(shadow_start, shadow_end)) { 549 if (kLowShadowBeg != kLowShadowEnd) { 550 // mmap the low shadow plus at least one page. 551 ReserveShadowMemoryRange(kLowShadowBeg - kMmapGranularity, kLowShadowEnd); 552 } 553 // mmap the high shadow. 554 ReserveShadowMemoryRange(kHighShadowBeg, kHighShadowEnd); 555 // protect the gap 556 void *prot = Mprotect(kShadowGapBeg, kShadowGapEnd - kShadowGapBeg + 1); 557 CHECK(prot == (void*)kShadowGapBeg); 558 } else { 559 Report("Shadow memory range interleaves with an existing memory mapping. " 560 "ASan cannot proceed correctly. ABORTING.\n"); 561 DumpProcessMap(); 562 Die(); 563 } 564 565 InstallSignalHandlers(); 566 567 // On Linux AsanThread::ThreadStart() calls malloc() that's why asan_inited 568 // should be set to 1 prior to initializing the threads. 569 asan_inited = 1; 570 asan_init_is_running = false; 571 572 asanThreadRegistry().Init(); 573 asanThreadRegistry().GetMain()->ThreadStart(); 574 force_interface_symbols(); // no-op. 575 576 if (FLAG_v) { 577 Report("AddressSanitizer Init done\n"); 578 } 579} 580 581#if defined(ASAN_USE_PREINIT_ARRAY) 582 // On Linux, we force __asan_init to be called before anyone else 583 // by placing it into .preinit_array section. 584 // FIXME: do we have anything like this on Mac? 585 __attribute__((section(".preinit_array"))) 586 typeof(__asan_init) *__asan_preinit =__asan_init; 587#elif defined(_WIN32) && defined(_DLL) 588 // On Windows, when using dynamic CRT (/MD), we can put a pointer 589 // to __asan_init into the global list of C initializers. 590 // See crt0dat.c in the CRT sources for the details. 591 #pragma section(".CRT$XIB", long, read) // NOLINT 592 __declspec(allocate(".CRT$XIB")) void (*__asan_preinit)() = __asan_init; 593#endif 594