2019-08-14 10:47:11 +02:00
|
|
|
//===-- ubsan_flags.cpp ---------------------------------------------------===//
|
2014-09-23 17:59:53 +00:00
|
|
|
//
|
2019-08-14 10:47:11 +02:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2014-09-23 17:59:53 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Runtime flags for UndefinedBehaviorSanitizer.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-10-21 10:32:45 +03:00
|
|
|
#include "ubsan_platform.h"
|
|
|
|
#if CAN_SANITIZE_UB
|
2014-09-23 17:59:53 +00:00
|
|
|
#include "ubsan_flags.h"
|
|
|
|
#include "sanitizer_common/sanitizer_common.h"
|
|
|
|
#include "sanitizer_common/sanitizer_flags.h"
|
2015-10-21 10:32:45 +03:00
|
|
|
#include "sanitizer_common/sanitizer_flag_parser.h"
|
2014-09-23 17:59:53 +00:00
|
|
|
|
2018-10-31 12:14:23 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2014-09-23 17:59:53 +00:00
|
|
|
namespace __ubsan {
|
|
|
|
|
2018-10-31 12:14:23 +01:00
|
|
|
static const char *GetFlag(const char *flag) {
|
|
|
|
// We cannot call getenv() from inside a preinit array initializer
|
|
|
|
if (SANITIZER_CAN_USE_PREINIT_ARRAY) {
|
|
|
|
return GetEnv(flag);
|
|
|
|
} else {
|
|
|
|
return getenv(flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-23 17:59:53 +00:00
|
|
|
Flags ubsan_flags;
|
|
|
|
|
2015-10-21 10:32:45 +03:00
|
|
|
void Flags::SetDefaults() {
|
|
|
|
#define UBSAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
|
|
|
|
#include "ubsan_flags.inc"
|
|
|
|
#undef UBSAN_FLAG
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegisterUbsanFlags(FlagParser *parser, Flags *f) {
|
|
|
|
#define UBSAN_FLAG(Type, Name, DefaultValue, Description) \
|
|
|
|
RegisterFlag(parser, #Name, Description, &f->Name);
|
|
|
|
#include "ubsan_flags.inc"
|
|
|
|
#undef UBSAN_FLAG
|
2014-09-23 17:59:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InitializeFlags() {
|
2015-10-21 10:32:45 +03:00
|
|
|
SetCommonFlagsDefaults();
|
|
|
|
{
|
|
|
|
CommonFlags cf;
|
|
|
|
cf.CopyFrom(*common_flags());
|
2023-11-15 12:46:56 +01:00
|
|
|
cf.print_summary = false;
|
2018-10-31 12:14:23 +01:00
|
|
|
cf.external_symbolizer_path = GetFlag("UBSAN_SYMBOLIZER_PATH");
|
2015-10-21 10:32:45 +03:00
|
|
|
OverrideCommonFlags(cf);
|
|
|
|
}
|
|
|
|
|
2014-09-23 17:59:53 +00:00
|
|
|
Flags *f = flags();
|
2015-10-21 10:32:45 +03:00
|
|
|
f->SetDefaults();
|
|
|
|
|
|
|
|
FlagParser parser;
|
|
|
|
RegisterCommonFlags(&parser);
|
|
|
|
RegisterUbsanFlags(&parser, f);
|
|
|
|
|
2014-09-23 17:59:53 +00:00
|
|
|
// Override from user-specified string.
|
2020-10-16 10:03:04 +02:00
|
|
|
parser.ParseString(__ubsan_default_options());
|
2014-09-23 17:59:53 +00:00
|
|
|
// Override from environment variable.
|
2019-08-14 10:47:11 +02:00
|
|
|
parser.ParseStringFromEnv("UBSAN_OPTIONS");
|
2016-11-08 22:04:09 +00:00
|
|
|
InitializeCommonFlags();
|
2015-10-21 10:32:45 +03:00
|
|
|
if (Verbosity()) ReportUnrecognizedFlags();
|
|
|
|
|
|
|
|
if (common_flags()->help) parser.PrintFlagDescriptions();
|
2014-09-23 17:59:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace __ubsan
|
|
|
|
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
SANITIZER_INTERFACE_WEAK_DEF(const char *, __ubsan_default_options, void) {
|
|
|
|
return "";
|
|
|
|
}
|
2015-10-21 10:32:45 +03:00
|
|
|
|
|
|
|
#endif // CAN_SANITIZE_UB
|