PR target/77349
[official-gcc.git] / libsanitizer / lsan / lsan.cc
blob6e7429c95a5efd43996e8859775ad79e4293b8e7
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_flag_parser.h"
17 #include "sanitizer_common/sanitizer_stacktrace.h"
18 #include "lsan_allocator.h"
19 #include "lsan_common.h"
20 #include "lsan_thread.h"
22 bool lsan_inited;
23 bool lsan_init_is_running;
25 namespace __lsan {
27 ///// Interface to the common LSan module. /////
28 bool WordIsPoisoned(uptr addr) {
29 return false;
32 } // namespace __lsan
34 using namespace __lsan; // NOLINT
36 static void InitializeFlags() {
37 // Set all the default values.
38 SetCommonFlagsDefaults();
40 CommonFlags cf;
41 cf.CopyFrom(*common_flags());
42 cf.external_symbolizer_path = GetEnv("LSAN_SYMBOLIZER_PATH");
43 cf.malloc_context_size = 30;
44 cf.detect_leaks = true;
45 cf.exitcode = 23;
46 OverrideCommonFlags(cf);
49 Flags *f = flags();
50 f->SetDefaults();
52 FlagParser parser;
53 RegisterLsanFlags(&parser, f);
54 RegisterCommonFlags(&parser);
56 parser.ParseString(GetEnv("LSAN_OPTIONS"));
58 SetVerbosity(common_flags()->verbosity);
60 if (Verbosity()) ReportUnrecognizedFlags();
62 if (common_flags()->help) parser.PrintFlagDescriptions();
65 extern "C" void __lsan_init() {
66 CHECK(!lsan_init_is_running);
67 if (lsan_inited)
68 return;
69 lsan_init_is_running = true;
70 SanitizerToolName = "LeakSanitizer";
71 CacheBinaryName();
72 InitializeFlags();
73 InitCommonLsan();
74 InitializeAllocator();
75 InitTlsSize();
76 InitializeInterceptors();
77 InitializeThreadRegistry();
78 u32 tid = ThreadCreate(0, 0, true);
79 CHECK_EQ(tid, 0);
80 ThreadStart(tid, GetTid());
81 SetCurrentThread(tid);
83 if (common_flags()->detect_leaks && common_flags()->leak_check_at_exit)
84 Atexit(DoLeakCheck);
86 InitializeCoverage(common_flags()->coverage, common_flags()->coverage_dir);
88 lsan_inited = true;
89 lsan_init_is_running = false;
92 extern "C" SANITIZER_INTERFACE_ATTRIBUTE
93 void __sanitizer_print_stack_trace() {
94 GET_STACK_TRACE_FATAL;
95 stack.Print();