asan_rtl.cc revision b831086e7c1e6004cf57594ec81b662f290dc2ac
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_atomic.h"
25#include "sanitizer_common/sanitizer_flags.h"
26#include "sanitizer_common/sanitizer_libc.h"
27
28namespace __sanitizer {
29using namespace __asan;
30
31void Die() {
32  static atomic_uint32_t num_calls;
33  if (atomic_fetch_add(&num_calls, 1, memory_order_relaxed) != 0) {
34    // Don't die twice - run a busy loop.
35    while (1) { }
36  }
37  if (flags()->sleep_before_dying) {
38    Report("Sleeping for %zd second(s)\n", flags()->sleep_before_dying);
39    SleepForSeconds(flags()->sleep_before_dying);
40  }
41  if (flags()->unmap_shadow_on_exit)
42    UnmapOrDie((void*)kLowShadowBeg, kHighShadowEnd - kLowShadowBeg);
43  if (death_callback)
44    death_callback();
45  if (flags()->abort_on_error)
46    Abort();
47  Exit(flags()->exitcode);
48}
49
50void CheckFailed(const char *file, int line, const char *cond, u64 v1, u64 v2) {
51  AsanReport("AddressSanitizer CHECK failed: %s:%d \"%s\" (0x%zx, 0x%zx)\n",
52             file, line, cond, (uptr)v1, (uptr)v2);
53  PRINT_CURRENT_STACK();
54  ShowStatsAndAbort();
55}
56
57}  // namespace __sanitizer
58
59namespace __asan {
60
61// -------------------------- Flags ------------------------- {{{1
62static const int kMallocContextSize = 30;
63
64static Flags asan_flags;
65
66Flags *flags() {
67  return &asan_flags;
68}
69
70static void ParseFlagsFromString(Flags *f, const char *str) {
71  ParseFlag(str, &f->quarantine_size, "quarantine_size");
72  ParseFlag(str, &f->symbolize, "symbolize");
73  ParseFlag(str, &f->verbosity, "verbosity");
74  ParseFlag(str, &f->redzone, "redzone");
75  CHECK(f->redzone >= 16);
76  CHECK(IsPowerOfTwo(f->redzone));
77
78  ParseFlag(str, &f->debug, "debug");
79  ParseFlag(str, &f->report_globals, "report_globals");
80  ParseFlag(str, &f->malloc_context_size, "malloc_context_size");
81  CHECK(f->malloc_context_size <= kMallocContextSize);
82
83  ParseFlag(str, &f->replace_str, "replace_str");
84  ParseFlag(str, &f->replace_intrin, "replace_intrin");
85  ParseFlag(str, &f->replace_cfallocator, "replace_cfallocator");
86  ParseFlag(str, &f->mac_ignore_invalid_free, "mac_ignore_invalid_free");
87  ParseFlag(str, &f->use_fake_stack, "use_fake_stack");
88  ParseFlag(str, &f->max_malloc_fill_size, "max_malloc_fill_size");
89  ParseFlag(str, &f->exitcode, "exitcode");
90  ParseFlag(str, &f->allow_user_poisoning, "allow_user_poisoning");
91  ParseFlag(str, &f->sleep_before_dying, "sleep_before_dying");
92  ParseFlag(str, &f->handle_segv, "handle_segv");
93  ParseFlag(str, &f->use_sigaltstack, "use_sigaltstack");
94  ParseFlag(str, &f->check_malloc_usable_size, "check_malloc_usable_size");
95  ParseFlag(str, &f->unmap_shadow_on_exit, "unmap_shadow_on_exit");
96  ParseFlag(str, &f->abort_on_error, "abort_on_error");
97  ParseFlag(str, &f->atexit, "atexit");
98  ParseFlag(str, &f->disable_core, "disable_core");
99}
100
101extern "C" {
102const char* WEAK __asan_default_options() { return ""; }
103}  // extern "C"
104
105void InitializeFlags(Flags *f, const char *env) {
106  internal_memset(f, 0, sizeof(*f));
107
108  f->quarantine_size = (ASAN_LOW_MEMORY) ? 1UL << 24 : 1UL << 28;
109  f->symbolize = false;
110  f->verbosity = 0;
111  f->redzone = (ASAN_LOW_MEMORY) ? 64 : 128;
112  f->debug = false;
113  f->report_globals = 1;
114  f->malloc_context_size = kMallocContextSize;
115  f->replace_str = true;
116  f->replace_intrin = true;
117  f->replace_cfallocator = true;
118  f->mac_ignore_invalid_free = false;
119  f->use_fake_stack = true;
120  f->max_malloc_fill_size = 0;
121  f->exitcode = ASAN_DEFAULT_FAILURE_EXITCODE;
122  f->allow_user_poisoning = true;
123  f->sleep_before_dying = 0;
124  f->handle_segv = ASAN_NEEDS_SEGV;
125  f->use_sigaltstack = false;
126  f->check_malloc_usable_size = true;
127  f->unmap_shadow_on_exit = false;
128  f->abort_on_error = false;
129  f->atexit = false;
130  f->disable_core = (__WORDSIZE == 64);
131
132  // Override from user-specified string.
133  ParseFlagsFromString(f, __asan_default_options());
134  if (flags()->verbosity) {
135    Report("Using the defaults from __asan_default_options: %s\n",
136           __asan_default_options());
137  }
138
139  // Override from command line.
140  ParseFlagsFromString(f, env);
141}
142
143// -------------------------- Globals --------------------- {{{1
144int asan_inited;
145bool asan_init_is_running;
146void (*death_callback)(void);
147static void (*error_report_callback)(const char*);
148char *error_message_buffer = 0;
149uptr error_message_buffer_pos = 0;
150uptr error_message_buffer_size = 0;
151
152// -------------------------- Misc ---------------- {{{1
153void ShowStatsAndAbort() {
154  __asan_print_accumulated_stats();
155  Die();
156}
157
158static void PrintBytes(const char *before, uptr *a) {
159  u8 *bytes = (u8*)a;
160  uptr byte_num = (__WORDSIZE) / 8;
161  AsanPrintf("%s%p:", before, (void*)a);
162  for (uptr i = 0; i < byte_num; i++) {
163    AsanPrintf(" %x%x", bytes[i] >> 4, bytes[i] & 15);
164  }
165  AsanPrintf("\n");
166}
167
168void AppendToErrorMessageBuffer(const char *buffer) {
169  if (error_message_buffer) {
170    uptr length = internal_strlen(buffer);
171    CHECK_GE(error_message_buffer_size, error_message_buffer_pos);
172    uptr remaining = error_message_buffer_size - error_message_buffer_pos;
173    internal_strncpy(error_message_buffer + error_message_buffer_pos,
174                     buffer, remaining);
175    error_message_buffer[error_message_buffer_size - 1] = '\0';
176    // FIXME: reallocate the buffer instead of truncating the message.
177    error_message_buffer_pos += remaining > length ? length : remaining;
178  }
179}
180
181// ---------------------- mmap -------------------- {{{1
182// Reserve memory range [beg, end].
183static void ReserveShadowMemoryRange(uptr beg, uptr end) {
184  CHECK((beg % kPageSize) == 0);
185  CHECK(((end + 1) % kPageSize) == 0);
186  uptr size = end - beg + 1;
187  void *res = MmapFixedNoReserve(beg, size);
188  CHECK(res == (void*)beg && "ReserveShadowMemoryRange failed");
189}
190
191// ---------------------- LowLevelAllocator ------------- {{{1
192void *LowLevelAllocator::Allocate(uptr size) {
193  CHECK((size & (size - 1)) == 0 && "size must be a power of two");
194  if (allocated_end_ - allocated_current_ < (sptr)size) {
195    uptr size_to_allocate = Max(size, kPageSize);
196    allocated_current_ =
197        (char*)MmapOrDie(size_to_allocate, __FUNCTION__);
198    allocated_end_ = allocated_current_ + size_to_allocate;
199    PoisonShadow((uptr)allocated_current_, size_to_allocate,
200                 kAsanInternalHeapMagic);
201  }
202  CHECK(allocated_end_ - allocated_current_ >= (sptr)size);
203  void *res = allocated_current_;
204  allocated_current_ += size;
205  return res;
206}
207
208// ---------------------- DescribeAddress -------------------- {{{1
209static bool DescribeStackAddress(uptr addr, uptr access_size) {
210  AsanThread *t = asanThreadRegistry().FindThreadByStackAddress(addr);
211  if (!t) return false;
212  const sptr kBufSize = 4095;
213  char buf[kBufSize];
214  uptr offset = 0;
215  const char *frame_descr = t->GetFrameNameByAddr(addr, &offset);
216  // This string is created by the compiler and has the following form:
217  // "FunctioName n alloc_1 alloc_2 ... alloc_n"
218  // where alloc_i looks like "offset size len ObjectName ".
219  CHECK(frame_descr);
220  // Report the function name and the offset.
221  const char *name_end = internal_strchr(frame_descr, ' ');
222  CHECK(name_end);
223  buf[0] = 0;
224  internal_strncat(buf, frame_descr,
225                   Min(kBufSize,
226                       static_cast<sptr>(name_end - frame_descr)));
227  AsanPrintf("Address %p is located at offset %zu "
228             "in frame <%s> of T%d's stack:\n",
229             (void*)addr, offset, buf, t->tid());
230  // Report the number of stack objects.
231  char *p;
232  uptr n_objects = internal_simple_strtoll(name_end, &p, 10);
233  CHECK(n_objects > 0);
234  AsanPrintf("  This frame has %zu object(s):\n", n_objects);
235  // Report all objects in this frame.
236  for (uptr i = 0; i < n_objects; i++) {
237    uptr beg, size;
238    sptr len;
239    beg  = internal_simple_strtoll(p, &p, 10);
240    size = internal_simple_strtoll(p, &p, 10);
241    len  = internal_simple_strtoll(p, &p, 10);
242    if (beg <= 0 || size <= 0 || len < 0 || *p != ' ') {
243      AsanPrintf("AddressSanitizer can't parse the stack frame "
244                 "descriptor: |%s|\n", frame_descr);
245      break;
246    }
247    p++;
248    buf[0] = 0;
249    internal_strncat(buf, p, Min(kBufSize, len));
250    p += len;
251    AsanPrintf("    [%zu, %zu) '%s'\n", beg, beg + size, buf);
252  }
253  AsanPrintf("HINT: this may be a false positive if your program uses "
254             "some custom stack unwind mechanism\n"
255             "      (longjmp and C++ exceptions *are* supported)\n");
256  t->summary()->Announce();
257  return true;
258}
259
260static bool DescribeAddrIfShadow(uptr addr) {
261  if (AddrIsInMem(addr))
262    return false;
263  static const char kAddrInShadowReport[] =
264      "Address %p is located in the %s.\n";
265  if (AddrIsInShadowGap(addr)) {
266    AsanPrintf(kAddrInShadowReport, addr, "shadow gap area");
267    return true;
268  }
269  if (AddrIsInHighShadow(addr)) {
270    AsanPrintf(kAddrInShadowReport, addr, "high shadow area");
271    return true;
272  }
273  if (AddrIsInLowShadow(addr)) {
274    AsanPrintf(kAddrInShadowReport, addr, "low shadow area");
275    return true;
276  }
277
278  CHECK(0);  // Unreachable.
279  return false;
280}
281
282static NOINLINE void DescribeAddress(uptr addr, uptr access_size) {
283  // Check if this is shadow or shadow gap.
284  if (DescribeAddrIfShadow(addr))
285    return;
286
287  CHECK(AddrIsInMem(addr));
288
289  // Check if this is a global.
290  if (DescribeAddrIfGlobal(addr))
291    return;
292
293  if (DescribeStackAddress(addr, access_size))
294    return;
295
296  // finally, check if this is a heap.
297  DescribeHeapAddress(addr, access_size);
298}
299
300// -------------------------- Run-time entry ------------------- {{{1
301// exported functions
302#define ASAN_REPORT_ERROR(type, is_write, size)                     \
303extern "C" NOINLINE INTERFACE_ATTRIBUTE                        \
304void __asan_report_ ## type ## size(uptr addr);                \
305void __asan_report_ ## type ## size(uptr addr) {               \
306  GET_CALLER_PC_BP_SP;                                              \
307  __asan_report_error(pc, bp, sp, addr, is_write, size);            \
308}
309
310ASAN_REPORT_ERROR(load, false, 1)
311ASAN_REPORT_ERROR(load, false, 2)
312ASAN_REPORT_ERROR(load, false, 4)
313ASAN_REPORT_ERROR(load, false, 8)
314ASAN_REPORT_ERROR(load, false, 16)
315ASAN_REPORT_ERROR(store, true, 1)
316ASAN_REPORT_ERROR(store, true, 2)
317ASAN_REPORT_ERROR(store, true, 4)
318ASAN_REPORT_ERROR(store, true, 8)
319ASAN_REPORT_ERROR(store, true, 16)
320
321// Force the linker to keep the symbols for various ASan interface functions.
322// We want to keep those in the executable in order to let the instrumented
323// dynamic libraries access the symbol even if it is not used by the executable
324// itself. This should help if the build system is removing dead code at link
325// time.
326static NOINLINE void force_interface_symbols() {
327  volatile int fake_condition = 0;  // prevent dead condition elimination.
328  if (fake_condition) {
329    __asan_report_load1(0);
330    __asan_report_load2(0);
331    __asan_report_load4(0);
332    __asan_report_load8(0);
333    __asan_report_load16(0);
334    __asan_report_store1(0);
335    __asan_report_store2(0);
336    __asan_report_store4(0);
337    __asan_report_store8(0);
338    __asan_report_store16(0);
339    __asan_register_global(0, 0, 0);
340    __asan_register_globals(0, 0);
341    __asan_unregister_globals(0, 0);
342    __asan_set_death_callback(0);
343    __asan_set_error_report_callback(0);
344    __asan_handle_no_return();
345  }
346}
347
348// -------------------------- Init ------------------- {{{1
349static void asan_atexit() {
350  AsanPrintf("AddressSanitizer exit stats:\n");
351  __asan_print_accumulated_stats();
352}
353
354}  // namespace __asan
355
356// ---------------------- Interface ---------------- {{{1
357using namespace __asan;  // NOLINT
358
359int __asan_set_error_exit_code(int exit_code) {
360  int old = flags()->exitcode;
361  flags()->exitcode = exit_code;
362  return old;
363}
364
365void NOINLINE __asan_handle_no_return() {
366  int local_stack;
367  AsanThread *curr_thread = asanThreadRegistry().GetCurrent();
368  CHECK(curr_thread);
369  uptr top = curr_thread->stack_top();
370  uptr bottom = ((uptr)&local_stack - kPageSize) & ~(kPageSize-1);
371  PoisonShadow(bottom, top - bottom, 0);
372}
373
374void NOINLINE __asan_set_death_callback(void (*callback)(void)) {
375  death_callback = callback;
376}
377
378void NOINLINE __asan_set_error_report_callback(void (*callback)(const char*)) {
379  error_report_callback = callback;
380  if (callback) {
381    error_message_buffer_size = 1 << 16;
382    error_message_buffer =
383        (char*)MmapOrDie(error_message_buffer_size, __FUNCTION__);
384    error_message_buffer_pos = 0;
385  }
386}
387
388void __asan_report_error(uptr pc, uptr bp, uptr sp,
389                         uptr addr, bool is_write, uptr access_size) {
390  static atomic_uint32_t num_calls;
391  if (atomic_fetch_add(&num_calls, 1, memory_order_relaxed) != 0) {
392    // Do not print more than one report, otherwise they will mix up.
393    // We can not return here because the function is marked as never-return.
394    AsanPrintf("AddressSanitizer: while reporting a bug found another one."
395               "Ignoring.\n");
396    SleepForSeconds(5);
397    Die();
398  }
399
400  AsanPrintf("===================================================="
401             "=============\n");
402  const char *bug_descr = "unknown-crash";
403  if (AddrIsInMem(addr)) {
404    u8 *shadow_addr = (u8*)MemToShadow(addr);
405    // If we are accessing 16 bytes, look at the second shadow byte.
406    if (*shadow_addr == 0 && access_size > SHADOW_GRANULARITY)
407      shadow_addr++;
408    // If we are in the partial right redzone, look at the next shadow byte.
409    if (*shadow_addr > 0 && *shadow_addr < 128)
410      shadow_addr++;
411    switch (*shadow_addr) {
412      case kAsanHeapLeftRedzoneMagic:
413      case kAsanHeapRightRedzoneMagic:
414        bug_descr = "heap-buffer-overflow";
415        break;
416      case kAsanHeapFreeMagic:
417        bug_descr = "heap-use-after-free";
418        break;
419      case kAsanStackLeftRedzoneMagic:
420        bug_descr = "stack-buffer-underflow";
421        break;
422      case kAsanStackMidRedzoneMagic:
423      case kAsanStackRightRedzoneMagic:
424      case kAsanStackPartialRedzoneMagic:
425        bug_descr = "stack-buffer-overflow";
426        break;
427      case kAsanStackAfterReturnMagic:
428        bug_descr = "stack-use-after-return";
429        break;
430      case kAsanUserPoisonedMemoryMagic:
431        bug_descr = "use-after-poison";
432        break;
433      case kAsanGlobalRedzoneMagic:
434        bug_descr = "global-buffer-overflow";
435        break;
436    }
437  }
438
439  AsanThread *curr_thread = asanThreadRegistry().GetCurrent();
440  u32 curr_tid = asanThreadRegistry().GetCurrentTidOrInvalid();
441
442  if (curr_thread) {
443    // We started reporting an error message. Stop using the fake stack
444    // in case we will call an instrumented function from a symbolizer.
445    curr_thread->fake_stack().StopUsingFakeStack();
446  }
447
448  AsanReport("ERROR: AddressSanitizer %s on address "
449             "%p at pc 0x%zx bp 0x%zx sp 0x%zx\n",
450             bug_descr, (void*)addr, pc, bp, sp);
451
452  AsanPrintf("%s of size %zu at %p thread T%d\n",
453             access_size ? (is_write ? "WRITE" : "READ") : "ACCESS",
454             access_size, (void*)addr, curr_tid);
455
456  if (flags()->debug) {
457    PrintBytes("PC: ", (uptr*)pc);
458  }
459
460  GET_STACK_TRACE_WITH_PC_AND_BP(kStackTraceMax, pc, bp);
461  stack.PrintStack();
462
463  DescribeAddress(addr, access_size);
464
465  if (AddrIsInMem(addr)) {
466    uptr shadow_addr = MemToShadow(addr);
467    AsanReport("ABORTING\n");
468    __asan_print_accumulated_stats();
469    AsanPrintf("Shadow byte and word:\n");
470    AsanPrintf("  %p: %x\n", (void*)shadow_addr, *(unsigned char*)shadow_addr);
471    uptr aligned_shadow = shadow_addr & ~(kWordSize - 1);
472    PrintBytes("  ", (uptr*)(aligned_shadow));
473    AsanPrintf("More shadow bytes:\n");
474    PrintBytes("  ", (uptr*)(aligned_shadow-4*kWordSize));
475    PrintBytes("  ", (uptr*)(aligned_shadow-3*kWordSize));
476    PrintBytes("  ", (uptr*)(aligned_shadow-2*kWordSize));
477    PrintBytes("  ", (uptr*)(aligned_shadow-1*kWordSize));
478    PrintBytes("=>", (uptr*)(aligned_shadow+0*kWordSize));
479    PrintBytes("  ", (uptr*)(aligned_shadow+1*kWordSize));
480    PrintBytes("  ", (uptr*)(aligned_shadow+2*kWordSize));
481    PrintBytes("  ", (uptr*)(aligned_shadow+3*kWordSize));
482    PrintBytes("  ", (uptr*)(aligned_shadow+4*kWordSize));
483  }
484  if (error_report_callback) {
485    error_report_callback(error_message_buffer);
486  }
487  Die();
488}
489
490
491void __asan_init() {
492  if (asan_inited) return;
493  asan_init_is_running = true;
494
495  // Make sure we are not statically linked.
496  AsanDoesNotSupportStaticLinkage();
497
498  // Initialize flags.
499  const char *options = GetEnv("ASAN_OPTIONS");
500  InitializeFlags(flags(), options);
501
502  if (flags()->verbosity && options) {
503    Report("Parsed ASAN_OPTIONS: %s\n", options);
504  }
505
506  if (flags()->atexit) {
507    Atexit(asan_atexit);
508  }
509
510  // interceptors
511  InitializeAsanInterceptors();
512
513  ReplaceSystemMalloc();
514  ReplaceOperatorsNewAndDelete();
515
516  if (flags()->verbosity) {
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)flags()->redzone);
533    Printf("malloc_context_size=%zu\n", (uptr)flags()->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 (flags()->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 (flags()->verbosity) {
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