diff options
author | Ivan Baravy <i.baravy@samsung.com> | 2017-02-27 11:07:23 +0300 |
---|---|---|
committer | Ivan Baravy <i.baravy@samsung.com> | 2017-02-27 11:07:23 +0300 |
commit | 6b3e63486ce3712ca2d6025785c50053326d8e10 (patch) | |
tree | 042d4d98336e31b5280975b94fff01bb5f5bca15 | |
parent | ead8b34418bb7485ca234c01d7950f9c7ec32df8 (diff) | |
download | linaro-gcc-6b3e63486ce3712ca2d6025785c50053326d8e10.tar.gz linaro-gcc-6b3e63486ce3712ca2d6025785c50053326d8e10.tar.bz2 linaro-gcc-6b3e63486ce3712ca2d6025785c50053326d8e10.zip |
Make lsan-force-options and lsan-build-env more usable. Factor out common
code from {A, UB}San to sanitizer_common code.
Add -fno-omit-frame-pointer -U_FORTIFY_SOURCE to lsan-force-options because
LSan heavily relies on frame pointers. Disable LSan in QEMU builds through
LSAN_OPTIONS file. Refactor Tizen specific patches in ASan and UBSan.
-rw-r--r-- | libsanitizer/asan/asan_flags.cc | 23 | ||||
-rw-r--r-- | libsanitizer/asan/asan_rtl.cc | 14 | ||||
-rw-r--r-- | libsanitizer/lsan/lsan.cc | 10 | ||||
-rw-r--r-- | libsanitizer/sanitizer_common/sanitizer_common.cc | 18 | ||||
-rw-r--r-- | libsanitizer/sanitizer_common/sanitizer_common.h | 3 | ||||
-rw-r--r-- | libsanitizer/sanitizer_common/sanitizer_libc.cc | 11 | ||||
-rw-r--r-- | libsanitizer/sanitizer_common/sanitizer_libc.h | 6 | ||||
-rw-r--r-- | libsanitizer/ubsan/ubsan_flags.cc | 19 |
8 files changed, 59 insertions, 45 deletions
diff --git a/libsanitizer/asan/asan_flags.cc b/libsanitizer/asan/asan_flags.cc index db257c40bc9..4f87cd247e3 100644 --- a/libsanitizer/asan/asan_flags.cc +++ b/libsanitizer/asan/asan_flags.cc @@ -105,21 +105,11 @@ void InitializeFlags() { ubsan_parser.ParseString(ubsan_default_options); #endif - // Read from command line. - const char *options = GetEnv("ASAN_OPTIONS"); - // If environment variable ASAN_OPTIONS is not set use predefined file to - // init options. - bool getFlagsFromFile = options == 0; - char *asanFlags = 0; - uptr len = GetPageSizeCached(); - uptr read_len = 0; - if (getFlagsFromFile) { - ReadFileToBuffer("/ASAN_OPTIONS", &asanFlags, &len, &read_len, - GetPageSizeCached()); - options = asanFlags; - } - + int mmaped = 0; + const char *options = + GetRuntimeOptions("ASAN_OPTIONS", "/ASAN_OPTIONS", &mmaped); asan_parser.ParseString(options); + #if CAN_SANITIZE_LEAKS lsan_parser.ParseString(GetEnv("LSAN_OPTIONS")); #endif @@ -179,9 +169,8 @@ void InitializeFlags() { f->quarantine_size_mb = kDefaultQuarantineSizeMb; } - if (getFlagsFromFile) - UnmapOrDie(asanFlags, len); - + if (mmaped) + UnmapOrDie((void *)options, GetPageSizeCached()); } } // namespace __asan diff --git a/libsanitizer/asan/asan_rtl.cc b/libsanitizer/asan/asan_rtl.cc index 7f51016921b..d4dfc1df4a2 100644 --- a/libsanitizer/asan/asan_rtl.cc +++ b/libsanitizer/asan/asan_rtl.cc @@ -400,25 +400,11 @@ static void PrintAddressSpaceLayout() { kHighShadowBeg > kMidMemEnd); } -extern "C" -int mount(const char *source, const char *target, const char *filesystemtype, - unsigned long mountflags, const void *data); - static void MaybeDisableUlimit() { if (!AddressSpaceIsUnlimited()) SetAddressSpaceUnlimited(); } -bool MaybeMountProcFS() { - if (FileExists("/proc/self/maps")) return true; - - if(0 != mount("proc", "/proc", "proc", 0, 0)) { - Report("Failed to mount /proc, Asan is likely to fail\n"); - return false; - } - return true; -} - static void AsanInitInternal() { if (LIKELY(asan_inited)) return; MaybeMountProcFS(); diff --git a/libsanitizer/lsan/lsan.cc b/libsanitizer/lsan/lsan.cc index d544dfa5f2c..8d20bb6eb07 100644 --- a/libsanitizer/lsan/lsan.cc +++ b/libsanitizer/lsan/lsan.cc @@ -15,6 +15,7 @@ #include "sanitizer_common/sanitizer_flags.h" #include "sanitizer_common/sanitizer_flag_parser.h" #include "sanitizer_common/sanitizer_stacktrace.h" +#include "sanitizer_common/sanitizer_libc.h" #include "lsan_allocator.h" #include "lsan_common.h" #include "lsan_thread.h" @@ -67,13 +68,20 @@ static void InitializeFlags() { RegisterLsanFlags(&parser, f); RegisterCommonFlags(&parser); - parser.ParseString(GetEnv("LSAN_OPTIONS")); + int mmaped = 0; + const char *options = + GetRuntimeOptions("LSAN_OPTIONS", "/LSAN_OPTIONS", &mmaped); + parser.ParseString(options); SetVerbosity(common_flags()->verbosity); if (Verbosity()) ReportUnrecognizedFlags(); if (common_flags()->help) parser.PrintFlagDescriptions(); + __sanitizer_set_report_path(common_flags()->log_path); + + if (mmaped) + UnmapOrDie((void *)options, GetPageSizeCached()); } extern "C" void __lsan_init() { diff --git a/libsanitizer/sanitizer_common/sanitizer_common.cc b/libsanitizer/sanitizer_common/sanitizer_common.cc index 7c3f55ddf18..5df61c22591 100644 --- a/libsanitizer/sanitizer_common/sanitizer_common.cc +++ b/libsanitizer/sanitizer_common/sanitizer_common.cc @@ -461,6 +461,24 @@ void PrintCmdline() { Printf("\n\n"); } +const char *GetRuntimeOptions(const char *env_option, const char *filename, + int *mmaped) { + // Read from command line. + const char *options = GetEnv(env_option); + // If environment variable {A, L, UB}SAN_OPTIONS is not set use predefined + // file to init options. + bool getFlagsFromFile = options == 0; + char *flags = 0; + uptr len = GetPageSizeCached(); + uptr read_len = 0; + if (getFlagsFromFile) { + ReadFileToBuffer(filename, &flags, &len, &read_len, GetPageSizeCached()); + *mmaped = 1; + options = flags; + } + return options; +} + } // namespace __sanitizer using namespace __sanitizer; // NOLINT diff --git a/libsanitizer/sanitizer_common/sanitizer_common.h b/libsanitizer/sanitizer_common/sanitizer_common.h index 15501548f2f..0ac1cd136ac 100644 --- a/libsanitizer/sanitizer_common/sanitizer_common.h +++ b/libsanitizer/sanitizer_common/sanitizer_common.h @@ -712,6 +712,9 @@ struct SignalContext { void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp); +const char *GetRuntimeOptions(const char *env_option, const char *filename, + int *mmaped); + } // namespace __sanitizer inline void *operator new(__sanitizer::operator_new_size_type size, diff --git a/libsanitizer/sanitizer_common/sanitizer_libc.cc b/libsanitizer/sanitizer_common/sanitizer_libc.cc index 05fdca622e4..d3d9cfe37bf 100644 --- a/libsanitizer/sanitizer_common/sanitizer_libc.cc +++ b/libsanitizer/sanitizer_common/sanitizer_libc.cc @@ -258,4 +258,15 @@ bool mem_is_zero(const char *beg, uptr size) { return all == 0; } +bool MaybeMountProcFS() { + if (FileExists("/proc/self/maps")) + return true; + + if (0 != mount("proc", "/proc", "proc", 0, 0)) { + Report("Failed to mount /proc, %s is likely to fail\n", SanitizerToolName); + return false; + } + return true; +} + } // namespace __sanitizer diff --git a/libsanitizer/sanitizer_common/sanitizer_libc.h b/libsanitizer/sanitizer_common/sanitizer_libc.h index 1b3f8edfadb..f9f58202d59 100644 --- a/libsanitizer/sanitizer_common/sanitizer_libc.h +++ b/libsanitizer/sanitizer_common/sanitizer_libc.h @@ -76,6 +76,12 @@ uptr internal_sched_yield(); // Error handling bool internal_iserror(uptr retval, int *rverrno = nullptr); +extern "C" int mount(const char *source, const char *target, + const char *filesystemtype, unsigned long mountflags, + const void *data); + +bool MaybeMountProcFS(); + } // namespace __sanitizer #endif // SANITIZER_LIBC_H diff --git a/libsanitizer/ubsan/ubsan_flags.cc b/libsanitizer/ubsan/ubsan_flags.cc index f3496d39a5e..d94da27950a 100644 --- a/libsanitizer/ubsan/ubsan_flags.cc +++ b/libsanitizer/ubsan/ubsan_flags.cc @@ -56,20 +56,13 @@ void InitializeFlags() { // Override from user-specified string. parser.ParseString(MaybeCallUbsanDefaultOptions()); - // Read from command line. - const char *options = GetEnv("UBSAN_OPTIONS"); - char *ubsanFlags = 0; - uptr len = GetPageSizeCached(); - uptr read_len = 0; - bool getFlagsFromFile = ubsanFlags == 0; - // Override from predefined file if exists. - if (getFlagsFromFile) { - ReadFileToBuffer("/UBSAN_OPTIONS", &ubsanFlags, &len, &read_len, - GetPageSizeCached()); - options = ubsanFlags; - } + int mmaped = 0; + const char *options = + GetRuntimeOptions("UBSAN_OPTIONS", "/UBSAN_OPTIONS", &mmaped); parser.ParseString(options); - UnmapOrDie(ubsanFlags, len); + + if (mmaped) + UnmapOrDie((void *)options, GetPageSizeCached()); SetVerbosity(common_flags()->verbosity); if (Verbosity()) ReportUnrecognizedFlags(); |