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