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