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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-03-27 01:26:04 +08:00
|
|
|
#include "ubsan_platform.h"
|
|
|
|
#if CAN_SANITIZE_UB
|
2014-07-24 02:44:54 +08:00
|
|
|
#include "ubsan_flags.h"
|
|
|
|
#include "sanitizer_common/sanitizer_common.h"
|
|
|
|
#include "sanitizer_common/sanitizer_flags.h"
|
2015-01-15 23:13:43 +08:00
|
|
|
#include "sanitizer_common/sanitizer_flag_parser.h"
|
2014-07-24 02:44:54 +08:00
|
|
|
|
|
|
|
namespace __ubsan {
|
|
|
|
|
2015-04-02 06:42:36 +08:00
|
|
|
const char *MaybeCallUbsanDefaultOptions() {
|
2014-09-20 02:54:52 +08:00
|
|
|
return (&__ubsan_default_options) ? __ubsan_default_options() : "";
|
2014-07-30 08:01:41 +08:00
|
|
|
}
|
|
|
|
|
2014-07-24 02:44:54 +08:00
|
|
|
Flags ubsan_flags;
|
|
|
|
|
2015-01-07 08:38:00 +08:00
|
|
|
void Flags::SetDefaults() {
|
|
|
|
#define UBSAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
|
|
|
|
#include "ubsan_flags.inc"
|
|
|
|
#undef UBSAN_FLAG
|
|
|
|
}
|
|
|
|
|
2015-01-15 23:13:43 +08:00
|
|
|
void RegisterUbsanFlags(FlagParser *parser, Flags *f) {
|
|
|
|
#define UBSAN_FLAG(Type, Name, DefaultValue, Description) \
|
|
|
|
RegisterFlag(parser, #Name, Description, &f->Name);
|
2015-01-07 08:38:00 +08:00
|
|
|
#include "ubsan_flags.inc"
|
|
|
|
#undef UBSAN_FLAG
|
2014-07-30 07:49:20 +08:00
|
|
|
}
|
|
|
|
|
2015-04-02 06:42:36 +08:00
|
|
|
void InitializeFlags() {
|
|
|
|
SetCommonFlagsDefaults();
|
|
|
|
{
|
2015-01-15 23:13:43 +08:00
|
|
|
CommonFlags cf;
|
|
|
|
cf.CopyFrom(*common_flags());
|
|
|
|
cf.print_summary = false;
|
2017-04-19 22:03:40 +08:00
|
|
|
cf.external_symbolizer_path = GetEnv("UBSAN_SYMBOLIZER_PATH");
|
2015-01-15 23:13:43 +08:00
|
|
|
OverrideCommonFlags(cf);
|
|
|
|
}
|
|
|
|
|
2015-04-02 06:42:36 +08:00
|
|
|
Flags *f = flags();
|
2015-01-07 08:38:00 +08:00
|
|
|
f->SetDefaults();
|
2015-04-02 06:42:36 +08:00
|
|
|
|
|
|
|
FlagParser parser;
|
|
|
|
RegisterCommonFlags(&parser);
|
|
|
|
RegisterUbsanFlags(&parser, f);
|
|
|
|
|
2014-09-20 02:54:52 +08:00
|
|
|
// Override from user-specified string.
|
2015-01-15 23:13:43 +08:00
|
|
|
parser.ParseString(MaybeCallUbsanDefaultOptions());
|
2014-07-30 07:49:20 +08:00
|
|
|
// Override from environment variable.
|
2015-01-15 23:13:43 +08:00
|
|
|
parser.ParseString(GetEnv("UBSAN_OPTIONS"));
|
2016-03-19 03:28:07 +08:00
|
|
|
InitializeCommonFlags();
|
2015-08-14 04:34:00 +08:00
|
|
|
if (Verbosity()) ReportUnrecognizedFlags();
|
|
|
|
|
|
|
|
if (common_flags()->help) parser.PrintFlagDescriptions();
|
2014-07-24 02:44:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace __ubsan
|
2014-09-20 02:54:52 +08:00
|
|
|
|
2017-01-29 13:44:59 +08:00
|
|
|
SANITIZER_INTERFACE_WEAK_DEF(const char *, __ubsan_default_options, void) {
|
|
|
|
return "";
|
|
|
|
}
|
2015-07-02 09:44:34 +08:00
|
|
|
|
2015-03-27 01:26:04 +08:00
|
|
|
#endif // CAN_SANITIZE_UB
|