PR debug/57232
[official-gcc.git] / libsanitizer / lsan / lsan.cc
blob270979a78e7e4d29338b303c7bbd64b97cf016ab
1 //=-- lsan.cc -------------------------------------------------------------===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // This file is a part of LeakSanitizer.
9 // Standalone LSan RTL.
11 //===----------------------------------------------------------------------===//
13 #include "lsan.h"
15 #include "sanitizer_common/sanitizer_flags.h"
16 #include "sanitizer_common/sanitizer_stacktrace.h"
17 #include "lsan_allocator.h"
18 #include "lsan_common.h"
19 #include "lsan_thread.h"
21 bool lsan_inited;
22 bool lsan_init_is_running;
24 namespace __lsan {
26 static void InitializeCommonFlags() {
27 CommonFlags *cf = common_flags();
28 SetCommonFlagsDefaults(cf);
29 cf->external_symbolizer_path = GetEnv("LSAN_SYMBOLIZER_PATH");
30 cf->malloc_context_size = 30;
31 cf->detect_leaks = true;
33 ParseCommonFlagsFromString(cf, GetEnv("LSAN_OPTIONS"));
36 } // namespace __lsan
38 using namespace __lsan; // NOLINT
40 extern "C" void __lsan_init() {
41 CHECK(!lsan_init_is_running);
42 if (lsan_inited)
43 return;
44 lsan_init_is_running = true;
45 SanitizerToolName = "LeakSanitizer";
46 InitializeCommonFlags();
47 InitializeAllocator();
48 InitTlsSize();
49 InitializeInterceptors();
50 InitializeThreadRegistry();
51 u32 tid = ThreadCreate(0, 0, true);
52 CHECK_EQ(tid, 0);
53 ThreadStart(tid, GetTid());
54 SetCurrentThread(tid);
56 // Start symbolizer process if necessary.
57 if (common_flags()->symbolize) {
58 Symbolizer::Init(common_flags()->external_symbolizer_path);
59 } else {
60 Symbolizer::Disable();
63 InitCommonLsan();
64 if (common_flags()->detect_leaks && common_flags()->leak_check_at_exit)
65 Atexit(DoLeakCheck);
66 lsan_inited = true;
67 lsan_init_is_running = false;