2014-07-24 02:44:54 +08:00
|
|
|
//===-- ubsan_flags.cc ----------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Runtime flags for UndefinedBehaviorSanitizer.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ubsan_flags.h"
|
|
|
|
#include "sanitizer_common/sanitizer_common.h"
|
|
|
|
#include "sanitizer_common/sanitizer_flags.h"
|
|
|
|
|
|
|
|
namespace __ubsan {
|
|
|
|
|
2014-07-30 08:01:41 +08:00
|
|
|
static const char *GetRuntimeFlagsFromCompileDefinition() {
|
|
|
|
#ifdef UBSAN_DEFAULT_OPTIONS
|
|
|
|
// Stringize the macro value
|
|
|
|
# define UBSAN_STRINGIZE(x) #x
|
|
|
|
# define UBSAN_STRINGIZE_OPTIONS(options) UBSAN_STRINGIZE(options)
|
|
|
|
return UBSAN_STRINGIZE_OPTIONS(UBSAN_DEFAULT_OPTIONS);
|
|
|
|
#else
|
|
|
|
return "";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-07-30 07:49:20 +08:00
|
|
|
void InitializeCommonFlags() {
|
|
|
|
CommonFlags *cf = common_flags();
|
|
|
|
SetCommonFlagsDefaults(cf);
|
|
|
|
cf->print_summary = false;
|
2014-07-30 08:01:41 +08:00
|
|
|
// Override from compile definition.
|
|
|
|
ParseCommonFlagsFromString(cf, GetRuntimeFlagsFromCompileDefinition());
|
|
|
|
// Override from environment variable.
|
2014-07-30 07:49:20 +08:00
|
|
|
ParseCommonFlagsFromString(cf, GetEnv("UBSAN_OPTIONS"));
|
|
|
|
}
|
|
|
|
|
2014-07-24 02:44:54 +08:00
|
|
|
Flags ubsan_flags;
|
|
|
|
|
2014-07-30 07:49:20 +08:00
|
|
|
static void ParseFlagsFromString(Flags *f, const char *str) {
|
|
|
|
if (!str)
|
|
|
|
return;
|
|
|
|
ParseFlag(str, &f->print_stacktrace, "print_stacktrace",
|
|
|
|
"Include full stacktrace into an error report");
|
|
|
|
}
|
|
|
|
|
2014-07-24 02:44:54 +08:00
|
|
|
void InitializeFlags() {
|
|
|
|
Flags *f = flags();
|
|
|
|
// Default values.
|
|
|
|
f->print_stacktrace = false;
|
2014-07-30 08:01:41 +08:00
|
|
|
// Override from compile definition.
|
|
|
|
ParseFlagsFromString(f, GetRuntimeFlagsFromCompileDefinition());
|
2014-07-30 07:49:20 +08:00
|
|
|
// Override from environment variable.
|
|
|
|
ParseFlagsFromString(f, GetEnv("UBSAN_OPTIONS"));
|
2014-07-24 02:44:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace __ubsan
|