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";
|
|
|
|
}
|
|
|
|
|
2015-04-02 06:42:36 +08:00
|
|
|
static enum {
|
|
|
|
UBSAN_MODE_UNKNOWN = 0,
|
|
|
|
UBSAN_MODE_STANDALONE,
|
|
|
|
UBSAN_MODE_PLUGIN
|
|
|
|
} ubsan_mode;
|
|
|
|
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 02:32:51 +08:00
|
|
|
InitializeFlags();
|
2017-09-12 05:12:43 +08:00
|
|
|
CacheBinaryName();
|
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();
|
|
|
|
ubsan_mode = UBSAN_MODE_STANDALONE;
|
2014-07-26 06:24:34 +08:00
|
|
|
}
|
|
|
|
|
2015-04-02 06:42:36 +08:00
|
|
|
void __ubsan::InitAsStandalone() {
|
|
|
|
if (SANITIZER_CAN_USE_PREINIT_ARRAY) {
|
|
|
|
CHECK_EQ(UBSAN_MODE_UNKNOWN, ubsan_mode);
|
|
|
|
CommonStandaloneInit();
|
|
|
|
return;
|
2014-07-26 06:24:34 +08:00
|
|
|
}
|
2015-04-02 06:42:36 +08:00
|
|
|
SpinMutexLock l(&ubsan_init_mu);
|
|
|
|
CHECK_NE(UBSAN_MODE_PLUGIN, ubsan_mode);
|
|
|
|
if (ubsan_mode == UBSAN_MODE_UNKNOWN)
|
|
|
|
CommonStandaloneInit();
|
|
|
|
}
|
|
|
|
|
|
|
|
void __ubsan::InitAsStandaloneIfNecessary() {
|
|
|
|
if (SANITIZER_CAN_USE_PREINIT_ARRAY) {
|
|
|
|
CHECK_NE(UBSAN_MODE_UNKNOWN, ubsan_mode);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SpinMutexLock l(&ubsan_init_mu);
|
|
|
|
if (ubsan_mode == UBSAN_MODE_UNKNOWN)
|
|
|
|
CommonStandaloneInit();
|
|
|
|
}
|
|
|
|
|
|
|
|
void __ubsan::InitAsPlugin() {
|
|
|
|
#if !SANITIZER_CAN_USE_PREINIT_ARRAY
|
|
|
|
SpinMutexLock l(&ubsan_init_mu);
|
|
|
|
#endif
|
|
|
|
CHECK_EQ(UBSAN_MODE_UNKNOWN, ubsan_mode);
|
|
|
|
CommonInit();
|
|
|
|
ubsan_mode = UBSAN_MODE_PLUGIN;
|
|
|
|
}
|
2015-03-27 01:26:04 +08:00
|
|
|
|
|
|
|
#endif // CAN_SANITIZE_UB
|