[compiler-rt] r226175 - [sanitizer] Implement include= option.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Mon Jan 19 00:22:17 PST 2015


Thanks! I tried figuring out the problem by the test output from
sanitizer-ppc bot, but it was not that easy.


On Sat, Jan 17, 2015 at 6:36 AM, Hal Finkel <hfinkel at anl.gov> wrote:
> ----- Original Message -----
>> From: "Evgeniy Stepanov" <eugeni.stepanov at gmail.com>
>> To: llvm-commits at cs.uiuc.edu
>> Sent: Thursday, January 15, 2015 10:27:00 AM
>> Subject: [compiler-rt] r226175 - [sanitizer] Implement include= option.
>>
>> Author: eugenis
>> Date: Thu Jan 15 10:26:59 2015
>> New Revision: 226175
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=226175&view=rev
>> Log:
>> [sanitizer] Implement include= option.
>>
>> Allows loading sanitizer options from file.
>>
>> Added:
>>     compiler-rt/trunk/test/asan/TestCases/asan_options-include.cc
>>       (with props)
>> Modified:
>>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_flag_parser.cc
>>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_flag_parser.h
>>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc
>>
>> Modified:
>> compiler-rt/trunk/lib/sanitizer_common/sanitizer_flag_parser.cc
>> URL:
>> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_flag_parser.cc?rev=226175&r1=226174&r2=226175&view=diff
>> ==============================================================================
>> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_flag_parser.cc
>> (original)
>> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_flag_parser.cc
>> Thu Jan 15 10:26:59 2015
>> @@ -71,10 +71,7 @@ void FlagParser::parse_flag() {
>>    InternalFree((void *)value);
>>  }
>>
>> -void FlagParser::ParseString(const char *s) {
>> -  if (!s) return;
>> -  buf_ = s;
>> -  pos_ = 0;
>> +void FlagParser::parse_flags() {
>>    while (true) {
>>      skip_whitespace();
>>      if (buf_[pos_] == 0) break;
>> @@ -86,6 +83,20 @@ void FlagParser::ParseString(const char
>>      common_flags_dont_use.malloc_context_size = 1;
>>  }
>>
>> +void FlagParser::ParseString(const char *s) {
>> +  if (!s) return;
>> +  // Backup current parser state to allow nested ParseString()
>> calls.
>> +  const char *old_buf_ = buf_;
>> +  uptr old_pos_ = pos_;
>> +  buf_ = s;
>> +  pos_ = 0;
>> +
>> +  parse_flags();
>> +
>> +  buf_ = old_buf_;
>> +  pos_ = old_pos_;
>> +}
>> +
>>  bool FlagParser::run_handler(const char *name, const char *value) {
>>    for (int i = 0; i < n_flags_; ++i) {
>>      if (internal_strcmp(name, flags_[i].name) == 0)
>>
>> Modified:
>> compiler-rt/trunk/lib/sanitizer_common/sanitizer_flag_parser.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_flag_parser.h?rev=226175&r1=226174&r2=226175&view=diff
>> ==============================================================================
>> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_flag_parser.h
>> (original)
>> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_flag_parser.h
>> Thu Jan 15 10:26:59 2015
>> @@ -101,6 +101,7 @@ class FlagParser {
>>    void fatal_error(const char *err);
>>    bool is_space(char c);
>>    void skip_whitespace();
>> +  void parse_flags();
>>    void parse_flag();
>>    bool run_handler(const char *name, const char *value);
>>  };
>>
>> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc
>> URL:
>> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc?rev=226175&r1=226174&r2=226175&view=diff
>> ==============================================================================
>> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc
>> (original)
>> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc Thu Jan
>> 15 10:26:59 2015
>> @@ -45,11 +45,37 @@ void CommonFlags::CopyFrom(const CommonF
>>    internal_memcpy(this, &other, sizeof(*this));
>>  }
>>
>> +class FlagHandlerInclude : public FlagHandlerBase {
>> +  static const uptr kMaxIncludeSize = 1 << 15;
>> +  FlagParser *parser_;
>> +
>> + public:
>> +  explicit FlagHandlerInclude(FlagParser *parser) : parser_(parser)
>> {}
>> +  bool Parse(const char *value) {
>> +    char *data;
>> +    uptr data_mapped_size;
>> +    uptr len =
>> +        ReadFileToBuffer(value, &data, &data_mapped_size,
>> kMaxIncludeSize);
>
> I adjusted this slightly in r226368 to that this will work on systems with a page size larger than kMaxIncludeSize == 1 << 15. Bumping this to 1 << 16 will also work for me; I don't have a strong preference. Feel free to adjust my adjustment ;)
>
> Thanks again,
> Hal
>
>> +    if (!len) {
>> +      Printf("Failed to read options from '%s'\n", value);
>> +      return false;
>> +    }
>> +    parser_->ParseString(data);
>> +    UnmapOrDie(data, data_mapped_size);
>> +    return true;
>> +  }
>> +};
>> +
>>  void RegisterCommonFlags(FlagParser *parser, CommonFlags *cf) {
>>  #define COMMON_FLAG(Type, Name, DefaultValue, Description) \
>>    RegisterFlag(parser, #Name, Description, &cf->Name);
>>  #include "sanitizer_flags.inc"
>>  #undef COMMON_FLAG
>> +
>> +  FlagHandlerInclude *fh_include =
>> +      new (INTERNAL_ALLOC) FlagHandlerInclude(parser);  // NOLINT
>> +  parser->RegisterHandler("include", fh_include,
>> +                          "read more options from the given file");
>>  }
>>
>>  }  // namespace __sanitizer
>>
>> Added: compiler-rt/trunk/test/asan/TestCases/asan_options-include.cc
>> URL:
>> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/asan_options-include.cc?rev=226175&view=auto
>> ==============================================================================
>> --- compiler-rt/trunk/test/asan/TestCases/asan_options-include.cc
>> (added)
>> +++ compiler-rt/trunk/test/asan/TestCases/asan_options-include.cc Thu
>> Jan 15 10:26:59 2015
>> @@ -0,0 +1,16 @@
>> +// RUN: %clangxx_asan -O0 %s -o %t
>> +// RUN: echo "symbolize=1\ninclude='%t.options2.txt'" >
>> %t.options1.txt
>> +// RUN: echo "verbosity=1" > %t.options2.txt
>> +// RUN: ASAN_OPTIONS="verbosity=0:include='%t.options2.txt'" %run %t
>> 2>&1 | FileCheck %s --check-prefix=CHECK-VERBOSITY1
>> +// RUN: ASAN_OPTIONS="include='%t.options2.txt',verbosity=0" %run %t
>> 2>&1 | FileCheck %s --check-prefix=CHECK-VERBOSITY0
>> +// RUN:
>> ASAN_OPTIONS="include='%t.options-not-found.txt',verbosity=0" not
>> %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOT-FOUND
>> +
>> +#include <stdio.h>
>> +
>> +int main() {
>> +  fprintf(stderr, "done\n");
>> +}
>> +
>> +// CHECK-VERBOSITY1: Parsed ASAN_OPTIONS:
>> +// CHECK-VERBOSITY0-NOT: Parsed ASAN_OPTIONS:
>> +// CHECK-NOT-FOUND: Failed to read options from
>>
>> Propchange:
>> compiler-rt/trunk/test/asan/TestCases/asan_options-include.cc
>> ------------------------------------------------------------------------------
>>     svn:eol-style = LF
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>
> --
> Hal Finkel
> Assistant Computational Scientist
> Leadership Computing Facility
> Argonne National Laboratory



More information about the llvm-commits mailing list