summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/scudo/scudo_flags.cpp
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2016-08-02 22:25:38 +0000
committerKostya Serebryany <kcc@google.com>2016-08-02 22:25:38 +0000
commit707894b09270dc072f734d2a28567db58bc36b34 (patch)
treebf3f73c3a537a22d2dca6dcbfc260992a142ba8c /compiler-rt/lib/scudo/scudo_flags.cpp
parent979902b3ff9009b5909ae245baf43d15f470e22b (diff)
downloadbcm5719-llvm-707894b09270dc072f734d2a28567db58bc36b34.tar.gz
bcm5719-llvm-707894b09270dc072f734d2a28567db58bc36b34.zip
[sanitizer] Implement a __asan_default_options() equivalent for Scudo
Summary: Currently, the Scudo Hardened Allocator only gets its flags via the SCUDO_OPTIONS environment variable. With this patch, we offer the opportunity for programs to define their own options via __scudo_default_options() which behaves like __asan_default_options() (weak symbol). A relevant test has been added as well, and the documentation updated accordingly. I also used this patch as an opportunity to rename a few variables to comply with the LLVM naming scheme, and replaced a use of Report with dieWithMessage for consistency (and to avoid a callback). Reviewers: llvm-commits, kcc Differential Revision: https://reviews.llvm.org/D23018 llvm-svn: 277536
Diffstat (limited to 'compiler-rt/lib/scudo/scudo_flags.cpp')
-rw-r--r--compiler-rt/lib/scudo/scudo_flags.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/compiler-rt/lib/scudo/scudo_flags.cpp b/compiler-rt/lib/scudo/scudo_flags.cpp
index 430dcd2995d..f0d208863bc 100644
--- a/compiler-rt/lib/scudo/scudo_flags.cpp
+++ b/compiler-rt/lib/scudo/scudo_flags.cpp
@@ -17,9 +17,12 @@
#include "sanitizer_common/sanitizer_flags.h"
#include "sanitizer_common/sanitizer_flag_parser.h"
+extern "C" SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
+const char* __scudo_default_options();
+
namespace __scudo {
-Flags scudo_flags_dont_use_directly; // use via flags().
+Flags ScudoFlags; // Use via getFlags().
void Flags::setDefaults() {
#define SCUDO_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
@@ -34,6 +37,10 @@ static void RegisterScudoFlags(FlagParser *parser, Flags *f) {
#undef SCUDO_FLAG
}
+static const char *callGetScudoDefaultOptions() {
+ return (&__scudo_default_options) ? __scudo_default_options() : "";
+}
+
void initFlags() {
SetCommonFlagsDefaults();
{
@@ -45,11 +52,16 @@ void initFlags() {
Flags *f = getFlags();
f->setDefaults();
- FlagParser scudo_parser;
- RegisterScudoFlags(&scudo_parser, f);
- RegisterCommonFlags(&scudo_parser);
+ FlagParser ScudoParser;
+ RegisterScudoFlags(&ScudoParser, f);
+ RegisterCommonFlags(&ScudoParser);
+
+ // Override from user-specified string.
+ const char *ScudoDefaultOptions = callGetScudoDefaultOptions();
+ ScudoParser.ParseString(ScudoDefaultOptions);
- scudo_parser.ParseString(GetEnv("SCUDO_OPTIONS"));
+ // Override from environment.
+ ScudoParser.ParseString(GetEnv("SCUDO_OPTIONS"));
InitializeCommonFlags();
@@ -75,7 +87,7 @@ void initFlags() {
}
Flags *getFlags() {
- return &scudo_flags_dont_use_directly;
+ return &ScudoFlags;
}
}
OpenPOWER on IntegriCloud