2014-07-26 06:24:34 +08:00
|
|
|
//===-- ubsan_init.cc -----------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Initialization of UBSan runtime.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-03-27 01:26:04 +08:00
|
|
|
#include "ubsan_platform.h"
|
|
|
|
#if CAN_SANITIZE_UB
|
2015-02-21 01:41:59 +08:00
|
|
|
#include "ubsan_diag.h"
|
2014-07-26 06:24:34 +08:00
|
|
|
#include "ubsan_init.h"
|
|
|
|
#include "ubsan_flags.h"
|
|
|
|
#include "sanitizer_common/sanitizer_common.h"
|
|
|
|
#include "sanitizer_common/sanitizer_libc.h"
|
|
|
|
#include "sanitizer_common/sanitizer_mutex.h"
|
2014-07-26 09:41:45 +08:00
|
|
|
#include "sanitizer_common/sanitizer_symbolizer.h"
|
2014-07-26 06:24:34 +08:00
|
|
|
|
|
|
|
using namespace __ubsan;
|
|
|
|
|
2017-04-15 02:24:35 +08:00
|
|
|
const char *__ubsan::GetSanititizerToolName() {
|
|
|
|
return "UndefinedBehaviorSanitizer";
|
|
|
|
}
|
|
|
|
|
2017-09-21 08:35:22 +08:00
|
|
|
static bool ubsan_initialized;
|
2015-04-02 06:42:36 +08:00
|
|
|
static StaticSpinMutex ubsan_init_mu;
|
2014-07-26 06:24:34 +08:00
|
|
|
|
2015-04-02 06:42:36 +08:00
|
|
|
static void CommonInit() {
|
2015-02-21 01:41:59 +08:00
|
|
|
InitializeSuppressions();
|
2015-04-02 06:42:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void CommonStandaloneInit() {
|
2017-04-15 02:24:35 +08:00
|
|
|
SanitizerToolName = GetSanititizerToolName();
|
2017-09-12 05:12:43 +08:00
|
|
|
CacheBinaryName();
|
2017-09-12 05:13:06 +08:00
|
|
|
InitializeFlags();
|
2015-04-20 04:16:13 +08:00
|
|
|
__sanitizer_set_report_path(common_flags()->log_path);
|
2016-08-16 02:35:40 +08:00
|
|
|
AndroidLogInit();
|
2015-01-06 09:31:23 +08:00
|
|
|
InitializeCoverage(common_flags()->coverage, common_flags()->coverage_dir);
|
2015-04-02 06:42:36 +08:00
|
|
|
CommonInit();
|
2014-07-26 06:24:34 +08:00
|
|
|
}
|
|
|
|
|
2015-04-02 06:42:36 +08:00
|
|
|
void __ubsan::InitAsStandalone() {
|
|
|
|
SpinMutexLock l(&ubsan_init_mu);
|
2017-09-21 08:35:22 +08:00
|
|
|
if (!ubsan_initialized) {
|
2015-04-02 06:42:36 +08:00
|
|
|
CommonStandaloneInit();
|
2017-09-21 08:35:22 +08:00
|
|
|
ubsan_initialized = true;
|
2015-04-02 06:42:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-21 08:35:22 +08:00
|
|
|
void __ubsan::InitAsStandaloneIfNecessary() { return InitAsStandalone(); }
|
|
|
|
|
2015-04-02 06:42:36 +08:00
|
|
|
void __ubsan::InitAsPlugin() {
|
|
|
|
SpinMutexLock l(&ubsan_init_mu);
|
2017-09-21 08:35:22 +08:00
|
|
|
if (!ubsan_initialized) {
|
|
|
|
CommonInit();
|
|
|
|
ubsan_initialized = true;
|
|
|
|
}
|
2015-04-02 06:42:36 +08:00
|
|
|
}
|
2015-03-27 01:26:04 +08:00
|
|
|
|
|
|
|
#endif // CAN_SANITIZE_UB
|