gcc/libsanitizer/ubsan/ubsan_init.cc
Max Ostapenko 696d846a56 libsanitizer merge from upstream r250806.
libsanitizer/

2015-10-20  Maxim Ostapenko  <m.ostapenko@partner.samsung.com>

	* All source files: Merge from upstream r250806.
	* configure.ac (link_sanitizer_common): Add -lrt flag.
	* configure.tgt: Enable TSAN and LSAN for aarch64-linux targets.
	Set CXX_ABI_NEEDED=true for darwin.
	* asan/Makefile.am (asan_files): Add new files.
	(DEFS): Add DCAN_SANITIZE_UB=0 and remove unused and legacy
	DASAN_FLEXIBLE_MAPPING_AND_OFFSET=0.
	* asan/Makefile.in: Regenerate.
	* ubsan/Makefile.am (ubsan_files): Add new files.
	(DEFS): Add DCAN_SANITIZE_UB=1.
	(libubsan_la_LIBADD): Add -lc++abi if CXX_ABI_NEEDED is true.
	* ubsan/Makefile.in: Regenerate.
	* tsan/Makefile.am (tsan_files): Add new files.
	(DEFS): Add DCAN_SANITIZE_UB=0.
	* tsan/Makefile.in: Regenerate.
	* sanitizer_common/Makefile.am (sanitizer_common_files): Add new files.
	* sanitizer_common/Makefile.in: Regenerate.
	* asan/libtool-version: Bump the libasan SONAME.

From-SVN: r229111
2015-10-21 10:32:45 +03:00

77 lines
2.0 KiB
C++

//===-- ubsan_init.cc -----------------------------------------------------===//
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Initialization of UBSan runtime.
//
//===----------------------------------------------------------------------===//
#include "ubsan_platform.h"
#if CAN_SANITIZE_UB
#include "ubsan_diag.h"
#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"
#include "sanitizer_common/sanitizer_symbolizer.h"
using namespace __ubsan;
static enum {
UBSAN_MODE_UNKNOWN = 0,
UBSAN_MODE_STANDALONE,
UBSAN_MODE_PLUGIN
} ubsan_mode;
static StaticSpinMutex ubsan_init_mu;
static void CommonInit() {
InitializeSuppressions();
}
static void CommonStandaloneInit() {
SanitizerToolName = "UndefinedBehaviorSanitizer";
InitializeFlags();
CacheBinaryName();
__sanitizer_set_report_path(common_flags()->log_path);
InitializeCoverage(common_flags()->coverage, common_flags()->coverage_dir);
CommonInit();
ubsan_mode = UBSAN_MODE_STANDALONE;
}
void __ubsan::InitAsStandalone() {
if (SANITIZER_CAN_USE_PREINIT_ARRAY) {
CHECK_EQ(UBSAN_MODE_UNKNOWN, ubsan_mode);
CommonStandaloneInit();
return;
}
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;
}
#endif // CAN_SANITIZE_UB