From a993ee9f0f69ed87565d581dccc801934dccc937 Mon Sep 17 00:00:00 2001 From: Derek Bruening Date: Fri, 20 May 2016 19:26:52 +0000 Subject: [esan] Add custom flag support Summary: Adds custom flag support to EfficiencySanitizer's runtime library. Adds an initial flag cache_line_size which will be used by multiple tools. Reviewers: aizatsky, vitalybuka Subscribers: llvm-commits, eugenis, kcc, zhaoqin, aizatsky, kubabrecka Differential Revision: http://reviews.llvm.org/D20478 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@270256 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/esan/CMakeLists.txt | 1 + lib/esan/esan.cpp | 18 +-------------- lib/esan/esan_flags.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/esan/esan_flags.h | 41 ++++++++++++++++++++++++++++++++++ lib/esan/esan_flags.inc | 25 +++++++++++++++++++++ 5 files changed, 126 insertions(+), 17 deletions(-) create mode 100644 lib/esan/esan_flags.cpp create mode 100644 lib/esan/esan_flags.h create mode 100644 lib/esan/esan_flags.inc diff --git a/lib/esan/CMakeLists.txt b/lib/esan/CMakeLists.txt index 61a1982ba..5e4ee107a 100644 --- a/lib/esan/CMakeLists.txt +++ b/lib/esan/CMakeLists.txt @@ -9,6 +9,7 @@ include_directories(..) set(ESAN_SOURCES esan.cpp + esan_flags.cpp esan_interface.cpp esan_interceptors.cpp) diff --git a/lib/esan/esan.cpp b/lib/esan/esan.cpp index e16eea716..1499895eb 100644 --- a/lib/esan/esan.cpp +++ b/lib/esan/esan.cpp @@ -13,6 +13,7 @@ //===----------------------------------------------------------------------===// #include "esan.h" +#include "esan_flags.h" #include "esan_interface_internal.h" #include "esan_shadow.h" #include "sanitizer_common/sanitizer_common.h" @@ -30,8 +31,6 @@ bool EsanIsInitialized; ToolType WhichTool; ShadowMapping Mapping; -static const char EsanOptsEnv[] = "ESAN_OPTIONS"; - // We are combining multiple performance tuning tools under the umbrella of // one EfficiencySanitizer super-tool. Most of our tools have very similar // memory access instrumentation, shadow memory mapping, libc interception, @@ -142,21 +141,6 @@ static void initializeShadow() { } } -static void initializeFlags() { - // Once we add our own flags we'll parse them here. - // For now the common ones are sufficient. - FlagParser Parser; - SetCommonFlagsDefaults(); - RegisterCommonFlags(&Parser); - Parser.ParseString(GetEnv(EsanOptsEnv)); - InitializeCommonFlags(); - if (Verbosity()) - ReportUnrecognizedFlags(); - if (common_flags()->help) - Parser.PrintFlagDescriptions(); - __sanitizer_set_report_path(common_flags()->log_path); -} - void initializeLibrary(ToolType Tool) { // We assume there is only one thread during init. if (EsanIsInitialized) { diff --git a/lib/esan/esan_flags.cpp b/lib/esan/esan_flags.cpp new file mode 100644 index 000000000..3b047e28b --- /dev/null +++ b/lib/esan/esan_flags.cpp @@ -0,0 +1,58 @@ +//===-- esan_flags.cc -------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of EfficiencySanitizer, a family of performance tuners. +// +// Esan flag parsing logic. +//===----------------------------------------------------------------------===// + +#include "esan_flags.h" +#include "sanitizer_common/sanitizer_common.h" +#include "sanitizer_common/sanitizer_flag_parser.h" +#include "sanitizer_common/sanitizer_flags.h" + +namespace __esan { + +static const char EsanOptsEnv[] = "ESAN_OPTIONS"; + +Flags EsanFlagsDontUseDirectly; + +void Flags::setDefaults() { +#define ESAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue; +#include "esan_flags.inc" +#undef ESAN_FLAG +} + +static void registerEsanFlags(FlagParser *Parser, Flags *F) { +#define ESAN_FLAG(Type, Name, DefaultValue, Description) \ + RegisterFlag(Parser, #Name, Description, &F->Name); +#include "esan_flags.inc" +#undef ESAN_FLAG +} + +void initializeFlags() { + SetCommonFlagsDefaults(); + Flags *F = getFlags(); + F->setDefaults(); + + FlagParser Parser; + registerEsanFlags(&Parser, F); + RegisterCommonFlags(&Parser); + Parser.ParseString(GetEnv(EsanOptsEnv)); + + InitializeCommonFlags(); + if (Verbosity()) + ReportUnrecognizedFlags(); + if (common_flags()->help) + Parser.PrintFlagDescriptions(); + + __sanitizer_set_report_path(common_flags()->log_path); +} + +} // namespace __esan diff --git a/lib/esan/esan_flags.h b/lib/esan/esan_flags.h new file mode 100644 index 000000000..c8f4ef5ab --- /dev/null +++ b/lib/esan/esan_flags.h @@ -0,0 +1,41 @@ +//===-- esan_flags.h --------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of EfficiencySanitizer, a family of performance tuners. +// +// Esan runtime flags. +//===----------------------------------------------------------------------===// + +#ifndef ESAN_FLAGS_H +#define ESAN_FLAGS_H + +#include "sanitizer_common/sanitizer_internal_defs.h" +#include "sanitizer_common/sanitizer_flag_parser.h" + +namespace __esan { + +class Flags { +public: +#define ESAN_FLAG(Type, Name, DefaultValue, Description) Type Name; +#include "esan_flags.inc" +#undef ESAN_FLAG + + void setDefaults(); +}; + +extern Flags EsanFlagsDontUseDirectly; +inline Flags *getFlags() { + return &EsanFlagsDontUseDirectly; +} + +void initializeFlags(); + +} // namespace __esan + +#endif // ESAN_FLAGS_H diff --git a/lib/esan/esan_flags.inc b/lib/esan/esan_flags.inc new file mode 100644 index 000000000..f79fe9bf2 --- /dev/null +++ b/lib/esan/esan_flags.inc @@ -0,0 +1,25 @@ +//===-- esan_flags.inc ------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Esan runtime flags. +// +//===----------------------------------------------------------------------===// + +#ifndef ESAN_FLAG +# error "Define ESAN_FLAG prior to including this file!" +#endif + +// ESAN_FLAG(Type, Name, DefaultValue, Description) +// See COMMON_FLAG in sanitizer_flags.inc for more details. + +// Cross-tool options: +ESAN_FLAG(int, cache_line_size, 64, + "The number of bytes in a cache line. For the working-set tool, this " + "cannot be changed without also changing the compiler " + "instrumentation.") -- cgit v1.2.3