1 //===-- ubsan_init.cc -----------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Initialization of UBSan runtime.
12 //===----------------------------------------------------------------------===//
14 #include "ubsan_platform.h"
16 #include "ubsan_diag.h"
17 #include "ubsan_init.h"
18 #include "ubsan_flags.h"
19 #include "sanitizer_common/sanitizer_common.h"
20 #include "sanitizer_common/sanitizer_libc.h"
21 #include "sanitizer_common/sanitizer_mutex.h"
22 #include "sanitizer_common/sanitizer_symbolizer.h"
24 using namespace __ubsan;
26 const char *__ubsan::GetSanititizerToolName() {
27 return "UndefinedBehaviorSanitizer";
30 static bool ubsan_initialized;
31 static StaticSpinMutex ubsan_init_mu;
33 static void CommonInit() {
34 InitializeSuppressions();
37 static void CommonStandaloneInit() {
38 SanitizerToolName = GetSanititizerToolName();
41 __sanitizer_set_report_path(common_flags()->log_path);
43 InitializeCoverage(common_flags()->coverage, common_flags()->coverage_dir);
47 void __ubsan::InitAsStandalone() {
48 SpinMutexLock l(&ubsan_init_mu);
49 if (!ubsan_initialized) {
50 CommonStandaloneInit();
51 ubsan_initialized = true;
55 void __ubsan::InitAsStandaloneIfNecessary() { return InitAsStandalone(); }
57 void __ubsan::InitAsPlugin() {
58 SpinMutexLock l(&ubsan_init_mu);
59 if (!ubsan_initialized) {
61 ubsan_initialized = true;
65 #endif // CAN_SANITIZE_UB