summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Abrahams <jonathan@mongodb.com>2016-09-15 14:14:12 -0400
committerJonathan Abrahams <jonathan@mongodb.com>2016-09-15 14:16:38 -0400
commitd0d28ea7b664cf1fefbc33fe4751e0a70d29b7fa (patch)
treea03301ceee4653a998b8830b0e8c8997d81e82f6
parent4b9ef4fb0a71b5e03d9083afdae884e860cd5f98 (diff)
downloadmongo-d0d28ea7b664cf1fefbc33fe4751e0a70d29b7fa.tar.gz
SERVER-25488 Added JavaScript funciton to mongo shell to check for sanitizer builds
_isAddressSanitizerActive() _isLeakSanitizerActive() _isThreadSanitizerActive() _isUndefinedBehaviorSanitizerActive()
-rw-r--r--src/mongo/shell/shell_utils.cpp18
-rw-r--r--src/mongo/shell/utils.js25
2 files changed, 25 insertions, 18 deletions
diff --git a/src/mongo/shell/shell_utils.cpp b/src/mongo/shell/shell_utils.cpp
index 1e79ab36f0a..20c199fc652 100644
--- a/src/mongo/shell/shell_utils.cpp
+++ b/src/mongo/shell/shell_utils.cpp
@@ -154,23 +154,6 @@ BSONObj isWindows(const BSONObj& a, void* data) {
#endif
}
-BSONObj isAddressSanitizerActive(const BSONObj& a, void* data) {
- bool isSanitized = false;
-// See the following for information on how we detect address sanitizer in clang and gcc.
-//
-// - http://clang.llvm.org/docs/AddressSanitizer.html#has-feature-address-sanitizer
-// - https://gcc.gnu.org/ml/gcc-patches/2012-11/msg01827.html
-//
-#if defined(__has_feature)
-#if __has_feature(address_sanitizer)
- isSanitized = true;
-#endif
-#elif defined(__SANITIZE_ADDRESS__)
- isSanitized = true;
-#endif
- return BSON("" << isSanitized);
-}
-
BSONObj getBuildInfo(const BSONObj& a, void* data) {
uassert(16822, "getBuildInfo accepts no arguments", a.nFields() == 0);
BSONObjBuilder b;
@@ -236,7 +219,6 @@ void installShellUtils(Scope& scope) {
scope.injectNative("_srand", JSSrand);
scope.injectNative("_rand", JSRand);
scope.injectNative("_isWindows", isWindows);
- scope.injectNative("_isAddressSanitizerActive", isAddressSanitizerActive);
scope.injectNative("interpreterVersion", interpreterVersion);
scope.injectNative("getBuildInfo", getBuildInfo);
scope.injectNative("isKeyTooLarge", isKeyTooLarge);
diff --git a/src/mongo/shell/utils.js b/src/mongo/shell/utils.js
index d24e8aad3e9..c2ccd97e7bb 100644
--- a/src/mongo/shell/utils.js
+++ b/src/mongo/shell/utils.js
@@ -156,6 +156,31 @@ if (typeof TestData == "undefined") {
TestData = undefined;
}
+function __sanitizeMatch(flag) {
+ var sanitizeMatch = /-fsanitize=([^\s]+) /.exec(getBuildInfo()["buildEnvironment"]["ccflags"]);
+ if (flag && RegExp(flag).exec(sanitizeMatch[1])) {
+ return true;
+ } else {
+ return false;
+ }
+}
+
+function _isAddressSanitizerActive() {
+ return __sanitizeMatch("address");
+}
+
+function _isLeakSanitizerActive() {
+ return __sanitizeMatch("leak");
+}
+
+function _isThreadSanitizerActive() {
+ return __sanitizeMatch("thread");
+}
+
+function _isUndefinedBehaviorSanitizerActive() {
+ return __sanitizeMatch("undefined");
+}
+
jsTestName = function() {
if (TestData)
return TestData.testName;